Bug 1363262 - Don't call First() on empty strings in nsCommandLine::HandleFlagWithParam. r=bsmedberg, a=gchang
authorL. David Baron <dbaron@dbaron.org>
Thu, 11 May 2017 15:41:41 -0700
changeset 396279 6a28c6d2c2f5c48b8ffccd7989dd95a9163fe2e4
parent 396278 d6b02b22e29cdf65e8a3b928245b59f54cef7c47
child 396280 121ef7d3dcaea47b7b7ad0063bae02493ec0584e
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, gchang
bugs1363262
milestone54.0
Bug 1363262 - Don't call First() on empty strings in nsCommandLine::HandleFlagWithParam. r=bsmedberg, a=gchang MozReview-Commit-ID: 91J55PjzwmF
toolkit/components/commandlines/nsCommandLine.cpp
--- a/toolkit/components/commandlines/nsCommandLine.cpp
+++ b/toolkit/components/commandlines/nsCommandLine.cpp
@@ -182,21 +182,25 @@ nsCommandLine::HandleFlagWithParam(const
   }
 
   if (found == int32_t(mArgs.Length()) - 1) {
     return NS_ERROR_INVALID_ARG;
   }
 
   ++found;
 
-  if (mArgs[found].First() == '-') {
-    return NS_ERROR_INVALID_ARG;
+  { // scope for validity of |param|, which RemoveArguments call invalidates
+    const nsString& param = mArgs[found];
+    if (!param.IsEmpty() && param.First() == '-') {
+      return NS_ERROR_INVALID_ARG;
+    }
+
+    aResult = param;
   }
 
-  aResult = mArgs[found];
   RemoveArguments(found - 1, found);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCommandLine::GetState(uint32_t *aResult)
 {