Skip to content

Commit f373b7f

Browse files
authored
Merge pull request #11596 from geoffw0/cleartextbufferwrite
C++: Performance fix for cpp/cleartext-storage-buffer
2 parents 5288138 + a8b8b54 commit f373b7f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,25 @@ 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 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
*/
2442
class 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

3856
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
4159
where
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()
4663
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

Comments
 (0)