From 99edf9e2470a6021befa0cfbe695b03db1c09d6f Mon Sep 17 00:00:00 2001 From: Kirk Steuber Date: Wed, 13 Nov 2019 02:00:18 +0000 Subject: [PATCH] Bug 1595470 - Prevent EnsureCorrectPermissions from making faulty assumptions about childBuffer r=rstrong Differential Revision: https://phabricator.services.mozilla.com/D52604 --HG-- extra : moz-landing-system : lando --- toolkit/mozapps/update/common/commonupdatedir.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/toolkit/mozapps/update/common/commonupdatedir.cpp b/toolkit/mozapps/update/common/commonupdatedir.cpp index e75259145c26..c200923dd0f6 100644 --- a/toolkit/mozapps/update/common/commonupdatedir.cpp +++ b/toolkit/mozapps/update/common/commonupdatedir.cpp @@ -1510,12 +1510,6 @@ static HRESULT EnsureCorrectPermissions(SimpleAutoString& path, 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; @@ -1526,6 +1520,13 @@ static HRESULT EnsureCorrectPermissions(SimpleAutoString& path, 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) {