1
1
import python
2
+ import semmle.python.objects.ObjectInternal
2
3
3
4
private predicate re_module_function ( string name , int flags ) {
4
5
name = "compile" and flags = 1 or
@@ -14,44 +15,42 @@ private predicate re_module_function(string name, int flags) {
14
15
predicate used_as_regex ( Expr s , string mode ) {
15
16
( s instanceof Bytes or s instanceof Unicode )
16
17
and
17
- exists ( ModuleObject re | re .getName ( ) = "re" |
18
+ exists ( ModuleValue re | re .getName ( ) = "re" |
18
19
/* Call to re.xxx(regex, ... [mode]) */
19
20
exists ( CallNode call , string name |
20
21
call .getArg ( 0 ) .refersTo ( _, _, s .getAFlowNode ( ) ) and
21
- call .getFunction ( ) .refersTo ( re .attr ( name ) ) |
22
+ call .getFunction ( ) .pointsTo ( re .attr ( name ) ) |
22
23
mode = "None"
23
24
or
24
- exists ( Object obj |
25
+ exists ( Value obj |
25
26
mode = mode_from_mode_object ( obj ) |
26
27
exists ( int flags_arg |
27
28
re_module_function ( name , flags_arg ) and
28
- call .getArg ( flags_arg ) .refersTo ( obj )
29
+ call .getArg ( flags_arg ) .pointsTo ( obj )
29
30
)
30
31
or
31
- call .getArgByName ( "flags" ) .refersTo ( obj )
32
+ call .getArgByName ( "flags" ) .pointsTo ( obj )
32
33
)
33
34
)
34
35
)
35
36
}
36
37
37
- string mode_from_mode_object ( Object obj ) {
38
+ string mode_from_mode_object ( Value obj ) {
38
39
(
39
40
result = "DEBUG" or result = "IGNORECASE" or result = "LOCALE" or
40
41
result = "MULTILINE" or result = "DOTALL" or result = "UNICODE" or
41
42
result = "VERBOSE"
42
43
) and
43
- obj = ModuleObject:: named ( "sre_constants" ) .attr ( "SRE_FLAG_" + result )
44
- or
45
- exists ( BinaryExpr be , Object sub | obj .getOrigin ( ) = be |
46
- be .getOp ( ) instanceof BitOr and
47
- be .getASubExpression ( ) .refersTo ( sub ) and
48
- result = mode_from_mode_object ( sub )
44
+ exists ( int flag |
45
+ flag = Value:: named ( "sre_constants.SRE_FLAG_" + result ) .( ObjectInternal ) .intValue ( )
46
+ and
47
+ obj .( ObjectInternal ) .intValue ( ) .bitAnd ( flag ) = flag
49
48
)
50
49
}
51
50
52
51
/** A StrConst used as a regular expression */
53
52
abstract class RegexString extends Expr {
54
-
53
+
55
54
RegexString ( ) {
56
55
( this instanceof Bytes or this instanceof Unicode )
57
56
}
0 commit comments