Python: Fix bad join in regex::used_as_regex

Since the number of relevant attributes in the `re` module is fairly
small, it made sense to factor this out in a separate predicate, and
the join order also became more sensible.
This commit is contained in:
Taus Brock-Nannestad
2020-11-05 16:33:59 +01:00
parent 035e747ad5
commit 35a63e2411

View File

@@ -19,6 +19,19 @@ private predicate re_module_function(string name, int flags) {
name = "subn" and flags = 4
}
/**
* Gets the names and corresponding values of attributes of the `re` module that are likely to be
* methods taking regular expressions as arguments.
*
* This is a helper predicate that fixes a bad join order, and should not be inlined without checking
* that this is safe.
*/
pragma[nomagic]
private Value relevant_re_attr(string name) {
result = Module::named("re").attr(name) and
name != "escape"
}
/**
* Holds if `s` is used as a regex with the `re` module, with the regex-mode `mode` (if known).
* If regex mode is not known, `mode` will be `"None"`.
@@ -28,8 +41,7 @@ predicate used_as_regex(Expr s, string mode) {
/* Call to re.xxx(regex, ... [mode]) */
exists(CallNode call, string name |
call.getArg(0).pointsTo(_, _, s.getAFlowNode()) and
call.getFunction().pointsTo(Module::named("re").attr(name)) and
not name = "escape"
call.getFunction().pointsTo(relevant_re_attr(name))
|
mode = "None"
or