diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp index 12f2dc9ee1ee21ec08bf85b1b049acaf45b55cab..33d3f310d125ed2d14ff1decd2bf164d38d1f255 100644 --- a/netwerk/base/nsStandardURL.cpp +++ b/netwerk/base/nsStandardURL.cpp @@ -1290,8 +1290,6 @@ nsStandardURL::GetHost(nsACString &result) NS_IMETHODIMP nsStandardURL::GetPort(int32_t *result) { - // should never be more than 16 bit - MOZ_ASSERT(mPort <= std::numeric_limits<uint16_t>::max()); *result = mPort; return NS_OK; } @@ -1969,9 +1967,8 @@ nsStandardURL::SetPort(int32_t port) if ((port == mPort) || (mPort == -1 && port == mDefaultPort)) return NS_OK; - // ports must be >= 0 and 16 bit - // -1 == use default - if (port < -1 || port > std::numeric_limits<uint16_t>::max()) + // ports must be >= 0 + if (port < -1) // -1 == use default return NS_ERROR_MALFORMED_URI; if (mURLType == URLTYPE_NO_AUTHORITY) { @@ -3126,8 +3123,7 @@ nsStandardURL::Init(uint32_t urlType, { ENSURE_MUTABLE(); - if (spec.Length() > (uint32_t) net_GetURLMaxLength() || - defaultPort > std::numeric_limits<uint16_t>::max()) { + if (spec.Length() > (uint32_t) net_GetURLMaxLength()) { return NS_ERROR_MALFORMED_URI; } @@ -3178,11 +3174,6 @@ nsStandardURL::SetDefaultPort(int32_t aNewDefaultPort) InvalidateCache(); - // should never be more than 16 bit - if (aNewDefaultPort >= std::numeric_limits<uint16_t>::max()) { - return NS_ERROR_MALFORMED_URI; - } - // If we're already using the new default-port as a custom port, then clear // it off of our mSpec & set mPort to -1, to indicate that we'll be using // the default from now on (which happens to match what we already had). diff --git a/netwerk/base/nsURLParsers.cpp b/netwerk/base/nsURLParsers.cpp index b75ee0c4d4db6cbf8e3b513d9f48adc3912a00e7..015c0c02555f6a225c15e38b3af64271266514d4 100644 --- a/netwerk/base/nsURLParsers.cpp +++ b/netwerk/base/nsURLParsers.cpp @@ -606,7 +606,7 @@ nsAuthURLParser::ParseServerInfo(const char *serverinfo, int32_t serverinfoLen, nsresult err; *port = buf.ToInteger(&err); - if (NS_FAILED(err) || *port < 0 || *port > std::numeric_limits<uint16_t>::max()) + if (NS_FAILED(err) || *port < 0) return NS_ERROR_MALFORMED_URI; } } diff --git a/netwerk/test/unit/test_bug652761.js b/netwerk/test/unit/test_bug652761.js index e2b781da8721c93dfa9c4e4a9a7c7b17af59768e..fc5708a8b341aaee2f7646109b2113b1a7ab8ebf 100644 --- a/netwerk/test/unit/test_bug652761.js +++ b/netwerk/test/unit/test_bug652761.js @@ -2,16 +2,19 @@ Cu.import("resource://gre/modules/NetUtil.jsm"); -function run_test() +function completeTest(request, data, ctx) { - // Bug 1301621 makes invalid ports throw - Assert.throws(() => { - var chan = NetUtil.newChannel({ - uri: "http://localhost:80000/", - loadUsingSystemPrincipal: true - }); - }, "invalid port"); - do_test_finished(); } +function run_test() +{ + var chan = NetUtil.newChannel({ + uri: "http://localhost:80000/", + loadUsingSystemPrincipal: true + }); + var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel); + httpChan.asyncOpen2(new ChannelListener(completeTest,httpChan, CL_EXPECT_FAILURE)); + do_test_pending(); +} + diff --git a/netwerk/test/unit/test_invalidport.js b/netwerk/test/unit/test_invalidport.js new file mode 100644 index 0000000000000000000000000000000000000000..70d401c84c54c65ef2134c42e66a5919ceac322f --- /dev/null +++ b/netwerk/test/unit/test_invalidport.js @@ -0,0 +1,38 @@ +// This is essentially a crashtest for accessing an out of range port +// Perform the async open several times in order to induce exponential +// scheduling behavior bugs. + +Cu.import("resource://gre/modules/NetUtil.jsm"); + +var CC = Components.Constructor; + +var counter = 0; +const iterations = 10; + +var listener = { + onStartRequest: function test_onStartR(request, ctx) { + }, + + onDataAvailable: function test_ODA() { + do_throw("Should not get any data!"); + }, + + onStopRequest: function test_onStopR(request, ctx, status) { + if (counter++ == iterations) + do_test_finished(); + else + execute_test(); + }, +}; + +function run_test() { + execute_test(); + do_test_pending(); +} + +function execute_test() { + var chan = NetUtil.newChannel({uri: "http://localhost:75000", loadUsingSystemPrincipal: true}); + chan.QueryInterface(Ci.nsIHttpChannel); + chan.asyncOpen2(listener); +} + diff --git a/netwerk/test/unit/test_large_port.js b/netwerk/test/unit/test_large_port.js deleted file mode 100644 index d2480582f2d06b2e923e3326ff0ab670a20bb416..0000000000000000000000000000000000000000 --- a/netwerk/test/unit/test_large_port.js +++ /dev/null @@ -1,36 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Ensure that non-16-bit URIs are rejected - -"use strict"; - -var Cc = Components.classes; -var Ci = Components.interfaces; - -const StandardURL = Components.Constructor("@mozilla.org/network/standard-url;1", - "nsIStandardURL", - "init"); -function run_test() -{ - // Bug 1301621 makes invalid ports throw - Assert.throws(() => { - new StandardURL(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 65536, - "http://localhost", "UTF-8", null) - }, "invalid port during creation"); - let url = new StandardURL(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 65535, - "http://localhost", "UTF-8", null) - .QueryInterface(Ci.nsIStandardURL) - - Assert.throws(() => { - url.setDefaultPort(65536); - }, "invalid port in setDefaultPort"); - Assert.throws(() => { - url.port = 65536; - }, "invalid port in port setter"); - - do_check_eq(url.QueryInterface(Ci.nsIURI).port, -1); - do_test_finished(); -} - diff --git a/netwerk/test/unit/xpcshell.ini b/netwerk/test/unit/xpcshell.ini index a53cc0cc539612b60ffc62c656825648877368c9..5d7b81003bbdf2938ebe709f4b466a617509235c 100644 --- a/netwerk/test/unit/xpcshell.ini +++ b/netwerk/test/unit/xpcshell.ini @@ -232,8 +232,8 @@ skip-if = os == "android" [test_immutable.js] skip-if = !hasNode run-sequentially = node server exceptions dont replay well +[test_invalidport.js] [test_localstreams.js] -[test_large_port.js] [test_mismatch_last-modified.js] [test_MIME_params.js] [test_mozTXTToHTMLConv.js] diff --git a/testing/web-platform/meta/url/url-constructor.html.ini b/testing/web-platform/meta/url/url-constructor.html.ini index 7f99f601db16a6e7bcefe4853a27826a6070fc64..dcfe308c5acd56f4bb96d9c34127f9f4bcffede4 100644 --- a/testing/web-platform/meta/url/url-constructor.html.ini +++ b/testing/web-platform/meta/url/url-constructor.html.ini @@ -237,6 +237,9 @@ [Parsing: <file:..> against <http://www.example.com/test>] expected: FAIL + [Parsing: <http://f:999999/c> against <http://example.org/foo/bar>] + expected: FAIL + [Parsing: <http://www/foo%2Ehtml> against <about:blank>] expected: FAIL diff --git a/testing/web-platform/meta/url/url-setters.html.ini b/testing/web-platform/meta/url/url-setters.html.ini index b0f131bd5bcce072d9d4ddbe92aa18548326a753..0f574ea33bdc206c41fa91e6723b8869a6e679fd 100644 --- a/testing/web-platform/meta/url/url-setters.html.ini +++ b/testing/web-platform/meta/url/url-setters.html.ini @@ -75,6 +75,9 @@ [Setting <view-source+http://example.net/path>.host = 'example.com:8080stuff2' Anything other than ASCII digit stops the port parser in a setter but is not an error] expected: FAIL + [Setting <http://example.net/path>.host = 'example.com:65536' Port numbers are 16 bit integers, overflowing is an error. Hostname is still set, though.] + expected: FAIL + [Setting <view-source+http://example.net/foo>.hostname = '' The empty host is OK for non-special schemes] expected: FAIL @@ -102,6 +105,9 @@ [Setting <view-source+http://example.net/path>.port = '8080stuff2' Anything other than ASCII digit stops the port parser in a setter but is not an error] expected: FAIL + [Setting <http://example.net:8080/path>.port = '65536' Port numbers are 16 bit integers, overflowing is an error] + expected: FAIL + [Setting <unix:/run/foo.socket?timeout=10>.pathname = '/var/log/../run/bar.socket'] expected: FAIL diff --git a/toolkit/components/search/tests/xpcshell/test_location_error.js b/toolkit/components/search/tests/xpcshell/test_location_error.js index d668aea5189f118006dcfd920c2a018ae5a6dabf..5ff66c20b0a68771b0445e2348cf6e0ad55c829d 100644 --- a/toolkit/components/search/tests/xpcshell/test_location_error.js +++ b/toolkit/components/search/tests/xpcshell/test_location_error.js @@ -4,8 +4,8 @@ function run_test() { installTestEngine(); - // We use a large port that won't be open - let url = "http://localhost:999"; + // using a port > 2^32 causes an error to be reported. + let url = "http://localhost:111111111"; Services.prefs.setCharPref("browser.search.geoip.url", url); Services.search.init(() => {