Bug 1321814 - Check for path truncation. r=rstrong, a=gchang
authorAdam Gashlin <agashlin@mozilla.com>
Thu, 16 Feb 2017 10:21:35 -0500 (2017-02-16)
changeset 312682 0a22becb23cde8ec54cb9a1c0c43382d80db63a3
parent 312681 025668e8b786e1b5ceeb00675e146d8d663a1c0e
child 312683 a0ead6ef09eb931ac334c715946cf798193c59ee
push id429
push userryanvm@gmail.com
push dateThu, 16 Feb 2017 15:23:16 +0000 (2017-02-16)
treeherdermozilla-esr45@d3fede027d06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong, gchang
bugs1321814
milestone45.7.1
Bug 1321814 - Check for path truncation. r=rstrong, a=gchang
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -3330,20 +3330,35 @@ int NS_main(int argc, NS_tchar **argv)
         else
           *d = *s;
         ++s;
         ++d;
       } while (*s);
       *d = NS_T('\0');
       ++d;
 
+      const size_t callbackBackupPathBufSize =
+        sizeof(gCallbackBackupPath)/sizeof(gCallbackBackupPath[0]);
+      const int callbackBackupPathLen =
+        NS_tsnprintf(gCallbackBackupPath, callbackBackupPathBufSize,
+                     NS_T("%s" CALLBACK_BACKUP_EXT), argv[callbackIndex]);
+
+      if (callbackBackupPathLen < 0 ||
+          callbackBackupPathLen >= static_cast<int>(callbackBackupPathBufSize)) {
+        LOG(("NS_main: callback backup path truncated"));
+        LogFinish();
+        WriteStatusFile(USAGE_ERROR);
+
+        // Don't attempt to launch the callback when the callback path is
+        // longer than expected.
+        EXIT_WHEN_ELEVATED(elevatedLockFilePath, updateLockFileHandle, 1);
+        return 1;
+      }
+
       // Make a copy of the callback executable so it can be read when patching.
-      NS_tsnprintf(gCallbackBackupPath,
-                   sizeof(gCallbackBackupPath)/sizeof(gCallbackBackupPath[0]),
-                   NS_T("%s" CALLBACK_BACKUP_EXT), argv[callbackIndex]);
       NS_tremove(gCallbackBackupPath);
       CopyFileW(argv[callbackIndex], gCallbackBackupPath, false);
 
       // Since the process may be signaled as exited by WaitForSingleObject before
       // the release of the executable image try to lock the main executable file
       // multiple times before giving up.  If we end up giving up, we won't
       // fail the update.
       const int max_retries = 10;