[llvm] [FileCheck] Fix parsing empty global and pseudo variable names (PR #82595)
Daniil Kovalev via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 21 23:42:59 PST 2024
https://github.com/kovdan01 created https://github.com/llvm/llvm-project/pull/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.
>From 9a1f4db3f9ccc92c7ad340c04bcabd55a9b1ac3d Mon Sep 17 00:00:00 2001
From: Daniil Kovalev <dkovalev at accesssoftek.com>
Date: Thu, 22 Feb 2024 10:33:55 +0300
Subject: [PATCH] [FileCheck] Fix parsing empty global and pseudo variable
names
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.
---
llvm/lib/FileCheck/FileCheck.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 6d3a2b9cf46f7c..bb1855f599a1a3 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,
+ StringRef("empty ") +
+ (IsPseudo ? "pseudo " : "global ") +
+ "variable name");
+
if (!isValidVarNameStart(Str[I++]))
return ErrorDiagnostic::get(SM, Str, "invalid variable name");
More information about the llvm-commits
mailing list