Bug 1344467 - Clear the format type for unknown types. r=valentin, a=lizzard
authorDaniel Stenberg <daniel@haxx.se>
Fri, 31 Mar 2017 17:34:57 -0400
changeset 379421 4f97cc13beb2334f14e6cf4f73eaab5e45f07491
parent 379420 6c25e0308c34aa94624450f21e27d5e97d1b7a63
child 379422 62e7b123b0e1a6bc970d8506e778cd47dc2f5cff
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin, lizzard
bugs1344467
milestone53.0
Bug 1344467 - Clear the format type for unknown types. r=valentin, a=lizzard To make sure the last (unknown) entry is always -1. Also, nsDirIndexParser::ParseFormat() must return OK even when bailing out early to not cause subsequent problems.
netwerk/streamconv/converters/nsDirIndexParser.cpp
--- a/netwerk/streamconv/converters/nsDirIndexParser.cpp
+++ b/netwerk/streamconv/converters/nsDirIndexParser.cpp
@@ -148,21 +148,20 @@ nsDirIndexParser::ParseFormat(const char
 
   } while (*pos);
 
   delete[] mFormat;
   mFormat = new int[num+1];
   // Prevent nullptr Deref - Bug 443299 
   if (mFormat == nullptr)
     return NS_ERROR_OUT_OF_MEMORY;
-  mFormat[num] = -1;
-  mFormat[0] = -1; // to detect zero header fields
-  
   int formatNum=0;
   do {
+    mFormat[formatNum] = -1;
+
     while (*aFormatStr && nsCRT::IsAsciiSpace(char16_t(*aFormatStr)))
       ++aFormatStr;
     
     if (! *aFormatStr)
       break;
 
     nsAutoCString name;
     int32_t     len = 0;
@@ -193,44 +192,39 @@ nsDirIndexParser::ParseFormat(const char
 }
 
 nsresult
 nsDirIndexParser::ParseData(nsIDirIndex *aIdx, char* aDataStr, int32_t aLineLen)
 {
   // Parse a "201" data line, using the field ordering specified in
   // mFormat.
 
-  if (!mFormat) {
+  if (!mFormat || (mFormat[0] == -1)) {
     // Ignore if we haven't seen a format yet.
     return NS_OK;
   }
 
   nsresult rv = NS_OK;
   nsAutoCString filename;
   int32_t lineLen = aLineLen;
 
-  if (mFormat[0] == -1) {
-    // no known header fields is an error
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-
   for (int32_t i = 0; mFormat[i] != -1; ++i) {
     // If we've exhausted the data before we run out of fields, just bail.
     if (!*aDataStr || (lineLen < 1)) {
-      return NS_ERROR_ILLEGAL_VALUE;
+      return NS_OK;
     }
 
     while ((lineLen > 0) && nsCRT::IsAsciiSpace(*aDataStr)) {
       ++aDataStr;
       --lineLen;
     }
 
     if (lineLen < 1) {
       // invalid format, bail
-      return NS_ERROR_ILLEGAL_VALUE;
+      return NS_OK;
     }
 
     char    *value = aDataStr;
     if (*aDataStr == '"' || *aDataStr == '\'') {
       // it's a quoted string. snarf everything up to the next quote character
       const char quotechar = *(aDataStr++);
       lineLen--;
       ++value;
@@ -240,17 +234,17 @@ nsDirIndexParser::ParseData(nsIDirIndex 
       }
       if (lineLen > 0) {
         *aDataStr++ = '\0';
         --lineLen;
       }
 
       if (!lineLen) {
         // invalid format, bail
-        return NS_ERROR_ILLEGAL_VALUE;
+        return NS_OK;
       }
     } else {
       // it's unquoted. snarf until we see whitespace.
       value = aDataStr;
       while ((lineLen > 0) && (!nsCRT::IsAsciiSpace(*aDataStr))) {
         ++aDataStr;
         --lineLen;
       }