@@ -19,7 +19,25 @@ import semmle.code.cpp.ir.dataflow.TaintTracking
19
19
import DataFlow:: PathGraph
20
20
21
21
/**
22
- * A taint flow configuration for flow from user input to a buffer write.
22
+ * A buffer write into a sensitive expression.
23
+ */
24
+ class SensitiveBufferWrite extends Expr instanceof BufferWrite:: BufferWrite {
25
+ SensitiveBufferWrite ( ) { super .getDest ( ) instanceof SensitiveExpr }
26
+
27
+ /**
28
+ * Gets a data source of this operation.
29
+ */
30
+ Expr getASource ( ) { result = super .getASource ( ) }
31
+
32
+ /**
33
+ * Gets the destination buffer of this operation.
34
+ */
35
+ Expr getDest ( ) { result = super .getDest ( ) }
36
+ }
37
+
38
+ /**
39
+ * A taint flow configuration for flow from user input to a buffer write
40
+ * into a sensitive expression.
23
41
*/
24
42
class ToBufferConfiguration extends TaintTracking:: Configuration {
25
43
ToBufferConfiguration ( ) { this = "ToBufferConfiguration" }
@@ -31,18 +49,17 @@ class ToBufferConfiguration extends TaintTracking::Configuration {
31
49
}
32
50
33
51
override predicate isSink ( DataFlow:: Node sink ) {
34
- exists ( BufferWrite :: BufferWrite w | w .getASource ( ) = sink .asExpr ( ) )
52
+ exists ( SensitiveBufferWrite w | w .getASource ( ) = sink .asExpr ( ) )
35
53
}
36
54
}
37
55
38
56
from
39
- ToBufferConfiguration config , BufferWrite :: BufferWrite w , DataFlow:: PathNode sourceNode ,
40
- DataFlow:: PathNode sinkNode , FlowSource source , SensitiveExpr dest
57
+ ToBufferConfiguration config , SensitiveBufferWrite w , DataFlow:: PathNode sourceNode ,
58
+ DataFlow:: PathNode sinkNode , FlowSource source
41
59
where
42
60
config .hasFlowPath ( sourceNode , sinkNode ) and
43
61
sourceNode .getNode ( ) = source and
44
- w .getASource ( ) = sinkNode .getNode ( ) .asExpr ( ) and
45
- dest = w .getDest ( )
62
+ w .getASource ( ) = sinkNode .getNode ( ) .asExpr ( )
46
63
select w , sourceNode , sinkNode ,
47
- "This write into buffer '" + dest . toString ( ) + "' may contain unencrypted data from $@." , source ,
48
- "user input (" + source .getSourceType ( ) + ")"
64
+ "This write into buffer '" + w . getDest ( ) . toString ( ) + "' may contain unencrypted data from $@." ,
65
+ source , "user input (" + source .getSourceType ( ) + ")"
0 commit comments