[llvm-branch-commits] [cfe-branch] r333507 - Merging r327863:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue May 29 22:22:21 PDT 2018


Author: tstellar
Date: Tue May 29 22:22:21 2018
New Revision: 333507

URL: http://llvm.org/viewvc/llvm-project?rev=333507&view=rev
Log:
Merging r327863:

------------------------------------------------------------------------
r327863 | sepavloff | 2018-03-19 09:13:43 -0700 (Mon, 19 Mar 2018) | 12 lines

[Driver] Avoid invalidated iterator in insertTargetAndModeArgs

Doing an .insert() can potentially invalidate iterators by reallocating the
vector's storage. When all the stars align just right, this causes segfaults
or glibc aborts.

Gentoo Linux bug (crashes while building Chromium): https://bugs.gentoo.org/650082.

Patch by Hector Martin!

Differential Revision: https://reviews.llvm.org/D44607

------------------------------------------------------------------------

Modified:
    cfe/branches/release_60/tools/driver/driver.cpp

Modified: cfe/branches/release_60/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/tools/driver/driver.cpp?rev=333507&r1=333506&r2=333507&view=diff
==============================================================================
--- cfe/branches/release_60/tools/driver/driver.cpp (original)
+++ cfe/branches/release_60/tools/driver/driver.cpp Tue May 29 22:22:21 2018
@@ -212,20 +212,21 @@ static void insertTargetAndModeArgs(cons
   // Put target and mode arguments at the start of argument list so that
   // arguments specified in command line could override them. Avoid putting
   // them at index 0, as an option like '-cc1' must remain the first.
-  auto InsertionPoint = ArgVector.begin();
-  if (InsertionPoint != ArgVector.end())
+  int InsertionPoint = 0;
+  if (ArgVector.size() > 0)
     ++InsertionPoint;
 
   if (NameParts.DriverMode) {
     // Add the mode flag to the arguments.
-    ArgVector.insert(InsertionPoint,
+    ArgVector.insert(ArgVector.begin() + InsertionPoint,
                      GetStableCStr(SavedStrings, NameParts.DriverMode));
   }
 
   if (NameParts.TargetIsValid) {
     const char *arr[] = {"-target", GetStableCStr(SavedStrings,
                                                   NameParts.TargetPrefix)};
-    ArgVector.insert(InsertionPoint, std::begin(arr), std::end(arr));
+    ArgVector.insert(ArgVector.begin() + InsertionPoint,
+                     std::begin(arr), std::end(arr));
   }
 }
 




More information about the llvm-branch-commits mailing list