@@ -28,100 +28,99 @@ import semmle.code.cpp.dataflow.new.DataFlow
28
28
* - EVP_MD_CTX
29
29
* - EVP_PKEY_CTX
30
30
*/
31
- private class CTXType extends Type {
32
- CTXType ( ) { this .getUnspecifiedType ( ) .stripType ( ) .getName ( ) .matches ( "evp_%ctx_%st" ) }
31
+ private class CtxType extends Type {
32
+ CtxType ( ) { this .getUnspecifiedType ( ) .stripType ( ) .getName ( ) .matches ( "evp_%ctx_%st" ) }
33
33
}
34
34
35
35
/**
36
- * A pointer to a CTXType
36
+ * A pointer to a CtxType
37
37
*/
38
- private class CTXPointerExpr extends Expr {
39
- CTXPointerExpr ( ) {
40
- this .getType ( ) instanceof CTXType and
38
+ private class CtxPointerExpr extends Expr {
39
+ CtxPointerExpr ( ) {
40
+ this .getType ( ) instanceof CtxType and
41
41
this .getType ( ) instanceof PointerType
42
42
}
43
43
}
44
44
45
45
/**
46
- * A call argument of type CTXPointerExpr .
46
+ * A call argument of type CtxPointerExpr .
47
47
*/
48
- private class CTXPointerArgument extends CTXPointerExpr {
49
- CTXPointerArgument ( ) { exists ( Call c | c .getAnArgument ( ) = this ) }
48
+ private class CtxPointerArgument extends CtxPointerExpr {
49
+ CtxPointerArgument ( ) { exists ( Call c | c .getAnArgument ( ) = this ) }
50
50
51
51
Call getCall ( ) { result .getAnArgument ( ) = this }
52
52
}
53
53
54
54
/**
55
55
* A call whose target contains 'free' or 'reset' and has an argument of type
56
- * CTXPointerArgument .
56
+ * CtxPointerArgument .
57
57
*/
58
- private class CTXClearCall extends Call {
59
- CTXClearCall ( ) {
58
+ private class CtxClearCall extends Call {
59
+ CtxClearCall ( ) {
60
60
this .getTarget ( ) .getName ( ) .toLowerCase ( ) .matches ( [ "%free%" , "%reset%" ] ) and
61
- this .getAnArgument ( ) instanceof CTXPointerArgument
61
+ this .getAnArgument ( ) instanceof CtxPointerArgument
62
62
}
63
63
}
64
64
65
65
/**
66
66
* A call whose target contains 'copy' and has an argument of type
67
- * CTXPointerArgument .
67
+ * CtxPointerArgument .
68
68
*/
69
- private class CTXCopyOutArgCall extends Call {
70
- CTXCopyOutArgCall ( ) {
69
+ private class CtxCopyOutArgCall extends Call {
70
+ CtxCopyOutArgCall ( ) {
71
71
this .getTarget ( ) .getName ( ) .toLowerCase ( ) .matches ( "%copy%" ) and
72
- this .getAnArgument ( ) instanceof CTXPointerArgument
72
+ this .getAnArgument ( ) instanceof CtxPointerArgument
73
73
}
74
74
}
75
75
76
76
/**
77
77
* A call whose target contains 'dup' and has an argument of type
78
- * CTXPointerArgument .
78
+ * CtxPointerArgument .
79
79
*/
80
- private class CTXCopyReturnCall extends Call {
81
- CTXCopyReturnCall ( ) {
80
+ private class CtxCopyReturnCall extends Call , CtxPointerExpr {
81
+ CtxCopyReturnCall ( ) {
82
82
this .getTarget ( ) .getName ( ) .toLowerCase ( ) .matches ( "%dup%" ) and
83
- this .getAnArgument ( ) instanceof CTXPointerArgument and
84
- this instanceof CTXPointerExpr
83
+ this .getAnArgument ( ) instanceof CtxPointerArgument
85
84
}
86
85
}
87
86
88
87
/**
89
- * Flow from any CTXPointerArgument to any other CTXPointerArgument
88
+ * Flow from any CtxPointerArgument to any other CtxPointerArgument
90
89
*/
91
- module OpenSSLCTXArgumentFlowConfig implements DataFlow:: ConfigSig {
92
- predicate isSource ( DataFlow:: Node source ) { source .asExpr ( ) instanceof CTXPointerArgument }
90
+ module OpenSSLCtxArgumentFlowConfig implements DataFlow:: ConfigSig {
91
+ predicate isSource ( DataFlow:: Node source ) { source .asExpr ( ) instanceof CtxPointerArgument }
93
92
94
- predicate isSink ( DataFlow:: Node sink ) { sink .asExpr ( ) instanceof CTXPointerArgument }
93
+ predicate isSink ( DataFlow:: Node sink ) { sink .asExpr ( ) instanceof CtxPointerArgument }
95
94
96
95
predicate isBarrier ( DataFlow:: Node node ) {
97
- exists ( CTXClearCall c | c .getAnArgument ( ) = node .asExpr ( ) )
96
+ exists ( CtxClearCall c | c .getAnArgument ( ) = node .asExpr ( ) )
98
97
}
99
98
100
99
predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
101
- exists ( CTXCopyOutArgCall c |
100
+ exists ( CtxCopyOutArgCall c |
102
101
c .getAnArgument ( ) = node1 .asExpr ( ) and
103
102
c .getAnArgument ( ) = node2 .asExpr ( ) and
104
103
node1 .asExpr ( ) != node2 .asExpr ( ) and
105
- node2 .asExpr ( ) .getType ( ) instanceof CTXType
104
+ node2 .asExpr ( ) .getType ( ) instanceof CtxType
106
105
)
107
106
or
108
- exists ( CTXCopyReturnCall c |
107
+ exists ( CtxCopyReturnCall c |
109
108
c .getAnArgument ( ) = node1 .asExpr ( ) and
110
109
c = node2 .asExpr ( ) and
111
110
node1 .asExpr ( ) != node2 .asExpr ( ) and
112
- node2 .asExpr ( ) .getType ( ) instanceof CTXType
111
+ node2 .asExpr ( ) .getType ( ) instanceof CtxType
113
112
)
114
113
}
115
114
}
116
115
117
- module OpenSSLCTXArgumentFlow = DataFlow:: Global< OpenSSLCTXArgumentFlowConfig > ;
116
+ module OpenSSLCtxArgumentFlow = DataFlow:: Global< OpenSSLCtxArgumentFlowConfig > ;
118
117
119
118
/**
120
119
* Holds if there is a context flow from the source to the sink.
121
120
*/
122
- predicate ctxArgFlowsToCtxArg ( CTXPointerArgument source , CTXPointerArgument sink ) {
121
+ predicate ctxArgFlowsToCtxArg ( CtxPointerArgument source , CtxPointerArgument sink ) {
123
122
exists ( DataFlow:: Node a , DataFlow:: Node b |
124
- OpenSSLCTXArgumentFlow :: flow ( a , b ) and
123
+ OpenSSLCtxArgumentFlow :: flow ( a , b ) and
125
124
a .asExpr ( ) = source and
126
125
b .asExpr ( ) = sink
127
126
)
0 commit comments