Skip to content

Commit 340b40e

Browse files
committed
C++: Modernize cpp/cleartext-storage-buffer.
1 parent 75f3897 commit 340b40e

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,32 @@
1313

1414
import cpp
1515
import semmle.code.cpp.security.BufferWrite
16-
import semmle.code.cpp.security.TaintTracking
1716
import semmle.code.cpp.security.SensitiveExprs
18-
import TaintedWithPath
17+
import semmle.code.cpp.security.Security
18+
import semmle.code.cpp.dataflow.TaintTracking
19+
import DataFlow::PathGraph
1920

20-
class Configuration extends TaintTrackingConfiguration {
21-
override predicate isSink(Element tainted) { exists(BufferWrite w | w.getASource() = tainted) }
21+
/**
22+
* Taint flow from user input to a buffer write.
23+
*/
24+
class ToBufferConfiguration extends TaintTracking::Configuration {
25+
ToBufferConfiguration() { this = "ToBufferConfiguration" }
26+
27+
override predicate isSource(DataFlow::Node source) { isUserInput(source.asExpr(), _) }
28+
29+
override predicate isSink(DataFlow::Node sink) {
30+
exists(BufferWrite w | w.getASource() = sink.asExpr())
31+
}
2232
}
2333

2434
from
25-
BufferWrite w, Expr taintedArg, Expr taintSource, PathNode sourceNode, PathNode sinkNode,
26-
string taintCause, SensitiveExpr dest
35+
ToBufferConfiguration config, BufferWrite w, Expr taintSource, DataFlow::PathNode sourceNode,
36+
DataFlow::PathNode sinkNode, string taintCause, SensitiveExpr dest
2737
where
28-
taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and
38+
config.hasFlowPath(sourceNode, sinkNode) and
39+
taintSource = sourceNode.getNode().asExpr() and
40+
w.getASource() = sinkNode.getNode().asExpr() and
2941
isUserInput(taintSource, taintCause) and
30-
w.getASource() = taintedArg and
3142
dest = w.getDest()
3243
select w, sourceNode, sinkNode,
3344
"This write into buffer '" + dest.toString() + "' may contain unencrypted data from $@",
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
edges
22
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input |
3-
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input |
4-
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input |
5-
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input |
6-
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input indirection |
7-
| test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input indirection |
8-
subpaths
93
nodes
104
| test.cpp:54:17:54:20 | argv | semmle.label | argv |
11-
| test.cpp:54:17:54:20 | argv | semmle.label | argv |
12-
| test.cpp:58:25:58:29 | input | semmle.label | input |
135
| test.cpp:58:25:58:29 | input | semmle.label | input |
14-
| test.cpp:58:25:58:29 | input | semmle.label | input |
15-
| test.cpp:58:25:58:29 | input indirection | semmle.label | input indirection |
16-
| test.cpp:58:25:58:29 | input indirection | semmle.label | input indirection |
6+
subpaths
177
#select
188
| test.cpp:58:3:58:9 | call to sprintf | test.cpp:54:17:54:20 | argv | test.cpp:58:25:58:29 | input | This write into buffer 'passwd' may contain unencrypted data from $@ | test.cpp:54:17:54:20 | argv | user input (argv) |

0 commit comments

Comments
 (0)