Add version number checking to PTH files.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63047 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2009-01-26 21:50:21 +00:00
Родитель e1b6498c41
Коммит 67d15050bb
2 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -456,6 +456,7 @@ void PTHWriter::EmitCachedSpellings() {
void PTHWriter::GeneratePTH() { void PTHWriter::GeneratePTH() {
// Generate the prologue. // Generate the prologue.
Out << "cfe-pth"; Out << "cfe-pth";
Emit32(PTHManager::Version);
Offset JumpOffset = Out.tell(); Offset JumpOffset = Out.tell();
Emit32(0); Emit32(0);

Просмотреть файл

@ -522,12 +522,18 @@ PTHManager* PTHManager::Create(const std::string& file) {
const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd(); const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd();
// Check the prologue of the file. // Check the prologue of the file.
if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3) || if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3 + 4) ||
memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0) memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0)
return 0; return 0;
// Compute the address of the index table at the end of the PTH file. // Read the PTH version.
const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1); const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
unsigned Version = ReadLE32(p);
if (Version != PTHManager::Version)
return 0;
// Compute the address of the index table at the end of the PTH file.
const unsigned char *EndTable = BufBeg + ReadLE32(p); const unsigned char *EndTable = BufBeg + ReadLE32(p);
if (EndTable >= BufEnd) if (EndTable >= BufEnd)