11import python
2+ import semmle.python.objects.ObjectInternal
23
34private predicate re_module_function ( string name , int flags ) {
45 name = "compile" and flags = 1 or
@@ -14,44 +15,42 @@ private predicate re_module_function(string name, int flags) {
1415predicate used_as_regex ( Expr s , string mode ) {
1516 ( s instanceof Bytes or s instanceof Unicode )
1617 and
17- exists ( ModuleObject re | re .getName ( ) = "re" |
18+ exists ( ModuleValue re | re .getName ( ) = "re" |
1819 /* Call to re.xxx(regex, ... [mode]) */
1920 exists ( CallNode call , string name |
2021 call .getArg ( 0 ) .refersTo ( _, _, s .getAFlowNode ( ) ) and
21- call .getFunction ( ) .refersTo ( re .attr ( name ) ) |
22+ call .getFunction ( ) .pointsTo ( re .attr ( name ) ) |
2223 mode = "None"
2324 or
24- exists ( Object obj |
25+ exists ( Value obj |
2526 mode = mode_from_mode_object ( obj ) |
2627 exists ( int flags_arg |
2728 re_module_function ( name , flags_arg ) and
28- call .getArg ( flags_arg ) .refersTo ( obj )
29+ call .getArg ( flags_arg ) .pointsTo ( obj )
2930 )
3031 or
31- call .getArgByName ( "flags" ) .refersTo ( obj )
32+ call .getArgByName ( "flags" ) .pointsTo ( obj )
3233 )
3334 )
3435 )
3536}
3637
37- string mode_from_mode_object ( Object obj ) {
38+ string mode_from_mode_object ( Value obj ) {
3839 (
3940 result = "DEBUG" or result = "IGNORECASE" or result = "LOCALE" or
4041 result = "MULTILINE" or result = "DOTALL" or result = "UNICODE" or
4142 result = "VERBOSE"
4243 ) 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
4948 )
5049}
5150
5251/** A StrConst used as a regular expression */
5352abstract class RegexString extends Expr {
54-
53+
5554 RegexString ( ) {
5655 ( this instanceof Bytes or this instanceof Unicode )
5756 }
0 commit comments