Skip to content

Commit 69541d3

Browse files
authored
Merge pull request #6744 from rdmarsh2/rdmarsh2/dtt-subpath
C++: add subpaths to DefaultTaintTracking
2 parents cb0a567 + 3189c57 commit 69541d3

File tree

22 files changed

+60
-0
lines changed

22 files changed

+60
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/DefaultTaintTracking.qll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,39 @@ module TaintedWithPath {
550550
)
551551
}
552552

553+
/**
554+
* Holds if there is flow from `arg` to `out` across a call that can by summarized by the flow
555+
* from `par` to `ret` within it, in the graph of data flow path explanations.
556+
*/
557+
query predicate subpaths(PathNode arg, PathNode par, PathNode ret, PathNode out) {
558+
DataFlow3::PathGraph::subpaths(arg.(WrapPathNode).inner(), par.(WrapPathNode).inner(),
559+
ret.(WrapPathNode).inner(), out.(WrapPathNode).inner())
560+
or
561+
// To avoid showing trivial-looking steps, we _replace_ the last node instead
562+
// of adding an edge out of it.
563+
exists(WrapPathNode sinkNode |
564+
DataFlow3::PathGraph::subpaths(arg.(WrapPathNode).inner(), par.(WrapPathNode).inner(),
565+
ret.(WrapPathNode).inner(), sinkNode.inner()) and
566+
out.(FinalPathNode).inner() = adjustedSink(sinkNode.inner().getNode())
567+
)
568+
or
569+
// Same for the first node
570+
exists(WrapPathNode sourceNode |
571+
DataFlow3::PathGraph::subpaths(sourceNode.inner(), par.(WrapPathNode).inner(),
572+
ret.(WrapPathNode).inner(), out.(WrapPathNode).inner()) and
573+
sourceNode.inner().getNode() = getNodeForExpr(arg.(InitialPathNode).inner())
574+
)
575+
or
576+
// Finally, handle the case where the path goes directly from a source to a
577+
// sink, meaning that they both need to be translated.
578+
exists(WrapPathNode sinkNode, WrapPathNode sourceNode |
579+
DataFlow3::PathGraph::subpaths(sourceNode.inner(), par.(WrapPathNode).inner(),
580+
ret.(WrapPathNode).inner(), sinkNode.inner()) and
581+
sourceNode.inner().getNode() = getNodeForExpr(arg.(InitialPathNode).inner()) and
582+
out.(FinalPathNode).inner() = adjustedSink(sinkNode.inner().getNode())
583+
)
584+
}
585+
553586
/** Holds if `n` is a node in the graph of data flow path explanations. */
554587
query predicate nodes(PathNode n, string key, string val) {
555588
key = "semmle.label" and val = n.toString()

cpp/ql/test/query-tests/Security/CWE/CWE-022/SAMATE/TaintedPath/TaintedPath.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edges
55
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | (const char *)... |
66
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data |
77
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:77:23:77:26 | data indirection |
8+
subpaths
89
nodes
910
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | ... + ... | semmle.label | ... + ... |
1011
| CWE23_Relative_Path_Traversal__char_console_fopen_11.cpp:55:27:55:38 | fgets output argument | semmle.label | fgets output argument |

cpp/ql/test/query-tests/Security/CWE/CWE-022/semmle/tests/TaintedPath.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edges
55
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName |
66
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection |
77
| test.c:9:23:9:26 | argv | test.c:17:11:17:18 | fileName indirection |
8+
subpaths
89
nodes
910
| test.c:9:23:9:26 | argv | semmle.label | argv |
1011
| test.c:9:23:9:26 | argv | semmle.label | argv |

cpp/ql/test/query-tests/Security/CWE/CWE-079/semmle/CgiXss/CgiXss.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ edges
2424
| search.c:55:17:55:25 | raw_query indirection | search.c:14:24:14:28 | *query |
2525
| search.c:57:5:57:15 | raw_query | search.c:22:24:22:28 | query |
2626
| search.c:57:17:57:25 | raw_query indirection | search.c:22:24:22:28 | *query |
27+
subpaths
2728
nodes
2829
| search.c:14:24:14:28 | *query | semmle.label | *query |
2930
| search.c:14:24:14:28 | query | semmle.label | query |

cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted/SqlTainted.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ edges
1313
| test.cpp:43:27:43:30 | argv | test.cpp:43:27:43:33 | access to array |
1414
| test.cpp:43:27:43:30 | argv | test.cpp:43:27:43:33 | access to array indirection |
1515
| test.cpp:43:27:43:30 | argv | test.cpp:43:27:43:33 | access to array indirection |
16+
subpaths
1617
nodes
1718
| test.c:15:20:15:23 | argv | semmle.label | argv |
1819
| test.c:15:20:15:23 | argv | semmle.label | argv |

cpp/ql/test/query-tests/Security/CWE/CWE-114/SAMATE/UncontrolledProcessOperation/UncontrolledProcessOperation.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ edges
1212
| test.cpp:64:30:64:35 | call to getenv | test.cpp:73:24:73:27 | data indirection |
1313
| test.cpp:73:17:73:22 | data | test.cpp:37:73:37:76 | data |
1414
| test.cpp:73:24:73:27 | data indirection | test.cpp:37:73:37:76 | *data |
15+
subpaths
1516
nodes
1617
| test.cpp:37:73:37:76 | *data | semmle.label | *data |
1718
| test.cpp:37:73:37:76 | data | semmle.label | data |

cpp/ql/test/query-tests/Security/CWE/CWE-114/semmle/UncontrolledProcessOperation/UncontrolledProcessOperation.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ edges
4747
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | (const char *)... |
4848
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | buffer |
4949
| test.cpp:106:17:106:22 | recv output argument | test.cpp:107:15:107:20 | buffer indirection |
50+
subpaths
5051
nodes
5152
| test.cpp:24:30:24:36 | *command | semmle.label | *command |
5253
| test.cpp:24:30:24:36 | command | semmle.label | command |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
edges
2+
subpaths
23
nodes
34
#select
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
edges
2+
subpaths
23
nodes
34
#select

cpp/ql/test/query-tests/Security/CWE/CWE-120/semmle/tests/UnboundedWrite.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ edges
4949
| tests.c:34:10:34:13 | argv | tests.c:34:10:34:16 | access to array |
5050
| tests.c:34:10:34:13 | argv | tests.c:34:10:34:16 | access to array indirection |
5151
| tests.c:34:10:34:13 | argv | tests.c:34:10:34:16 | access to array indirection |
52+
subpaths
5253
nodes
5354
| tests.c:28:22:28:25 | argv | semmle.label | argv |
5455
| tests.c:28:22:28:25 | argv | semmle.label | argv |

0 commit comments

Comments
 (0)