-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[FileCheck] Fix parsing empty global and pseudo variable names #82595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FileCheck] Fix parsing empty global and pseudo variable names #82595
Conversation
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/pr-subscribers-testing-tools Author: Daniil Kovalev (kovdan01) ChangesIn This patch adds an if statement against the case described. Full diff: https://github.com/llvm/llvm-project/pull/82595.diff 1 Files Affected:
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");
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test cases?
; CHECK-PSEUDO: b[[@]] | ||
; CHECK-ERROR-PSEUDO:[[DIR]]/empty-variable-name.txt:18:20: error: empty pseudo variable name | ||
; CHECK-ERROR-PSEUDO-NEXT:; CHECK-PSEUDO: b{{\[\[@\]\]}} | ||
; CHECK-ERROR-PSEUDO-NEXT: ^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks, see 6974c78. Also used Str.slice(I, StringRef::npos)
to point to ]
instead of @
.
; CHECK-GLOBAL: c[[$]] | ||
; CHECK-ERROR-GLOBAL:[[DIR]]/empty-variable-name.txt:29:20: error: empty global variable name | ||
; CHECK-ERROR-GLOBAL-NEXT:; CHECK-GLOBAL: c{{\[\[\$\]\]}} | ||
; CHECK-ERROR-GLOBAL-NEXT: ^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks, see 6974c78. Also used Str.slice(I, StringRef::npos)
to point to ]
instead of $
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
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 correspondingStringRef
.This patch adds an if statement against the case described.