@@ -12,25 +12,27 @@ private predicate re_module_function(string name, int flags) {
1212 name = "subn" and flags = 4
1313}
1414
15+ /**
16+ * Holds if `s` is used as a regex with the `re` module, with the regex-mode `mode` (if known).
17+ * If regex mode is not known, `mode` will be `"None"`.
18+ */
1519predicate used_as_regex ( Expr s , string mode ) {
1620 ( s instanceof Bytes or s instanceof Unicode )
1721 and
18- exists ( ModuleValue re | re .getName ( ) = "re" |
19- /* Call to re.xxx(regex, ... [mode]) */
20- exists ( CallNode call , string name |
21- call .getArg ( 0 ) .refersTo ( _, _, s .getAFlowNode ( ) ) and
22- call .getFunction ( ) .pointsTo ( re .attr ( name ) ) |
23- mode = "None"
24- or
25- exists ( Value obj |
26- mode = mode_from_mode_object ( obj ) |
27- exists ( int flags_arg |
28- re_module_function ( name , flags_arg ) and
29- call .getArg ( flags_arg ) .pointsTo ( obj )
30- )
31- or
32- call .getArgByName ( "flags" ) .pointsTo ( obj )
22+ /* Call to re.xxx(regex, ... [mode]) */
23+ exists ( CallNode call , string name |
24+ call .getArg ( 0 ) .refersTo ( _, _, s .getAFlowNode ( ) ) and
25+ call .getFunction ( ) .pointsTo ( Module:: named ( "re" ) .attr ( name ) ) |
26+ mode = "None"
27+ or
28+ exists ( Value obj |
29+ mode = mode_from_mode_object ( obj ) |
30+ exists ( int flags_arg |
31+ re_module_function ( name , flags_arg ) and
32+ call .getArg ( flags_arg ) .pointsTo ( obj )
3333 )
34+ or
35+ call .getArgByName ( "flags" ) .pointsTo ( obj )
3436 )
3537 )
3638}
0 commit comments