]> granicus.if.org Git - clang/commitdiff
Fix use-after-free detected by ASan bootstrap.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 6 Mar 2014 18:08:08 +0000 (18:08 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 6 Mar 2014 18:08:08 +0000 (18:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203140 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/HeaderSearch.cpp

index 11af5854a2e3b1c726f261c7dca8362d33aaa17b..3c5eb0ead8ce12e1a9cf0ea50933e05c7dc33d9e 100644 (file)
@@ -603,10 +603,14 @@ const FileEntry *HeaderSearch::LookupFile(
       TmpDir.push_back('/');
       TmpDir.append(Filename.begin(), Filename.end());
 
-      HeaderFileInfo &FromHFI = getFileInfo(Includer);
+      // FIXME: We don't cache the result of getFileInfo across the call to
+      // getFileAndSuggestModule, because it's a reference to an element of
+      // a container that could be reallocated across this call.
+      bool IncluderIsSystemHeader =
+          getFileInfo(Includer).DirInfo != SrcMgr::C_User;
       if (const FileEntry *FE =
               getFileAndSuggestModule(*this, TmpDir.str(), Includer->getDir(),
-                                      FromHFI.DirInfo != SrcMgr::C_User,
+                                      IncluderIsSystemHeader,
                                       SuggestedModule)) {
         // Leave CurDir unset.
         // This file is a system header or C++ unfriendly if the old file is.
@@ -614,6 +618,7 @@ const FileEntry *HeaderSearch::LookupFile(
         // Note that we only use one of FromHFI/ToHFI at once, due to potential
         // reallocation of the underlying vector potentially making the first
         // reference binding dangling.
+        HeaderFileInfo &FromHFI = getFileInfo(Includer);
         unsigned DirInfo = FromHFI.DirInfo;
         bool IndexHeaderMapHeader = FromHFI.IndexHeaderMapHeader;
         StringRef Framework = FromHFI.Framework;