mirror of
https://github.com/github/codeql.git
synced 2026-02-23 18:33:42 +01:00
Use RegexExecution in sanitizer definitions (expands scope)
This commit is contained in:
@@ -427,20 +427,17 @@ private class ReplaceDirectoryCharactersSanitizer extends StringReplaceOrReplace
|
||||
}
|
||||
}
|
||||
|
||||
/** Holds if `target` is the first argument of `matchesCall`. */
|
||||
private predicate isMatchesTarget(StringMatchesCall matchesCall, CompileTimeConstantExpr target) {
|
||||
target = matchesCall.getArgument(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `matchesCall` confirms that `checkedExpr` does not contain any directory characters
|
||||
* on the given `branch`.
|
||||
*/
|
||||
private predicate isMatchesCall(StringMatchesCall matchesCall, Expr checkedExpr, boolean branch) {
|
||||
private predicate isMatchesCall(
|
||||
RegexExecutionExpr::Range regexMatch, Expr checkedExpr, boolean branch
|
||||
) {
|
||||
exists(CompileTimeConstantExpr target, string targetValue |
|
||||
isMatchesTarget(matchesCall, target) and
|
||||
target = regexMatch.getRegex() and
|
||||
target.getStringValue() = targetValue and
|
||||
checkedExpr = matchesCall.getQualifier()
|
||||
checkedExpr = regexMatch.getString()
|
||||
|
|
||||
(
|
||||
// Allow anything except `.`, '/', '\'
|
||||
|
||||
@@ -46,19 +46,11 @@ predicate regexpMatchGuardChecks(Guard guard, Expr e, boolean branch) {
|
||||
guard = mc and
|
||||
branch = true
|
||||
|
|
||||
// `String.matches` and other `matches` methods.
|
||||
e = mc.(RegexExecutionExpr::Range).getString()
|
||||
or
|
||||
// Other `matches` methods.
|
||||
method.getName() = "matches" and
|
||||
e = mc.getQualifier()
|
||||
or
|
||||
method instanceof PatternMatchesMethod and
|
||||
e = mc.getArgument(1)
|
||||
or
|
||||
method instanceof MatcherMatchesMethod and
|
||||
exists(MethodCall matcherCall |
|
||||
matcherCall.getMethod() instanceof PatternMatcherMethod and
|
||||
e = matcherCall.getArgument(0) and
|
||||
DataFlow::localExprFlow(matcherCall, mc.getQualifier())
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user