Skip to content

Commit 703f18b

Browse files
committed
C++: Better deduplication.
1 parent c4d9c1d commit 703f18b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,17 @@ 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).getFullyConverted() = sink.asConvertedExpr()
299+
fc.getArgument(arg) = sink.asExpr()
300300
)
301301
}
302302
}
303303

304304
from ExposedSystemDataConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
305305
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+
)
306311
select sink, source, sink, "This operation exposes system data from $@.", source,
307312
source.getNode().toString()

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ edges
1212
| tests2.cpp:109:14:109:15 | c1 [read] [ptr] | tests2.cpp:109:14:109:19 | (const char *)... |
1313
nodes
1414
| tests2.cpp:63:13:63:18 | call to getenv | semmle.label | call to getenv |
15+
| tests2.cpp:63:13:63:18 | call to getenv | semmle.label | call to getenv |
1516
| tests2.cpp:63:13:63:26 | (const char *)... | semmle.label | (const char *)... |
1617
| tests2.cpp:64:13:64:18 | call to getenv | semmle.label | call to getenv |
18+
| tests2.cpp:64:13:64:18 | call to getenv | semmle.label | call to getenv |
1719
| tests2.cpp:64:13:64:26 | (const char *)... | semmle.label | (const char *)... |
1820
| tests2.cpp:65:13:65:18 | call to getenv | semmle.label | call to getenv |
21+
| tests2.cpp:65:13:65:18 | call to getenv | semmle.label | call to getenv |
1922
| tests2.cpp:65:13:65:30 | (const char *)... | semmle.label | (const char *)... |
2023
| tests2.cpp:76:18:76:38 | call to mysql_get_client_info | semmle.label | call to mysql_get_client_info |
2124
| tests2.cpp:78:14:78:34 | call to mysql_get_client_info | semmle.label | call to mysql_get_client_info |
@@ -30,9 +33,9 @@ nodes
3033
| tests2.cpp:109:14:109:19 | (const char *)... | semmle.label | (const char *)... |
3134
subpaths
3235
#select
33-
| tests2.cpp:63:13:63:26 | (const char *)... | tests2.cpp:63:13:63:18 | call to getenv | tests2.cpp:63:13:63:26 | (const char *)... | This operation exposes system data from $@. | tests2.cpp:63:13:63:18 | call to getenv | call to getenv |
34-
| tests2.cpp:64:13:64:26 | (const char *)... | tests2.cpp:64:13:64:18 | call to getenv | tests2.cpp:64:13:64:26 | (const char *)... | This operation exposes system data from $@. | tests2.cpp:64:13:64:18 | call to getenv | call to getenv |
35-
| tests2.cpp:65:13:65:30 | (const char *)... | tests2.cpp:65:13:65:18 | call to getenv | tests2.cpp:65:13:65:30 | (const char *)... | This operation exposes system data from $@. | tests2.cpp:65:13:65:18 | call to getenv | call to getenv |
36+
| tests2.cpp:63:13:63:18 | call to getenv | tests2.cpp:63:13:63:18 | call to getenv | tests2.cpp:63:13:63:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:63:13:63:18 | call to getenv | call to getenv |
37+
| tests2.cpp:64:13:64:18 | call to getenv | tests2.cpp:64:13:64:18 | call to getenv | tests2.cpp:64:13:64:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:64:13:64:18 | call to getenv | call to getenv |
38+
| tests2.cpp:65:13:65:18 | call to getenv | tests2.cpp:65:13:65:18 | call to getenv | tests2.cpp:65:13:65:18 | call to getenv | This operation exposes system data from $@. | tests2.cpp:65:13:65:18 | call to getenv | call to getenv |
3639
| 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 |
3740
| 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 |
3841
| 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 |

0 commit comments

Comments
 (0)