From 4f5424e74e28c143067a6e6b7babe7702e798d07 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 9 Dec 2014 23:50:38 +0000 Subject: [PATCH] AsmParser: Verifier that the contents of a hex integer are hex git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223856 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLLexer.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/AsmParser/LLLexer.cpp b/lib/AsmParser/LLLexer.cpp index d2ed616e782..99f94bbb070 100644 --- a/lib/AsmParser/LLLexer.cpp +++ b/lib/AsmParser/LLLexer.cpp @@ -757,7 +757,13 @@ lltok::Kind LLLexer::LexIdentifier() { isxdigit(static_cast(TokStart[3]))) { int len = CurPtr-TokStart-3; uint32_t bits = len * 4; - APInt Tmp(bits, StringRef(TokStart+3, len), 16); + StringRef HexStr(TokStart + 3, len); + if (!std::all_of(HexStr.begin(), HexStr.end(), isxdigit)) { + // Bad token, return it as an error. + CurPtr = TokStart+3; + return lltok::Error; + } + APInt Tmp(bits, HexStr, 16); uint32_t activeBits = Tmp.getActiveBits(); if (activeBits > 0 && activeBits < bits) Tmp = Tmp.trunc(activeBits); -- 2.34.1