In MemoryBuffer::getOpenFile() make sure that the buffer is null-terminated if
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 5 Apr 2012 04:23:56 +0000 (04:23 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 5 Apr 2012 04:23:56 +0000 (04:23 +0000)
commit541b2a4aa3401b1dcff9a127e0abeee08c5720f9
tree39f35490f6df9fca18a01dbace65ce296f9b22eb
parentb657a90929867716ca1c7c12d442bb5d32281bd4
In MemoryBuffer::getOpenFile() make sure that the buffer is null-terminated if
the caller requested a null-terminated one.

When mapping the file 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, so do a copy that adds a null-terminator.

Protects against crash of rdar://11161822.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154082 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Support/MemoryBuffer.cpp