Skip to content

Commit 848064e

Browse files
committed
Actions: Order quoted strings by their ID, not text
In the Bash parser, we compute a mostly-unique ID for each quoted string within a shell script block. Quoted strings are then ranked and referred to individually. Avoid a performance bottleneck by ranking quoted strings by their ID, not by their source text. I think this was the original intent of the code. Ranking by their original text ends up evaluating multiple possible orderings, which is slow on workflows that contain multiple complex quoted strings, such as JSON payloads.
1 parent fbe11cf commit 848064e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

actions/ql/lib/codeql/actions/Bash.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ class BashShellScript extends ShellScript {
137137
quotedStr.regexpMatch("[\"'].*[$\n\r'\"" + Bash::separator() + "].*[\"']")
138138
}
139139

140-
private predicate rankedQuotedStringReplacements(int i, string old, string new) {
141-
old = rank[i](string old2 | this.quotedStringReplacement(old2, _) | old2) and
142-
this.quotedStringReplacement(old, new)
140+
private predicate rankedQuotedStringReplacements(int i, string quotedString, string quotedStringId) {
141+
// rank quoted strings by their nearly-unique IDs
142+
quotedStringId = rank[i](string s, string id | this.quotedStringReplacement(s, id) | id) and
143+
// since we cannot output (string, ID) tuples from the rank operation,
144+
// we need to work out the specific string associated with the resulting ID
145+
this.quotedStringReplacement(quotedString, quotedStringId)
143146
}
144147

145148
private predicate doReplaceQuotedStrings(int line, int round, string old, string new) {

0 commit comments

Comments
 (0)