Skip to content

Commit 1287f5a

Browse files
[llvm-dwarfdump-fuzzer] fix out of bounds potential (#76408)
The fuzzer relies on MemoryBuffer to hold fuzz data, and MemoryBuffer guarantees that "In addition to basic access to the characters in the file, this interface guarantees you can read one character past the end of the file, and that this character will read as '\0'." [Ref](https://llvm.org/doxygen/classllvm_1_1MemoryBuffer.html#details). The current fuzzing set up does not support this, which causes potential false positives. This PR fixes it. Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65114 Signed-off-by: David Korczynski <[email protected]>
1 parent 1c87d5c commit 1287f5a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

llvm/tools/llvm-dwarfdump/fuzzer/llvm-dwarfdump-fuzzer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ using namespace llvm;
2020
using namespace object;
2121

2222
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
23-
std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(
24-
StringRef((const char *)data, size), "", false);
23+
std::string Payload(reinterpret_cast<const char *>(data), size);
24+
std::unique_ptr<MemoryBuffer> Buff = MemoryBuffer::getMemBuffer(Payload);
2525

2626
Expected<std::unique_ptr<ObjectFile>> ObjOrErr =
2727
ObjectFile::createObjectFile(Buff->getMemBufferRef());

0 commit comments

Comments
 (0)