|
14 | 14 | import cpp
|
15 | 15 | import semmle.code.cpp.security.BufferWrite as BufferWrite
|
16 | 16 | import semmle.code.cpp.security.SensitiveExprs
|
17 |
| -import semmle.code.cpp.security.Security |
| 17 | +import semmle.code.cpp.security.FlowSources |
18 | 18 | import semmle.code.cpp.ir.dataflow.TaintTracking
|
19 | 19 | import DataFlow::PathGraph
|
20 | 20 |
|
21 |
| -Expr exprForNode(DataFlow::Node n) { |
22 |
| - n = DataFlow::exprNode(result) |
23 |
| - or |
24 |
| - // (similar to DefaultTaintTracking's `getNodeForExpr`) |
25 |
| - n = DataFlow::definitionByReferenceNodeFromArgument(result) and |
26 |
| - not argv(result.(VariableAccess).getTarget()) |
27 |
| -} |
28 |
| - |
29 | 21 | /**
|
30 | 22 | * Taint flow from user input to a buffer write.
|
31 | 23 | */
|
32 | 24 | class ToBufferConfiguration extends TaintTracking::Configuration {
|
33 | 25 | ToBufferConfiguration() { this = "ToBufferConfiguration" }
|
34 | 26 |
|
35 |
| - override predicate isSource(DataFlow::Node source) { isUserInput(exprForNode(source), _) } |
| 27 | + override predicate isSource(DataFlow::Node source) { source instanceof FlowSource } |
36 | 28 |
|
37 | 29 | override predicate isSink(DataFlow::Node sink) {
|
38 | 30 | exists(BufferWrite::BufferWrite w | w.getASource() = sink.asExpr())
|
39 | 31 | }
|
40 | 32 | }
|
41 | 33 |
|
42 | 34 | from
|
43 |
| - ToBufferConfiguration config, BufferWrite::BufferWrite w, Expr taintSource, |
44 |
| - DataFlow::PathNode sourceNode, DataFlow::PathNode sinkNode, string taintCause, SensitiveExpr dest |
| 35 | + ToBufferConfiguration config, BufferWrite::BufferWrite w, DataFlow::PathNode sourceNode, |
| 36 | + DataFlow::PathNode sinkNode, FlowSource source, SensitiveExpr dest |
45 | 37 | where
|
46 | 38 | config.hasFlowPath(sourceNode, sinkNode) and
|
47 |
| - taintSource = exprForNode(sourceNode.getNode()) and |
| 39 | + sourceNode.getNode() = source and |
48 | 40 | w.getASource() = sinkNode.getNode().asExpr() and
|
49 |
| - isUserInput(taintSource, taintCause) and |
50 | 41 | dest = w.getDest()
|
51 | 42 | select w, sourceNode, sinkNode,
|
52 |
| - "This write into buffer '" + dest.toString() + "' may contain unencrypted data from $@", |
53 |
| - taintSource, "user input (" + taintCause + ")" |
| 43 | + "This write into buffer '" + dest.toString() + "' may contain unencrypted data from $@", source, |
| 44 | + "user input (" + source.getSourceType() + ")" |
0 commit comments