Bug 1595470 - Prevent EnsureCorrectPermissions from making faulty assumptions about childBuffer r=rstrong
authorKirk Steuber <ksteuber@mozilla.com>
Wed, 13 Nov 2019 02:00:18 +0000
changeset 501997 0213f7cd22c42d87a1222719004db5cd574eae67
parent 501996 109f738f08cbf047a751bef8fda45f4d053b4278
child 501998 46b4eb05f2ae0122e9f7e3711d2470e47ef54e15
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1595470
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1595470 - Prevent EnsureCorrectPermissions from making faulty assumptions about childBuffer r=rstrong Differential Revision: https://phabricator.services.mozilla.com/D52604
toolkit/mozapps/update/common/commonupdatedir.cpp
--- a/toolkit/mozapps/update/common/commonupdatedir.cpp
+++ b/toolkit/mozapps/update/common/commonupdatedir.cpp
@@ -1505,32 +1505,33 @@ static HRESULT EnsureCorrectPermissions(
 
   // We MUST not recurse into unlocked directories or links.
   if (!file.IsLocked() || file.IsLink() != Tristate::False ||
       file.IsDirectory() != Tristate::True) {
     returnValue = FAILED(returnValue) ? returnValue : E_FAIL;
     return returnValue;
   }
 
-  SimpleAutoString childBuffer;
-  if (!childBuffer.AllocEmpty(MAX_PATH)) {
-    // Fatal error. We need a buffer to put the path in.
-    return FAILED(returnValue) ? returnValue : E_OUTOFMEMORY;
-  }
-
   // Recurse into the directory.
   DIR directoryHandle(path.String());
   errno = 0;
   for (dirent* entry = readdir(&directoryHandle); entry;
        entry = readdir(&directoryHandle)) {
     if (wcscmp(entry->d_name, L".") == 0 || wcscmp(entry->d_name, L"..") == 0 ||
         file.LockFilenameMatches(entry->d_name)) {
       continue;
     }
 
+    SimpleAutoString childBuffer;
+    if (!childBuffer.AllocEmpty(MAX_PATH)) {
+      // Just return on this failure rather than continuing. It is unlikely that
+      // this error will go away for the next path we try.
+      return FAILED(returnValue) ? returnValue : E_OUTOFMEMORY;
+    }
+
     childBuffer.AssignSprintf(MAX_PATH + 1, L"%s\\%s", path.String(),
                               entry->d_name);
     if (childBuffer.Length() == 0) {
       returnValue = FAILED(returnValue)
                         ? returnValue
                         : HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW);
       continue;
     }