aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorDaniil Kovalev <dkovalev@accesssoftek.com>2024-03-05 11:20:16 +0300
committerGitHub <noreply@github.com>2024-03-05 11:20:16 +0300
commit3105cfe783d861e63c647469cc3a6c9b91f8bb4a (patch)
tree1bf225bd30ef064647a729ae4411cbf4c981ce6c /llvm/lib/FileCheck/FileCheck.cpp
parent0e337c67c8b9b0e04fb47712faba204c8d999af7 (diff)
downloadllvm-3105cfe783d861e63c647469cc3a6c9b91f8bb4a.zip
llvm-3105cfe783d861e63c647469cc3a6c9b91f8bb4a.tar.gz
llvm-3105cfe783d861e63c647469cc3a6c9b91f8bb4a.tar.bz2
[FileCheck] Fix parsing empty global and pseudo variable names (#83667)
Reland #82595 with fixes of build failures related to colored output. See https://lab.llvm.org/buildbot/#/builders/139/builds/60549 Use `%ProtectFileCheckOutput` to avoid colored output. Original commit message below. In `Pattern::parseVariable`, for global variables (those starting with '$') and for pseudo variables (those starting with '@') the first character is consumed before actual variable name parsing. If the name is empty, it leads to out-of-bound access to the corresponding `StringRef`. This patch adds an if statement against the case described.
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/lib/FileCheck/FileCheck.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 6d3a2b9..8f80a69 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -297,6 +297,12 @@ Pattern::parseVariable(StringRef &Str, const SourceMgr &SM) {
if (Str[0] == '$' || IsPseudo)
++I;
+ if (I == Str.size())
+ return ErrorDiagnostic::get(SM, Str.slice(I, StringRef::npos),
+ StringRef("empty ") +
+ (IsPseudo ? "pseudo " : "global ") +
+ "variable name");
+
if (!isValidVarNameStart(Str[I++]))
return ErrorDiagnostic::get(SM, Str, "invalid variable name");