From: Richard Smith Date: Thu, 6 Mar 2014 18:08:08 +0000 (+0000) Subject: Fix use-after-free detected by ASan bootstrap. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b5ceb309945d3414d7ec01454f6d649cc5067940;p=clang Fix use-after-free detected by ASan bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203140 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 11af5854a2..3c5eb0ead8 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -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;