aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorDaniil Kovalev <dkovalev@accesssoftek.com>2024-03-02 07:03:50 +0300
committerGitHub <noreply@github.com>2024-03-02 07:03:50 +0300
commitaab3d13179dc5a37465a0e6fbf1b9369a4e6e50f (patch)
tree98576184cbca19eebfe8e99002b95e55a82457ed /llvm/lib/FileCheck/FileCheck.cpp
parent07317bbc66d1f2d7663af3c9f04d0f6c0487ac03 (diff)
downloadllvm-aab3d13179dc5a37465a0e6fbf1b9369a4e6e50f.zip
llvm-aab3d13179dc5a37465a0e6fbf1b9369a4e6e50f.tar.gz
llvm-aab3d13179dc5a37465a0e6fbf1b9369a4e6e50f.tar.bz2
[FileCheck] Fix parsing empty global and pseudo variable names (#82595)
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");