Skip to content

Commit 321513c

Browse files
committed
Actions: Order command substitutions by their ID, not text
In the Bash parser, we compute a mostly-unique ID for each command substitution within a shell script block. Commands are then ranked and referred to individually. Avoid a performance bottleneck by ranking commands 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 command substitutions.
1 parent 39e710e commit 321513c

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
@@ -60,9 +60,12 @@ class BashShellScript extends ShellScript {
6060
)
6161
}
6262

63-
private predicate rankedCmdSubstitutionReplacements(int i, string old, string new) {
64-
old = rank[i](string old2 | this.cmdSubstitutionReplacement(old2, _, _) | old2) and
65-
this.cmdSubstitutionReplacement(old, new, _)
63+
private predicate rankedCmdSubstitutionReplacements(int i, string command, string commandId) {
64+
// rank commands by their unique IDs
65+
commandId = rank[i](string c, string id | this.cmdSubstitutionReplacement(c, id, _) | id) and
66+
// since we cannot output (command, ID) tuples from the rank operation,
67+
// we need to work out the specific command associated with the resulting ID
68+
this.cmdSubstitutionReplacement(command, commandId, _)
6669
}
6770

6871
private predicate doReplaceCmdSubstitutions(int line, int round, string old, string new) {

0 commit comments

Comments
 (0)