Skip to content

Commit b3d838d

Browse files
committed
C++: Define the sources more clearly and consistently (fixes performance issue).
1 parent 3b5b121 commit b3d838d

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

cpp/ql/src/Security/CWE/CWE-311/CleartextBufferWrite.ql

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,30 @@ import semmle.code.cpp.ir.dataflow.TaintTracking
1919
import 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 {
25+
BufferWrite::BufferWrite write;
26+
27+
SensitiveBufferWrite() {
28+
this = write and
29+
write.getDest() instanceof SensitiveExpr
30+
}
31+
32+
/**
33+
* Gets a data source of this operation.
34+
*/
35+
Expr getASource() { result = write.getASource() }
36+
37+
/**
38+
* Gets the destination buffer of this operation.
39+
*/
40+
Expr getDest() { result = write.getDest() }
41+
}
42+
43+
/**
44+
* A taint flow configuration for flow from user input to a buffer write
45+
* into a sensitive expression.
2346
*/
2447
class ToBufferConfiguration extends TaintTracking::Configuration {
2548
ToBufferConfiguration() { this = "ToBufferConfiguration" }
@@ -31,12 +54,12 @@ class ToBufferConfiguration extends TaintTracking::Configuration {
3154
}
3255

3356
override predicate isSink(DataFlow::Node sink) {
34-
exists(BufferWrite::BufferWrite w | w.getASource() = sink.asExpr())
57+
exists(SensitiveBufferWrite w | w.getASource() = sink.asExpr())
3558
}
3659
}
3760

3861
from
39-
ToBufferConfiguration config, BufferWrite::BufferWrite w, DataFlow::PathNode sourceNode,
62+
ToBufferConfiguration config, SensitiveBufferWrite w, DataFlow::PathNode sourceNode,
4063
DataFlow::PathNode sinkNode, FlowSource source, SensitiveExpr dest
4164
where
4265
config.hasFlowPath(sourceNode, sinkNode) and

0 commit comments

Comments
 (0)