@@ -44,22 +44,18 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
44
44
* Gets the type of this node.
45
45
*/
46
46
Type getType ( ) ;
47
+ }
47
48
48
- /**
49
- * Gets the enclosing callable of this node.
50
- */
51
- Callable getEnclosingCallable ( ) ;
49
+ /** Gets the enclosing callable of `node`. */
50
+ Callable getEnclosingCallable ( NodeExtended node ) ;
52
51
53
- /**
54
- * Gets the enclosing callable of this node, when considered as an expression.
55
- */
56
- Callable getAsExprEnclosingCallable ( ) ;
52
+ /**
53
+ * Gets the enclosing callable of ` node` , when considered as an expression.
54
+ */
55
+ Callable getAsExprEnclosingCallable ( NodeExtended node ) ;
57
56
58
- /**
59
- * Gets the parameter corresponding to this node, if any.
60
- */
61
- Parameter asParameter ( ) ;
62
- }
57
+ /** Gets the parameter corresponding to this node, if any. */
58
+ Parameter asParameter ( NodeExtended n ) ;
63
59
64
60
/**
65
61
* A class of callables that are potentially relevant for generating summary or
@@ -226,6 +222,14 @@ signature module ModelGeneratorInputSig<LocationSig Location, InputSig<Location>
226
222
*/
227
223
default Lang:: ParameterPosition getReturnKindParamPosition ( Lang:: ReturnKind node ) { none ( ) }
228
224
225
+ /**
226
+ * Gets the string that represents the return value corresponding to the
227
+ * return kind `kind`.
228
+ *
229
+ * For most languages this will be the string "ReturnValue".
230
+ */
231
+ default string getReturnValueString ( Lang:: ReturnKind kind ) { result = "ReturnValue" }
232
+
229
233
/**
230
234
* Holds if it is irrelevant to generate models for `api` based on data flow analysis.
231
235
*
@@ -321,9 +325,11 @@ module MakeModelGenerator<
321
325
322
326
private module PrintReturnNodeExt< printCallableParamSig / 2 printCallableParam> {
323
327
string getOutput ( ReturnNodeExt node ) {
324
- node .getKind ( ) instanceof DataFlow:: ValueReturnKind and
325
- not exists ( node .getPosition ( ) ) and
326
- result = "ReturnValue"
328
+ exists ( DataFlow:: ValueReturnKind valueReturnKind |
329
+ valueReturnKind = node .getKind ( ) and
330
+ not exists ( node .getPosition ( ) ) and
331
+ result = getReturnValueString ( valueReturnKind .getKind ( ) )
332
+ )
327
333
or
328
334
exists ( DataFlow:: ParameterPosition pos |
329
335
pos = node .getPosition ( ) and
@@ -390,7 +396,7 @@ module MakeModelGenerator<
390
396
* Gets the MaD string representation of the parameter node `p`.
391
397
*/
392
398
string parameterNodeAsInput ( DataFlow:: ParameterNode p ) {
393
- result = parameterAccess ( p . ( NodeExtended ) . asParameter ( ) )
399
+ result = parameterAccess ( asParameter ( p ) )
394
400
or
395
401
result = qualifierString ( ) and p instanceof InstanceParameterNode
396
402
}
@@ -465,7 +471,7 @@ module MakeModelGenerator<
465
471
predicate isSource ( DataFlow:: Node source , FlowState state ) {
466
472
source instanceof DataFlow:: ParameterNode and
467
473
exists ( Callable c |
468
- c = source . ( NodeExtended ) . getEnclosingCallable ( ) and
474
+ c = getEnclosingCallable ( source ) and
469
475
c instanceof DataFlowSummaryTargetApi and
470
476
not isUninterestingForHeuristicDataFlowModels ( c )
471
477
) and
@@ -475,7 +481,7 @@ module MakeModelGenerator<
475
481
predicate isSink ( DataFlow:: Node sink , FlowState state ) {
476
482
sink instanceof ReturnNodeExt and
477
483
not isOwnInstanceAccessNode ( sink ) and
478
- not exists ( captureQualifierFlow ( sink . ( NodeExtended ) . getAsExprEnclosingCallable ( ) ) ) and
484
+ not exists ( captureQualifierFlow ( getAsExprEnclosingCallable ( sink ) ) ) and
479
485
( state instanceof TaintRead or state instanceof TaintStore )
480
486
}
481
487
@@ -519,8 +525,8 @@ module MakeModelGenerator<
519
525
DataFlowSummaryTargetApi api , DataFlow:: ParameterNode p , ReturnNodeExt returnNodeExt
520
526
) {
521
527
exists ( string input , string output |
522
- p . ( NodeExtended ) . getEnclosingCallable ( ) = api and
523
- returnNodeExt . getEnclosingCallable ( ) = api and
528
+ getEnclosingCallable ( p ) = api and
529
+ getEnclosingCallable ( returnNodeExt ) = api and
524
530
input = parameterNodeAsInput ( p ) and
525
531
output = getOutput ( returnNodeExt ) and
526
532
input != output and
@@ -570,11 +576,12 @@ module MakeModelGenerator<
570
576
private module PropagateContentFlowConfig implements ContentDataFlow:: ConfigSig {
571
577
predicate isSource ( DataFlow:: Node source ) {
572
578
source instanceof DataFlow:: ParameterNode and
573
- source . ( NodeExtended ) . getEnclosingCallable ( ) instanceof DataFlowSummaryTargetApi
579
+ getEnclosingCallable ( source ) instanceof DataFlowSummaryTargetApi
574
580
}
575
581
576
582
predicate isSink ( DataFlow:: Node sink ) {
577
- sink .( ReturnNodeExt ) .getEnclosingCallable ( ) instanceof DataFlowSummaryTargetApi
583
+ sink instanceof ReturnNodeExt and
584
+ getEnclosingCallable ( sink ) instanceof DataFlowSummaryTargetApi
578
585
}
579
586
580
587
predicate isAdditionalFlowStep = isAdditionalContentFlowStep / 2 ;
@@ -613,7 +620,7 @@ module MakeModelGenerator<
613
620
* when used in content flow.
614
621
*/
615
622
private string parameterNodeAsContentInput ( DataFlow:: ParameterNode p ) {
616
- result = parameterContentAccess ( p . ( NodeExtended ) . asParameter ( ) )
623
+ result = parameterContentAccess ( asParameter ( p ) )
617
624
or
618
625
result = qualifierString ( ) and p instanceof InstanceParameterNode
619
626
}
@@ -667,8 +674,8 @@ module MakeModelGenerator<
667
674
PropagateContentFlow:: AccessPath stores , boolean preservesValue
668
675
) {
669
676
PropagateContentFlow:: flow ( p , reads , returnNodeExt , stores , preservesValue ) and
670
- returnNodeExt . getEnclosingCallable ( ) = api and
671
- p . ( NodeExtended ) . getEnclosingCallable ( ) = api
677
+ getEnclosingCallable ( returnNodeExt ) = api and
678
+ getEnclosingCallable ( p ) = api
672
679
}
673
680
674
681
/**
@@ -687,7 +694,7 @@ module MakeModelGenerator<
687
694
private DataFlow:: ParameterNode parameter ;
688
695
689
696
ContentDataFlowSummaryTargetApi ( ) {
690
- count ( string input , string output |
697
+ strictcount ( string input , string output |
691
698
exists (
692
699
PropagateContentFlow:: AccessPath reads , ReturnNodeExt returnNodeExt ,
693
700
PropagateContentFlow:: AccessPath stores
@@ -712,8 +719,8 @@ module MakeModelGenerator<
712
719
PropagateContentFlow:: AccessPath stores , boolean preservesValue
713
720
) {
714
721
PropagateContentFlow:: flow ( p , reads , returnNodeExt , stores , preservesValue ) and
715
- returnNodeExt . getEnclosingCallable ( ) = api and
716
- p . ( NodeExtended ) . getEnclosingCallable ( ) = api and
722
+ getEnclosingCallable ( returnNodeExt ) = api and
723
+ getEnclosingCallable ( p ) = api and
717
724
p = api .getARelevantParameterNode ( )
718
725
}
719
726
@@ -985,7 +992,8 @@ module MakeModelGenerator<
985
992
}
986
993
987
994
predicate isSink ( DataFlow:: Node sink ) {
988
- sink .( ReturnNodeExt ) .getEnclosingCallable ( ) instanceof DataFlowSourceTargetApi
995
+ sink instanceof ReturnNodeExt and
996
+ getEnclosingCallable ( sink ) instanceof DataFlowSourceTargetApi
989
997
}
990
998
991
999
DataFlow:: FlowFeature getAFeature ( ) { result instanceof DataFlow:: FeatureHasSinkCallContext }
@@ -1008,8 +1016,8 @@ module MakeModelGenerator<
1008
1016
exists ( NodeExtended source , ReturnNodeExt sink , string kind |
1009
1017
PropagateFromSource:: flow ( source , sink ) and
1010
1018
sourceNode ( source , kind ) and
1011
- api = sink . getEnclosingCallable ( ) and
1012
- not irrelevantSourceSinkApi ( source . getEnclosingCallable ( ) , api ) and
1019
+ api = getEnclosingCallable ( sink ) and
1020
+ not irrelevantSourceSinkApi ( getEnclosingCallable ( source ) , api ) and
1013
1021
result = ModelPrinting:: asSourceModel ( api , getOutput ( sink ) , kind )
1014
1022
)
1015
1023
}
@@ -1024,7 +1032,7 @@ module MakeModelGenerator<
1024
1032
module PropagateToSinkConfig implements DataFlow:: ConfigSig {
1025
1033
predicate isSource ( DataFlow:: Node source ) {
1026
1034
apiSource ( source ) and
1027
- source . ( NodeExtended ) . getEnclosingCallable ( ) instanceof DataFlowSinkTargetApi
1035
+ getEnclosingCallable ( source ) instanceof DataFlowSinkTargetApi
1028
1036
}
1029
1037
1030
1038
predicate isSink ( DataFlow:: Node sink ) {
@@ -1053,7 +1061,7 @@ module MakeModelGenerator<
1053
1061
exists ( NodeExtended src , NodeExtended sink , string kind |
1054
1062
PropagateToSink:: flow ( src , sink ) and
1055
1063
sinkNode ( sink , kind ) and
1056
- api = src . getEnclosingCallable ( ) and
1064
+ api = getEnclosingCallable ( src ) and
1057
1065
result = ModelPrinting:: asSinkModel ( api , asInputArgument ( src ) , kind )
1058
1066
)
1059
1067
}
0 commit comments