aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
authorDiogo Sampaio <diogo.sampaio@arm.com>2020-01-24 23:56:12 +0000
committerDiogo Sampaio <diogo.sampaio@arm.com>2020-01-24 23:56:47 +0000
commitbce360b7048cc6306c9d04faf27b71eec8762041 (patch)
treeef0a2a6952190c395bb7be4bfa70fa18a3ac64bd /clang/lib/Basic/SourceManager.cpp
parentec62bf2fd3284c9a525011b191c4960fce01dca7 (diff)
downloadllvm-bce360b7048cc6306c9d04faf27b71eec8762041.zip
llvm-bce360b7048cc6306c9d04faf27b71eec8762041.tar.gz
llvm-bce360b7048cc6306c9d04faf27b71eec8762041.tar.bz2
Detect source location overflow due includes
Summary: As discussed in http://lists.llvm.org/pipermail/cfe-dev/2019-October/063459.html the overflow of the souce locations (limited to 2^31 chars) can generate all sorts of weird things (bogus warnings, hangs, crashes, miscompilation and correct compilation). In debug mode this assert would fail. So it might be a good start, as in PR42301, to detect the failure and exit with a proper error message. Reviewers: rsmith, thakis, miyuki Reviewed By: miyuki Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70183
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 73f2ae9..187c33a 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -577,13 +577,15 @@ FileID SourceManager::createFileID(const ContentCache *File, StringRef Filename,
SLocEntryLoaded[Index] = true;
return FileID::get(LoadedID);
}
+ unsigned FileSize = File->getSize();
+ if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
+ NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) {
+ Diag.Report(IncludePos, diag::err_include_too_large);
+ return FileID();
+ }
LocalSLocEntryTable.push_back(
SLocEntry::get(NextLocalOffset,
FileInfo::get(IncludePos, File, FileCharacter, Filename)));
- unsigned FileSize = File->getSize();
- assert(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
- NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset &&
- "Ran out of source locations!");
// We do a +1 here because we want a SourceLocation that means "the end of the
// file", e.g. for the "no newline at the end of the file" diagnostic.
NextLocalOffset += FileSize + 1;