From edeaa6454ef1dc29fa3144b93e2121495b160b35 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 19 Nov 2013 21:12:39 +0000 Subject: [PATCH] Make it explicit that nulls are not allowed in names. The object files we support use null terminated strings, so there is no way to support these. This patch adds an assert to catch bad API use and an error check in the .ll parser. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195155 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLLexer.cpp | 4 ++++ lib/IR/Value.cpp | 2 ++ test/Assembler/invalid-name.ll | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 test/Assembler/invalid-name.ll diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index 1e6085b443f..3c384f5fcca 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -275,6 +275,10 @@ lltok::Kind LLLexer::LexAt() { if (CurChar == '"') { StrVal.assign(TokStart+2, CurPtr-1); UnEscapeLexed(StrVal); + if (StringRef(StrVal).find_first_of(0) != StringRef::npos) { + Error("Null bytes are not allowed in names"); + return lltok::Error; + } return lltok::GlobalVar; } } diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index 62a3b31c18b..2c90383edd8 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -182,6 +182,8 @@ void Value::setName(const Twine &NewName) { SmallString<256> NameData; StringRef NameRef = NewName.toStringRef(NameData); + assert(NameRef.find_first_of(0) == StringRef::npos && + "Null bytes are not allowed in names"); // Name isn't changing? if (getName() == NameRef) diff --git a/test/Assembler/invalid-name.ll b/test/Assembler/invalid-name.ll new file mode 100644 index 00000000000..d9d7a110880 --- /dev/null +++ b/test/Assembler/invalid-name.ll @@ -0,0 +1,6 @@ +; RUN: not llvm-as %s 2>&1 | FileCheck %s + +; CHECK: expected function name +define void @"zed\00bar"() { + ret void +}