@@ -3284,6 +3284,18 @@ module StdlibPrivate {
3284
3284
}
3285
3285
}
3286
3286
3287
+ /**
3288
+ * A base API node for regular expression functions.
3289
+ * Either the `re` module or a compiled regular expression.
3290
+ */
3291
+ private API:: Node re ( boolean compiled ) {
3292
+ result = API:: moduleImport ( "re" ) and
3293
+ compiled = false
3294
+ or
3295
+ result = any ( RePatternSummary c ) .getACall ( ) .( API:: CallNode ) .getReturn ( ) and
3296
+ compiled = true
3297
+ }
3298
+
3287
3299
/**
3288
3300
* A flow summary for methods returning a `re.Match` object
3289
3301
*
@@ -3293,17 +3305,18 @@ module StdlibPrivate {
3293
3305
ReMatchSummary ( ) { this = [ "re.Match" , "compiled re.Match" ] }
3294
3306
3295
3307
override DataFlow:: CallCfgNode getACall ( ) {
3296
- this = "re.Match" and
3297
- result = API:: moduleImport ( "re" ) .getMember ( [ "match" , "search" , "fullmatch" ] ) .getACall ( )
3298
- or
3299
- this = "compiled re.Match" and
3300
- result =
3301
- any ( RePatternSummary c )
3302
- .getACall ( )
3303
- .( API:: CallNode )
3304
- .getReturn ( )
3305
- .getMember ( [ "match" , "search" , "fullmatch" ] )
3306
- .getACall ( )
3308
+ exists ( API:: Node re , boolean compiled |
3309
+ re = re ( compiled ) and
3310
+ (
3311
+ compiled = false and
3312
+ this = "re.Match"
3313
+ or
3314
+ compiled = true and
3315
+ this = "compiled re.Match"
3316
+ )
3317
+ |
3318
+ result = re .getMember ( [ "match" , "search" , "fullmatch" ] ) .getACall ( )
3319
+ )
3307
3320
}
3308
3321
3309
3322
override DataFlow:: ArgumentNode getACallback ( ) { none ( ) }
@@ -3340,6 +3353,13 @@ module StdlibPrivate {
3340
3353
}
3341
3354
}
3342
3355
3356
+ /** An API node for a `re.Match` object */
3357
+ private API:: Node match ( ) {
3358
+ result = any ( ReMatchSummary c ) .getACall ( ) .( API:: CallNode ) .getReturn ( )
3359
+ or
3360
+ result = re ( _) .getMember ( "finditer" ) .getReturn ( ) .getASubscript ( )
3361
+ }
3362
+
3343
3363
/**
3344
3364
* A flow summary for methods on a `re.Match` object
3345
3365
*
@@ -3353,15 +3373,7 @@ module StdlibPrivate {
3353
3373
methodName in [ "expand" , "group" , "groups" , "groupdict" ]
3354
3374
}
3355
3375
3356
- override DataFlow:: CallCfgNode getACall ( ) {
3357
- result =
3358
- any ( ReMatchSummary c )
3359
- .getACall ( )
3360
- .( API:: CallNode )
3361
- .getReturn ( )
3362
- .getMember ( methodName )
3363
- .getACall ( )
3364
- }
3376
+ override DataFlow:: CallCfgNode getACall ( ) { result = match ( ) .getMember ( methodName ) .getACall ( ) }
3365
3377
3366
3378
override DataFlow:: ArgumentNode getACallback ( ) { none ( ) }
3367
3379
@@ -3463,6 +3475,14 @@ module StdlibPrivate {
3463
3475
) and
3464
3476
preservesValue = false
3465
3477
)
3478
+ or
3479
+ // flow from input string to attribute on match object
3480
+ exists ( int arg | arg = methodName .( RegexExecutionMethod ) .getStringArgIndex ( ) - offset |
3481
+ input in [ "Argument[" + arg + "]" , "Argument[string:]" ] and
3482
+ methodName = "finditer" and
3483
+ output = "ReturnValue.ListElement.Attribute[string]" and
3484
+ preservesValue = true
3485
+ )
3466
3486
)
3467
3487
}
3468
3488
}
0 commit comments