1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

In MemoryBuffer::getOpenFile() don't verify that the mmap'ed

file buffer is null-terminated.

If the file is smaller than we thought, mmap will not allow dereferencing
past the pages that are enough to cover the actual file size,
even though we asked for a larger address range.

rdar://11612916

llvm-svn: 160075
This commit is contained in:
Argyrios Kyrtzidis 2012-07-11 20:59:20 +00:00
parent e0fbd238e2
commit 4cbb37098a

View File

@ -313,16 +313,6 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
RealMapOffset)) {
result.reset(GetNamedBuffer<MemoryBufferMMapFile>(
StringRef(Pages + Delta, MapSize), Filename, RequiresNullTerminator));
if (RequiresNullTerminator && result->getBufferEnd()[0] != '\0') {
// There could be a racing issue that resulted in the file being larger
// than the FileSize passed by the caller. We already have an assertion
// for this in MemoryBuffer::init() but have a runtime guarantee that
// the buffer will be null-terminated here, so do a copy that adds a
// null-terminator.
result.reset(MemoryBuffer::getMemBufferCopy(result->getBuffer(),
Filename));
}
return error_code::success();
}
}