1
1
/** Provides classes and predicates related to handling APIs from external libraries. */
2
2
3
3
private import csharp
4
+ private import semmle.code.csharp.dispatch.Dispatch
4
5
private import semmle.code.csharp.dataflow.DataFlow
5
6
private import semmle.code.csharp.dataflow.ExternalFlow
6
7
private import semmle.code.csharp.dataflow.FlowSummary
8
+ private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
7
9
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
8
10
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
9
11
private import semmle.code.csharp.dataflow.TaintTracking
@@ -57,20 +59,25 @@ class ExternalApi extends DataFlowDispatch::DataFlowCallable {
57
59
string getInfo ( ) { result = this .getInfoPrefix ( ) + "#" + this .getSignature ( ) }
58
60
59
61
/** Gets a node that is an input to a call to this API. */
60
- private DataFlow:: Node getAnInput ( ) {
61
- exists ( Call call | call .getTarget ( ) .getUnboundDeclaration ( ) = this |
62
- result .asExpr ( ) = call .getAnArgument ( )
62
+ private ArgumentNode getAnInput ( ) {
63
+ exists ( DispatchCall call |
64
+ result .getCall ( ) .( DataFlowDispatch:: NonDelegateDataFlowCall ) .getDispatchCall ( ) = call
65
+ |
66
+ this = call .getADynamicTarget ( ) .getUnboundDeclaration ( )
67
+ or
68
+ this = call .getAStaticTarget ( ) .getUnboundDeclaration ( )
63
69
)
64
- or
65
- result .( ArgumentNode ) .getCall ( ) .getEnclosingCallable ( ) = this
66
70
}
67
71
68
72
/** Gets a node that is an output from a call to this API. */
69
73
private DataFlow:: Node getAnOutput ( ) {
70
- exists ( Call call | call .getTarget ( ) .getUnboundDeclaration ( ) = this | result .asExpr ( ) = call )
71
- or
72
- result .( PostUpdateNode ) .getPreUpdateNode ( ) .( ArgumentNode ) .getCall ( ) .getEnclosingCallable ( ) =
73
- this
74
+ exists ( DataFlowDispatch:: NonDelegateDataFlowCall call , DataFlowImplCommon:: ReturnKindExt ret |
75
+ result = ret .getAnOutNode ( call )
76
+ |
77
+ this = call .getDispatchCall ( ) .getADynamicTarget ( ) .getUnboundDeclaration ( )
78
+ or
79
+ this = call .getDispatchCall ( ) .getAStaticTarget ( ) .getUnboundDeclaration ( )
80
+ )
74
81
}
75
82
76
83
/** Holds if this API has a supported summary. */
@@ -79,15 +86,15 @@ class ExternalApi extends DataFlowDispatch::DataFlowCallable {
79
86
defaultAdditionalTaintStep ( this .getAnInput ( ) , _)
80
87
}
81
88
82
- /** Holds if this API is is a constructor without parameters */
89
+ /** Holds if this API is is a constructor without parameters. */
83
90
private predicate isParameterlessConstructor ( ) {
84
91
this instanceof Constructor and this .getNumberOfParameters ( ) = 0
85
92
}
86
93
87
- /** Holds if this API is part of a common testing library or framework */
94
+ /** Holds if this API is part of a common testing library or framework. */
88
95
private predicate isTestLibrary ( ) { this .getDeclaringType ( ) instanceof TestLibrary }
89
96
90
- /** Holds if this API is not worth supporting */
97
+ /** Holds if this API is not worth supporting. */
91
98
predicate isUninteresting ( ) { this .isTestLibrary ( ) or this .isParameterlessConstructor ( ) }
92
99
93
100
/** Holds if this API is a known source. */
0 commit comments