Bug 479485 - Invalid port numbers cause default port to be used, should fail to load, r=bzbarsky, a=dveditz
git-svn-id: svn://10.0.0.236/trunk@258722 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
087beb4980
commit
5f988c52bb
@ -614,10 +614,15 @@ nsAuthURLParser::ParseServerInfo(const char *serverinfo, PRInt32 serverinfoLen,
|
||||
if (port) {
|
||||
// XXX unfortunately ToInteger is not defined for substrings
|
||||
nsCAutoString buf(colon+1, serverinfoLen - (colon + 1 - serverinfo));
|
||||
PRInt32 err;
|
||||
*port = buf.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
*port = -1;
|
||||
if (buf.Length() == 0) {
|
||||
*port = -1;
|
||||
}
|
||||
else {
|
||||
PRInt32 err;
|
||||
*port = buf.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
29
mozilla/netwerk/test/unit/test_bug479485.js
Normal file
29
mozilla/netwerk/test/unit/test_bug479485.js
Normal file
@ -0,0 +1,29 @@
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
|
||||
function run_test() {
|
||||
var ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
|
||||
var success = false;
|
||||
try {
|
||||
var newURI = ios.newURI("http://foo.com:invalid", null, null);
|
||||
}
|
||||
catch (e) {
|
||||
success = e.result == Cr.NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
if (!success)
|
||||
do_throw("We didn't throw NS_ERROR_MALFORMED_URI when creating a new URI with :invalid as a port");
|
||||
|
||||
success = false;
|
||||
newURI = ios.newURI("http://foo.com", null, null);
|
||||
try {
|
||||
newURI.spec = "http://foo.com:invalid";
|
||||
}
|
||||
catch (e) {
|
||||
success = e.result == Cr.NS_ERROR_MALFORMED_URI;
|
||||
}
|
||||
if (!success)
|
||||
do_throw("We didn't throw NS_ERROR_MALFORMED_URI when setting a spec of a URI with :invalid as a port");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user