[llvm] [FileCheck] Fix parsing empty global and pseudo variable names (PR #82595)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 21 23:43:29 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-testing-tools
Author: Daniil Kovalev (kovdan01)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/82595.diff
1 Files Affected:
- (modified) llvm/lib/FileCheck/FileCheck.cpp (+6)
``````````diff
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");
``````````
</details>
https://github.com/llvm/llvm-project/pull/82595
More information about the llvm-commits
mailing list