From 10dedb9421467f2813195bcd9c81aca508a1875b Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 11 Jul 2012 20:59:20 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160075 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/MemoryBuffer.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 37377061aa2..992f03c5205 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -313,16 +313,6 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, RealMapOffset)) { result.reset(GetNamedBuffer( 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(); } }