@@ -11,6 +11,8 @@ import codeql.ruby.DataFlow
11
11
import codeql.ruby.typetracking.TypeTracker
12
12
import codeql.ruby.ast.internal.Module
13
13
private import codeql.ruby.controlflow.CfgNodes
14
+ private import codeql.ruby.dataflow.internal.DataFlowPrivate as DataFlowPrivate
15
+ private import codeql.ruby.dataflow.internal.DataFlowDispatch as DataFlowDispatch
14
16
15
17
/**
16
18
* Provides classes and predicates for working with APIs used in a database.
@@ -423,49 +425,56 @@ module API {
423
425
/** Gets a data flow node that flows to the RHS of a def-node. */
424
426
private DataFlow:: LocalSourceNode defCand ( ) { result = defCand ( TypeBackTracker:: end ( ) ) }
425
427
426
- /**
427
- * Holds if there should be a `lbl`-edge from the given call to an argument.
428
- */
429
- pragma [ nomagic]
430
- private predicate argumentStep ( string lbl , DataFlow:: CallNode call , DataFlow:: Node argument ) {
428
+ private string getLabelFromArgumentPosition ( DataFlowDispatch:: ArgumentPosition pos ) {
429
+ exists ( int n |
430
+ pos .isPositional ( n ) and
431
+ result = Label:: parameter ( n )
432
+ )
433
+ or
434
+ exists ( string name |
435
+ pos .isKeyword ( name ) and
436
+ result = Label:: keywordParameter ( name )
437
+ )
438
+ or
439
+ pos .isBlock ( ) and
440
+ result = Label:: blockParameter ( )
441
+ }
442
+
443
+ private string getLabelFromParameterPosition ( DataFlowDispatch:: ParameterPosition pos ) {
431
444
exists ( int n |
432
- argument = call . getArgument ( n ) and
433
- lbl = Label:: parameter ( n )
445
+ pos . isPositional ( n ) and
446
+ result = Label:: parameter ( n )
434
447
)
435
448
or
436
449
exists ( string name |
437
- argument = call . getKeywordArgument ( name ) and
438
- lbl = Label:: keywordParameter ( name )
450
+ pos . isKeyword ( name ) and
451
+ result = Label:: keywordParameter ( name )
439
452
)
440
453
or
441
- argument = call . getBlock ( ) and
442
- lbl = Label:: blockParameter ( )
454
+ pos . isBlock ( ) and
455
+ result = Label:: blockParameter ( )
443
456
}
444
457
445
458
/**
446
- * Holds if there should be a `lbl`-edge from the given callable to a parameter .
459
+ * Holds if there should be a `lbl`-edge from the given call to an argument .
447
460
*/
448
461
pragma [ nomagic]
449
- private predicate parameterStep ( string lbl , DataFlow:: Node callable , DataFlow:: Node paramNode ) {
450
- exists ( Parameter param |
451
- paramNode .asParameter ( ) = param and
452
- callable .asExpr ( ) .getExpr ( ) .( Callable ) .getAParameter ( ) = param and
453
- lbl = getLabelFromParameter ( param )
462
+ private predicate argumentStep ( string lbl , DataFlow:: CallNode call , DataFlowPrivate:: ArgumentNode argument ) {
463
+ exists ( DataFlowDispatch:: ArgumentPosition argPos |
464
+ argument .sourceArgumentOf ( call .asExpr ( ) , argPos ) and
465
+ lbl = getLabelFromArgumentPosition ( argPos )
454
466
)
455
467
}
456
468
457
- private string getLabelFromParameter ( Parameter param ) {
458
- result = Label:: keywordParameter ( param .( KeywordParameter ) .getName ( ) )
459
- or
460
- param instanceof BlockParameter and
461
- result = Label:: blockParameter ( )
462
- or
463
- (
464
- param instanceof SimpleParameter
465
- or
466
- param instanceof OptionalParameter
467
- ) and
468
- result = Label:: parameter ( param .getPosition ( ) )
469
+ /**
470
+ * Holds if there should be a `lbl`-edge from the given callable to a parameter.
471
+ */
472
+ pragma [ nomagic]
473
+ private predicate parameterStep ( string lbl , DataFlow:: Node callable , DataFlowPrivate:: ParameterNodeImpl paramNode ) {
474
+ exists ( DataFlowDispatch:: ParameterPosition paramPos |
475
+ paramNode .isSourceParameterOf ( callable .asExpr ( ) .getExpr ( ) , paramPos ) and
476
+ lbl = getLabelFromParameterPosition ( paramPos )
477
+ )
469
478
}
470
479
471
480
/**
0 commit comments