Bug 659871: Don't allow nsStandardURL::SetPort to set an invalid port. r=bz
authorRandell Jesup <rjesup@wgate.com>
Fri, 27 May 2011 02:46:41 -0400
changeset 70235 0cf4fa02c0f2a3cdc60c2d9fa1180a4d94b8aa6f
parent 70234 2182d1af7522f0c0fc74509df82a8a3477408cc5
child 70236 9077903ebbb861f4f14c0ae4a4d42771541c18d0
push id20250
push userrjesup@wgate.com
push dateFri, 27 May 2011 06:47:26 +0000
treeherdermozilla-central@0cf4fa02c0f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs659871
milestone7.0a1
first release with
nightly linux32
0cf4fa02c0f2 / 7.0a1 / 20110527030642 / files
nightly linux64
0cf4fa02c0f2 / 7.0a1 / 20110527030642 / files
nightly mac
0cf4fa02c0f2 / 7.0a1 / 20110527030642 / files
nightly win32
0cf4fa02c0f2 / 7.0a1 / 20110527030642 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 659871: Don't allow nsStandardURL::SetPort to set an invalid port. r=bz
netwerk/base/src/nsStandardURL.cpp
--- a/netwerk/base/src/nsStandardURL.cpp
+++ b/netwerk/base/src/nsStandardURL.cpp
@@ -1514,16 +1514,20 @@ nsStandardURL::SetPort(PRInt32 port)
 {
     ENSURE_MUTABLE();
 
     LOG(("nsStandardURL::SetPort [port=%d]\n", port));
 
     if ((port == mPort) || (mPort == -1 && port == mDefaultPort))
         return NS_OK;
 
+    // ports must be >= 0 (and 0 is pretty much garbage too, though legal per RFC)
+    if (port <= 0 && port != -1) // -1 == use default
+        return NS_ERROR_MALFORMED_URI;
+
     if (mURLType == URLTYPE_NO_AUTHORITY) {
         NS_WARNING("cannot set port on no-auth url");
         return NS_ERROR_UNEXPECTED;
     }
 
     InvalidateCache();
 
     if (mPort == -1) {