Skip to content

Commit

Permalink
Error out when faced with value names containing '\0'
Browse files Browse the repository at this point in the history
Bug found with afl-fuzz.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252048 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
filcab committed Nov 4, 2015
1 parent 1cfa35b commit c3c89b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,10 @@ ErrorOr<Value *> BitcodeReader::recordValue(SmallVectorImpl<uint64_t> &Record,
return error("Invalid record");
Value *V = ValueList[ValueID];

V->setName(StringRef(ValueName.data(), ValueName.size()));
StringRef NameStr(ValueName.data(), ValueName.size());
if (NameStr.find_first_of(0) != StringRef::npos)
return error("Invalid value name");
V->setName(NameStr);
auto *GO = dyn_cast<GlobalObject>(V);
if (GO) {
if (GO->getComdat() == reinterpret_cast<Comdat *>(1)) {
Expand Down
Binary file added test/Bitcode/Inputs/invalid-name-with-0-byte.bc
Binary file not shown.
5 changes: 5 additions & 0 deletions test/Bitcode/invalid.test
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-no-function-block.bc 2>&1 |
RUN: FileCheck --check-prefix=NO-FUNCTION-BLOCK %s

NO-FUNCTION-BLOCK: Trying to materialize functions before seeing function blocks

RUN: not llvm-dis -disable-output %p/Inputs/invalid-name-with-0-byte.bc 2>&1 | \
RUN: FileCheck --check-prefix=NAME-WITH-0 %s

NAME-WITH-0: Invalid value name

0 comments on commit c3c89b4

Please sign in to comment.