@@ -12,25 +12,27 @@ private predicate re_module_function(string name, int flags) {
12
12
name = "subn" and flags = 4
13
13
}
14
14
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
+ */
15
19
predicate used_as_regex ( Expr s , string mode ) {
16
20
( s instanceof Bytes or s instanceof Unicode )
17
21
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 )
33
33
)
34
+ or
35
+ call .getArgByName ( "flags" ) .pointsTo ( obj )
34
36
)
35
37
)
36
38
}
0 commit comments