@@ -13,13 +13,32 @@ private import semmle.code.cpp.dataflow.ExternalFlow
1313private import semmle.code.cpp.ir.IR
1414
1515module Input implements InputSig< Location , DataFlowImplSpecific:: CppDataFlow > {
16- private import codeql.util.Void
17-
1816 class SummarizedCallableBase = Function ;
1917
20- class SourceBase = Void ;
18+ abstract private class SourceSinkBase extends Element {
19+ /** Gets the call associated with this element, if any. */
20+ CallInstruction getCall ( ) { none ( ) }
21+
22+ /** Gets the function associated with this element, if any. */
23+ Function getFunction ( ) { none ( ) }
24+
25+ /** Gets the enclosing function of this element. */
26+ abstract Declaration getEnclosingFunction ( ) ;
27+ }
28+
29+ abstract class SourceBase extends SourceSinkBase { }
30+
31+ abstract class SinkBase extends SourceSinkBase { }
32+
33+ private class SourceSinkCall extends SourceBase , SinkBase instanceof Call {
34+ CallInstruction call ;
35+
36+ SourceSinkCall ( ) { call .getUnconvertedResultExpression ( ) = this }
2137
22- class SinkBase = Void ;
38+ final override CallInstruction getCall ( ) { result = call }
39+
40+ final override Declaration getEnclosingFunction ( ) { result = Call .super .getEnclosingFunction ( ) }
41+ }
2342
2443 class FlowSummaryCallBase = CallInstruction ;
2544
@@ -149,9 +168,46 @@ private module StepsInput implements Impl::Private::StepsInputSig {
149168 )
150169 }
151170
152- DataFlowCallable getSourceNodeEnclosingCallable ( Input:: SourceBase source ) { none ( ) }
171+ DataFlowCallable getSourceNodeEnclosingCallable ( Input:: SourceBase source ) {
172+ result .asSourceCallable ( ) = source .getEnclosingFunction ( )
173+ }
174+
175+ private ArgumentNode getSourceNodeArgument (
176+ Input:: SourceBase source , Impl:: Private:: SummaryComponent sc
177+ ) {
178+ exists ( Position pos , DataFlowCall call |
179+ sc = Impl:: Private:: SummaryComponent:: argument ( pos ) and
180+ source .getCall ( ) = call .asCallInstruction ( ) and
181+ result .argumentOf ( call , pos )
182+ )
183+ }
153184
154- Node getSourceNode ( Input:: SourceBase source , Impl:: Private:: SummaryComponentStack s ) { none ( ) }
185+ Node getSourceNode ( Input:: SourceBase source , Impl:: Private:: SummaryComponentStack s ) {
186+ exists ( ReturnKind rk , DataFlowCall call |
187+ s .head ( ) = Impl:: Private:: SummaryComponent:: return ( rk ) and
188+ source .getCall ( ) = call .asCallInstruction ( ) and
189+ result = getAnOutNode ( call , rk )
190+ )
191+ or
192+ exists ( Position pos , DataFlowCallable callable |
193+ s .head ( ) = Impl:: Private:: SummaryComponent:: parameter ( pos ) and
194+ result .( ParameterNode ) .isParameterOf ( callable , pos )
195+ |
196+ exists ( ArgumentNode arg , DataFlowCall call |
197+ arg = getSourceNodeArgument ( source , s .tail ( ) .headOfSingleton ( ) ) and
198+ arg .argumentOf ( call , pos ) and
199+ callable = call .getStaticCallTarget ( )
200+ )
201+ or
202+ source .getFunction ( ) = callable .asSourceCallable ( )
203+ )
204+ or
205+ exists ( Position pos |
206+ s .head ( ) = Impl:: Private:: SummaryComponent:: argument ( pos ) and
207+ result .( PostUpdateNode ) .getPreUpdateNode ( ) =
208+ getSourceNodeArgument ( source , s .headOfSingleton ( ) )
209+ )
210+ }
155211
156212 Node getSinkNode ( Input:: SinkBase sink , Impl:: Private:: SummaryComponent sc ) { none ( ) }
157213}
@@ -310,3 +366,23 @@ module Private {
310366}
311367
312368module Public = Impl:: Public;
369+
370+ private class SourceModelCall extends Public:: SourceElement instanceof Call {
371+ private string namespace ;
372+ private string type ;
373+ private boolean subtypes ;
374+ private string name ;
375+ private string signature ;
376+ private string ext ;
377+
378+ SourceModelCall ( ) {
379+ sourceModel ( namespace , type , subtypes , name , signature , ext , _, _, _, _) and
380+ this .getTarget ( ) = interpretElement ( namespace , type , subtypes , name , signature , ext )
381+ }
382+
383+ override predicate isSource (
384+ string output , string kind , Public:: Provenance provenance , string model
385+ ) {
386+ sourceModel ( namespace , type , subtypes , name , signature , ext , output , kind , provenance , model )
387+ }
388+ }
0 commit comments