Skip to content

Commit 6c40cda

Browse files
committed
C++: Pragmatic solution to include more sinks (plus autoformat changes).
1 parent 703f18b commit 6c40cda

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

cpp/ql/src/Security/CWE/CWE-497/ExposedSystemData.ql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,20 @@ class ExposedSystemDataConfiguration extends TaintTracking::Configuration {
296296
exists(FunctionCall fc, FunctionInput input, int arg |
297297
fc.getTarget().(RemoteFlowSinkFunction).hasRemoteFlowSink(input, _) and
298298
input.isParameterDeref(arg) and
299-
fc.getArgument(arg) = sink.asExpr()
299+
fc.getArgument(arg).getAChild*() = sink.asExpr()
300300
)
301301
}
302302
}
303303

304304
from ExposedSystemDataConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
305-
where config.hasFlowPath(source, sink)
306-
and not exists(DataFlow::Node alt | // remove duplicate results on conversions
307-
config.hasFlow(source.getNode(), alt) and
308-
alt.asConvertedExpr() = sink.getNode().asExpr() and
309-
alt != sink.getNode()
310-
)
305+
where
306+
config.hasFlowPath(source, sink) and
307+
not exists(
308+
DataFlow::Node alt // remove duplicate results on conversions
309+
|
310+
config.hasFlow(source.getNode(), alt) and
311+
alt.asConvertedExpr() = sink.getNode().asExpr() and
312+
alt != sink.getNode()
313+
)
311314
select sink, source, sink, "This operation exposes system data from $@.", source,
312315
source.getNode().toString()

cpp/ql/test/query-tests/Security/CWE/CWE-497/semmle/tests/ExposedSystemData.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edges
66
| tests2.cpp:78:14:78:34 | call to mysql_get_client_info | tests2.cpp:78:14:78:34 | call to mysql_get_client_info |
77
| tests2.cpp:78:14:78:34 | call to mysql_get_client_info | tests2.cpp:78:14:78:34 | call to mysql_get_client_info |
88
| tests2.cpp:89:42:89:45 | str1 | tests2.cpp:91:14:91:17 | str1 |
9+
| tests2.cpp:99:8:99:15 | call to getpwuid | tests2.cpp:100:14:100:15 | pw |
910
| tests2.cpp:107:3:107:4 | c1 [post update] [ptr] | tests2.cpp:109:14:109:15 | c1 [read] [ptr] |
1011
| tests2.cpp:107:6:107:8 | ptr [post update] | tests2.cpp:107:3:107:4 | c1 [post update] [ptr] |
1112
| tests2.cpp:107:12:107:17 | call to getenv | tests2.cpp:107:6:107:8 | ptr [post update] |
@@ -26,6 +27,8 @@ nodes
2627
| tests2.cpp:79:14:79:19 | (const char *)... | semmle.label | (const char *)... |
2728
| tests2.cpp:89:42:89:45 | str1 | semmle.label | str1 |
2829
| tests2.cpp:91:14:91:17 | str1 | semmle.label | str1 |
30+
| tests2.cpp:99:8:99:15 | call to getpwuid | semmle.label | call to getpwuid |
31+
| tests2.cpp:100:14:100:15 | pw | semmle.label | pw |
2932
| tests2.cpp:107:3:107:4 | c1 [post update] [ptr] | semmle.label | c1 [post update] [ptr] |
3033
| tests2.cpp:107:6:107:8 | ptr [post update] | semmle.label | ptr [post update] |
3134
| tests2.cpp:107:12:107:17 | call to getenv | semmle.label | call to getenv |
@@ -40,4 +43,5 @@ subpaths
4043
| tests2.cpp:78:14:78:34 | call to mysql_get_client_info | tests2.cpp:78:14:78:34 | call to mysql_get_client_info | tests2.cpp:78:14:78:34 | call to mysql_get_client_info | This operation exposes system data from $@. | tests2.cpp:78:14:78:34 | call to mysql_get_client_info | call to mysql_get_client_info |
4144
| tests2.cpp:79:14:79:19 | (const char *)... | tests2.cpp:76:18:76:38 | call to mysql_get_client_info | tests2.cpp:79:14:79:19 | (const char *)... | This operation exposes system data from $@. | tests2.cpp:76:18:76:38 | call to mysql_get_client_info | call to mysql_get_client_info |
4245
| tests2.cpp:91:14:91:17 | str1 | tests2.cpp:89:42:89:45 | str1 | tests2.cpp:91:14:91:17 | str1 | This operation exposes system data from $@. | tests2.cpp:89:42:89:45 | str1 | str1 |
46+
| tests2.cpp:100:14:100:15 | pw | tests2.cpp:99:8:99:15 | call to getpwuid | tests2.cpp:100:14:100:15 | pw | This operation exposes system data from $@. | tests2.cpp:99:8:99:15 | call to getpwuid | call to getpwuid |
4347
| tests2.cpp:109:14:109:19 | (const char *)... | tests2.cpp:107:12:107:17 | call to getenv | tests2.cpp:109:14:109:19 | (const char *)... | This operation exposes system data from $@. | tests2.cpp:107:12:107:17 | call to getenv | call to getenv |

cpp/ql/test/query-tests/Security/CWE/CWE-497/semmle/tests/tests2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void test1()
9797
passwd *pw;
9898

9999
pw = getpwuid(val());
100-
send(sock, pw->pw_passwd, val(), val()); // BAD [NOT DETECTED]
100+
send(sock, pw->pw_passwd, val(), val()); // BAD
101101
}
102102

103103
// tests for containers

0 commit comments

Comments
 (0)