@@ -63,6 +63,15 @@ private class CtxPointerArgument extends CtxPointerExpr {
6363 Call getCall ( ) { result .getAnArgument ( ) = this }
6464}
6565
66+ /**
67+ * A call returning a CtxPointerExpr.
68+ */
69+ private class CtxPointerReturn extends CtxPointerExpr {
70+ CtxPointerReturn ( ) { exists ( Call c | c = this ) }
71+
72+ Call getCall ( ) { result = this .( Call ) }
73+ }
74+
6675/**
6776 * A call whose target contains 'free' or 'reset' and has an argument of type
6877 * CtxPointerArgument.
@@ -97,10 +106,26 @@ private class CtxCopyReturnCall extends Call, CtxPointerExpr {
97106}
98107
99108/**
100- * Flow from any CtxPointerArgument to any other CtxPointerArgument
109+ * A source Ctx of interest is any argument or return of type CtxPointerExpr.
110+ */
111+ private class CtxPointerSource extends CtxPointerExpr {
112+ CtxPointerSource ( ) {
113+ this instanceof CtxPointerReturn or
114+ this instanceof CtxPointerArgument
115+ }
116+
117+ DataFlow:: Node asNode ( ) {
118+ result .asExpr ( ) = this
119+ or
120+ result .asDefiningArgument ( ) = this
121+ }
122+ }
123+
124+ /**
125+ * Flow from any CtxPointerSource to any CtxPointerArgument.
101126 */
102- module OpenSSLCtxArgumentFlowConfig implements DataFlow:: ConfigSig {
103- predicate isSource ( DataFlow:: Node source ) { source . asExpr ( ) instanceof CtxPointerArgument }
127+ module OpenSSLCtxSourceToArgumentFlowConfig implements DataFlow:: ConfigSig {
128+ predicate isSource ( DataFlow:: Node source ) { exists ( CtxPointerSource s | s . asNode ( ) = source ) }
104129
105130 predicate isSink ( DataFlow:: Node sink ) { sink .asExpr ( ) instanceof CtxPointerArgument }
106131
@@ -125,15 +150,15 @@ module OpenSSLCtxArgumentFlowConfig implements DataFlow::ConfigSig {
125150 }
126151}
127152
128- module OpenSSLCtxArgumentFlow = DataFlow:: Global< OpenSSLCtxArgumentFlowConfig > ;
153+ module OpenSSLCtxSourceToArgumentFlow = DataFlow:: Global< OpenSSLCtxSourceToArgumentFlowConfig > ;
129154
130155/**
131156 * Holds if there is a context flow from the source to the sink.
132157 */
133- predicate ctxArgFlowsToCtxArg ( CtxPointerArgument source , CtxPointerArgument sink ) {
158+ predicate ctxArgOrRetFlowsToCtxArg ( CtxPointerSource source , CtxPointerArgument sink ) {
134159 exists ( DataFlow:: Node a , DataFlow:: Node b |
135- OpenSSLCtxArgumentFlow :: flow ( a , b ) and
136- a . asExpr ( ) = source and
160+ OpenSSLCtxSourceToArgumentFlow :: flow ( a , b ) and
161+ a = source . asNode ( ) and
137162 b .asExpr ( ) = sink
138163 )
139164}
0 commit comments