Bug 1000079 - Nullcheck to avoid Windows overwriting length 0 string. r=bsmedberg, a=lsblakk
authorJames Kitchener <jkitch.bug@gmail.com>
Tue, 06 May 2014 07:25:00 -0400
changeset 192213 594456499788
parent 192212 b431c1c19a26
child 192214 10e5a05f34b3
push id3526
push userryanvm@gmail.com
push date2014-05-07 15:03 +0000
Treeherderresults
reviewersbsmedberg, lsblakk
bugs1000079
milestone30.0
Bug 1000079 - Nullcheck to avoid Windows overwriting length 0 string. r=bsmedberg, a=lsblakk
toolkit/xre/nsXREDirProvider.cpp
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -929,16 +929,21 @@ GetRegWindowsAppDataFolder(bool aLocal, 
     ::RegCloseKey(key);
     _retval.SetLength(0);
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // |size| includes room for the terminating null character
   DWORD resultLen = size / 2 - 1;
 
+  if (!resultLen) {
+    _retval.Truncate();
+    return NS_OK;
+  }
+
   _retval.SetLength(resultLen);
   nsAString::iterator begin;
   _retval.BeginWriting(begin);
   if (begin.size_forward() != resultLen) {
     ::RegCloseKey(key);
     _retval.SetLength(0);
     return NS_ERROR_NOT_AVAILABLE;
   }