summaryrefslogtreecommitdiff
path: root/lib/Serialization/ModuleManager.cpp
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2014-05-01 03:33:36 +0000
committerBen Langmuir <blangmuir@apple.com>2014-05-01 03:33:36 +0000
commit64d1a0b8f9083d688d05262c5382b85d823441eb (patch)
treec690244b907415a0e9cf42d16a4f8bbb0fdc1bd3 /lib/Serialization/ModuleManager.cpp
parent8dda109f621c4d2f27eaf30a86d2bb37ed9095a6 (diff)
downloadclang-64d1a0b8f9083d688d05262c5382b85d823441eb.tar.gz
clang-64d1a0b8f9083d688d05262c5382b85d823441eb.tar.bz2
clang-64d1a0b8f9083d688d05262c5382b85d823441eb.tar.xz
Avoid a potential race between stat() and open() of ASTFile
We need to open an ASTFile while checking its expected size and modification time, or another clang instance can modify the file between the stat() and the open(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207735 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ModuleManager.cpp')
-rw-r--r--lib/Serialization/ModuleManager.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Serialization/ModuleManager.cpp b/lib/Serialization/ModuleManager.cpp
index c36d902deb..9b3159e170 100644
--- a/lib/Serialization/ModuleManager.cpp
+++ b/lib/Serialization/ModuleManager.cpp
@@ -381,7 +381,9 @@ bool ModuleManager::lookupModuleFile(StringRef FileName,
off_t ExpectedSize,
time_t ExpectedModTime,
const FileEntry *&File) {
- File = FileMgr.getFile(FileName, /*openFile=*/false, /*cacheFailure=*/false);
+ // Open the file immediately to ensure there is no race between stat'ing and
+ // opening the file.
+ File = FileMgr.getFile(FileName, /*openFile=*/true, /*cacheFailure=*/false);
if (!File && FileName != "-") {
return false;
@@ -389,6 +391,8 @@ bool ModuleManager::lookupModuleFile(StringRef FileName,
if ((ExpectedSize && ExpectedSize != File->getSize()) ||
(ExpectedModTime && ExpectedModTime != File->getModificationTime())) {
+ FileMgr.invalidateCache(File);
+ File = nullptr;
return true;
}