Bug 1274044: Relax assertion in nsStandardURL for case when mDefaultPort is -1. r?valentin draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 19 May 2016 10:05:17 -0700
changeset 368910 e738322404a1e97ed95d7144323f64956c4c885c
parent 368365 c4449eab07d39e20ea315603f1b1863eeed7dcfe
child 521388 c37dfd5aaa1f49243371aa33403b72af6dbdbd55
push id18656
push userdholbert@mozilla.com
push dateThu, 19 May 2016 17:09:05 +0000
reviewersvalentin
bugs1274044
milestone49.0a1
Bug 1274044: Relax assertion in nsStandardURL for case when mDefaultPort is -1. r?valentin The assertion is trying to require that the caller should never pass in mDefaultPort; instead, the caller should pass -1. BUT, if mDefaultPort is itself -1 (i.e. there's no default port), then we need to allow the caller to pass in -1 without spamming an assertion. MozReview-Commit-ID: GKxndkJoXcv
netwerk/base/nsStandardURL.cpp
netwerk/test/crashtests/1274044-1.html
netwerk/test/crashtests/crashtests.list
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1852,17 +1852,17 @@ nsStandardURL::SetPort(int32_t port)
  *  - Calling InvalidateCache (since our mSpec is changing).
  *  - Checking whether aNewPort is mDefaultPort (in which case the
  *    caller should pass aNewPort=-1).
  */
 void
 nsStandardURL::ReplacePortInSpec(int32_t aNewPort)
 {
     MOZ_ASSERT(mMutable, "Caller should ensure we're mutable");
-    NS_ASSERTION(aNewPort != mDefaultPort,
+    NS_ASSERTION(aNewPort != mDefaultPort || mDefaultPort == -1,
                  "Caller should check its passed-in value and pass -1 instead of "
                  "mDefaultPort, to avoid encoding default port into mSpec");
 
     // Create the (possibly empty) string that we're planning to replace:
     nsAutoCString buf;
     if (mPort != -1) {
         buf.Assign(':');
         buf.AppendInt(mPort);
new file mode 100644
--- /dev/null
+++ b/netwerk/test/crashtests/1274044-1.html
@@ -0,0 +1,7 @@
+<script>
+
+var u = new URL("http://127.0.0.1:9607/");
+u.protocol = "resource:";
+u.port = "";
+
+</script>
--- a/netwerk/test/crashtests/crashtests.list
+++ b/netwerk/test/crashtests/crashtests.list
@@ -1,2 +1,3 @@
 load 785753-1.html
 load 785753-2.html
+load 1274044-1.html