Skip to content

Commit c2b356a

Browse files
committed
C++: add subpaths to DefaultTaintTracking
1 parent a031b2a commit c2b356a

File tree

22 files changed

+56
-0
lines changed

22 files changed

+56
-0
lines changed

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

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

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