Bug 1212939 - Disable update logging if given a log file path longer than MAX_PATH; r=rstrong
authorMatt Howell <mhowell@mozilla.com>
Mon, 21 Dec 2015 11:36:54 -0800
changeset 277865 81e422d038d3752790fb8b073faed8351eaf3e16
parent 277864 075e39cc5f6e423d02aa4ba6613e06e94555f9d2
child 277866 61a36f055e0bbf9df522a805b9380014625c2043
push id69628
push usercbook@mozilla.com
push dateWed, 30 Dec 2015 11:16:09 +0000
treeherdermozilla-inbound@b493cf33851f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1212939
milestone46.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 1212939 - Disable update logging if given a log file path longer than MAX_PATH; r=rstrong
toolkit/mozapps/update/common/updatelogging.cpp
--- a/toolkit/mozapps/update/common/updatelogging.cpp
+++ b/toolkit/mozapps/update/common/updatelogging.cpp
@@ -23,39 +23,53 @@ void UpdateLog::Init(NS_tchar* sourcePat
                      const NS_tchar* alternateFileName,
                      bool append)
 {
   if (logFP)
     return;
 
 #ifdef XP_WIN
   GetTempFileNameW(sourcePath, L"log", 0, mTmpFilePath);
-  if (append) {
-    NS_tsnprintf(mDstFilePath, sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
+  int dstFilePathLen = NS_tsnprintf(mDstFilePath,
+    sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
+    NS_T("%s/%s"), sourcePath, append ? alternateFileName : fileName);
+
+  // If the destination path was over the length limit,
+  // disable logging by skipping opening the file and setting logFP.
+  if ((dstFilePathLen > 0) &&
+      (dstFilePathLen <
+         static_cast<int>(sizeof(mDstFilePath)/sizeof(mDstFilePath[0])))) {
+    if (append) {
+      MoveFileExW(mDstFilePath, mTmpFilePath, MOVEFILE_REPLACE_EXISTING);
+    }
+    logFP = NS_tfopen(mTmpFilePath, append ? NS_T("a") : NS_T("w"));
+
+    // Delete this file now so it is possible to tell from the unelevated
+    // updater process if the elevated updater process has written the log.
+    DeleteFileW(mDstFilePath);
+  }
+#else
+  int dstFilePathLen = 0;
+  if (alternateFileName && NS_taccess(mDstFilePath, F_OK)) {
+    dstFilePathLen = NS_tsnprintf(mDstFilePath,
+      sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
       NS_T("%s/%s"), sourcePath, alternateFileName);
-    MoveFileExW(mDstFilePath, mTmpFilePath, MOVEFILE_REPLACE_EXISTING);
   } else {
-    NS_tsnprintf(mDstFilePath, sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
-                 NS_T("%s/%s"), sourcePath, fileName);
+    dstFilePathLen = NS_tsnprintf(mDstFilePath,
+      sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
+      NS_T("%s/%s"), sourcePath, fileName);
   }
 
-  logFP = NS_tfopen(mTmpFilePath, append ? NS_T("a") : NS_T("w"));
-  // Delete this file now so it is possible to tell from the unelevated
-  // updater process if the elevated updater process has written the log.
-  DeleteFileW(mDstFilePath);
-#else
-  NS_tsnprintf(mDstFilePath, sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
-               NS_T("%s/%s"), sourcePath, fileName);
-
-  if (alternateFileName && NS_taccess(mDstFilePath, F_OK)) {
-    NS_tsnprintf(mDstFilePath, sizeof(mDstFilePath)/sizeof(mDstFilePath[0]),
-      NS_T("%s/%s"), sourcePath, alternateFileName);
+  // If the destination path was over the length limit,
+  // disable logging by skipping opening the file and setting logFP.
+  if ((dstFilePathLen > 0) &&
+      (dstFilePathLen <
+         static_cast<int>(sizeof(mDstFilePath)/sizeof(mDstFilePath[0])))) {
+    logFP = NS_tfopen(mDstFilePath, append ? NS_T("a") : NS_T("w"));
   }
-
-  logFP = NS_tfopen(mDstFilePath, append ? NS_T("a") : NS_T("w"));
 #endif
 }
 
 void UpdateLog::Finish()
 {
   if (!logFP)
     return;