@@ -63,6 +63,15 @@ private class CtxPointerArgument extends CtxPointerExpr {
63
63
Call getCall ( ) { result .getAnArgument ( ) = this }
64
64
}
65
65
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
+
66
75
/**
67
76
* A call whose target contains 'free' or 'reset' and has an argument of type
68
77
* CtxPointerArgument.
@@ -97,10 +106,26 @@ private class CtxCopyReturnCall extends Call, CtxPointerExpr {
97
106
}
98
107
99
108
/**
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.
101
126
*/
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 ) }
104
129
105
130
predicate isSink ( DataFlow:: Node sink ) { sink .asExpr ( ) instanceof CtxPointerArgument }
106
131
@@ -125,15 +150,15 @@ module OpenSSLCtxArgumentFlowConfig implements DataFlow::ConfigSig {
125
150
}
126
151
}
127
152
128
- module OpenSSLCtxArgumentFlow = DataFlow:: Global< OpenSSLCtxArgumentFlowConfig > ;
153
+ module OpenSSLCtxSourceToArgumentFlow = DataFlow:: Global< OpenSSLCtxSourceToArgumentFlowConfig > ;
129
154
130
155
/**
131
156
* Holds if there is a context flow from the source to the sink.
132
157
*/
133
- predicate ctxArgFlowsToCtxArg ( CtxPointerArgument source , CtxPointerArgument sink ) {
158
+ predicate ctxArgOrRetFlowsToCtxArg ( CtxPointerSource source , CtxPointerArgument sink ) {
134
159
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
137
162
b .asExpr ( ) = sink
138
163
)
139
164
}
0 commit comments