Skip to content

Commit 639ae86

Browse files
authored
Update Bash alphaNumericRegex to match grouped quantified forms
1 parent 63b2263 commit 639ae86

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,5 +787,20 @@ module Bash {
787787
* Holds if the given regex is used to match an alphanumeric string
788788
* eg: `^[0-9a-zA-Z]{40}([0-9a-zA-Z]{24})?$`, `^[0-9]+$` or `^[a-zA-Z0-9_]+$`
789789
*/
790-
string alphaNumericRegex() { result = "^\\^\\[([09azAZ_-]+)\\](\\+|\\{\\d+\\})\\$$" }
790+
string alphaNumericRegex() {
791+
exists(string r1, string r2, string r3, string r4 |
792+
// An alphanumeric character class
793+
r1 = "\\[([09azAZ_-]+)\\]" and
794+
// The same as above, followed by a quantifier like `+` or `{20}`
795+
r2 = r1 + "(\\+|\\{\\d+\\})" and
796+
// The same as above, possibly with brackets around it
797+
r3 = "\\(?" + r2 + "\\)?" and
798+
// The same as above, possibly with a `?` after it
799+
r4 = r3 + "\\??"
800+
|
801+
// The same as above, repeated one or more times, and with `^` at the
802+
// beginning and `$` at the end
803+
result = "^\\^(" + r4 + ")+\\$$"
804+
)
805+
}
791806
}

0 commit comments

Comments
 (0)