@@ -19,7 +19,25 @@ import semmle.code.cpp.ir.dataflow.TaintTracking
1919import DataFlow:: PathGraph
2020
2121/**
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.
2341 */
2442class ToBufferConfiguration extends TaintTracking:: Configuration {
2543 ToBufferConfiguration ( ) { this = "ToBufferConfiguration" }
@@ -31,18 +49,17 @@ class ToBufferConfiguration extends TaintTracking::Configuration {
3149 }
3250
3351 override predicate isSink ( DataFlow:: Node sink ) {
34- exists ( BufferWrite :: BufferWrite w | w .getASource ( ) = sink .asExpr ( ) )
52+ exists ( SensitiveBufferWrite w | w .getASource ( ) = sink .asExpr ( ) )
3553 }
3654}
3755
3856from
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
4159where
4260 config .hasFlowPath ( sourceNode , sinkNode ) and
4361 sourceNode .getNode ( ) = source and
44- w .getASource ( ) = sinkNode .getNode ( ) .asExpr ( ) and
45- dest = w .getDest ( )
62+ w .getASource ( ) = sinkNode .getNode ( ) .asExpr ( )
4663select 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