Skip to content

Commit aa09361

Browse files
authored
Merge pull request github#12407 from MathiasVP/fix-internal-system-data-tests
2 parents 620c69d + d2d91cf commit aa09361

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ class PotentiallyExposedSystemDataConfiguration extends TaintTracking::Configura
3939
}
4040

4141
override predicate isSink(DataFlow::Node sink) {
42-
exists(OutputWrite ow | ow.getASource().getAChild*() = sink.asIndirectExpr())
42+
exists(OutputWrite ow, Expr child | child = ow.getASource().getAChild*() |
43+
// Most sinks receive a pointer as an argument (for example `printf`),
44+
// and we use an indirect sink for those.
45+
// However, some sinks (for example `puts`) receive receive a single
46+
// character as an argument. For those we have to use a direct sink.
47+
if
48+
child.getUnspecifiedType() instanceof PointerType or
49+
child.getUnspecifiedType() instanceof ArrayType
50+
then child = sink.asIndirectExpr()
51+
else child = sink.asExpr()
52+
)
4353
}
4454
}
4555

cpp/ql/src/Security/CWE/CWE-497/SystemData.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private predicate sqlConnectInfo(FunctionCall source, Expr use) {
7272
class SqlConnectInfo extends SystemData {
7373
SqlConnectInfo() { sqlConnectInfo(this, _) }
7474

75-
override DataFlow::Node getAnExpr() { sqlConnectInfo(this, result.asExpr()) }
75+
override DataFlow::Node getAnExpr() { sqlConnectInfo(this, result.asIndirectExpr(1)) }
7676

7777
override predicate isSensitive() { any() }
7878
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ edges
77
| tests2.cpp:65:13:65:18 | call to getenv indirection | tests2.cpp:65:13:65:30 | call to getenv indirection |
88
| tests2.cpp:66:13:66:18 | call to getenv indirection | tests2.cpp:66:13:66:34 | call to getenv indirection |
99
| tests2.cpp:78:18:78:38 | call to mysql_get_client_info indirection | tests2.cpp:81:14:81:19 | buffer indirection |
10-
| tests2.cpp:91:42:91:45 | str1 | tests2.cpp:93:14:93:17 | str1 indirection |
10+
| tests2.cpp:91:42:91:45 | str1 indirection | tests2.cpp:93:14:93:17 | str1 indirection |
11+
| tests2.cpp:91:42:91:45 | str1 indirection | tests2.cpp:93:14:93:17 | str1 indirection |
12+
| tests2.cpp:91:42:91:45 | str1 indirection | tests2.cpp:93:14:93:17 | str1 indirection |
1113
| tests2.cpp:101:8:101:15 | call to getpwuid indirection | tests2.cpp:102:14:102:15 | pw indirection |
1214
| tests2.cpp:101:8:101:15 | call to getpwuid indirection | tests2.cpp:102:14:102:15 | pw indirection |
1315
| tests2.cpp:109:3:109:36 | ... = ... indirection | tests2.cpp:109:6:109:8 | c1 indirection [post update] [ptr indirection] |
@@ -52,7 +54,10 @@ nodes
5254
| tests2.cpp:81:14:81:19 | buffer indirection | semmle.label | buffer indirection |
5355
| tests2.cpp:82:14:82:20 | global1 indirection | semmle.label | global1 indirection |
5456
| tests2.cpp:82:14:82:20 | global1 indirection | semmle.label | global1 indirection |
55-
| tests2.cpp:91:42:91:45 | str1 | semmle.label | str1 |
57+
| tests2.cpp:91:42:91:45 | str1 indirection | semmle.label | str1 indirection |
58+
| tests2.cpp:91:42:91:45 | str1 indirection | semmle.label | str1 indirection |
59+
| tests2.cpp:93:14:93:17 | str1 indirection | semmle.label | str1 indirection |
60+
| tests2.cpp:93:14:93:17 | str1 indirection | semmle.label | str1 indirection |
5661
| tests2.cpp:93:14:93:17 | str1 indirection | semmle.label | str1 indirection |
5762
| tests2.cpp:101:8:101:15 | call to getpwuid indirection | semmle.label | call to getpwuid indirection |
5863
| tests2.cpp:102:14:102:15 | pw indirection | semmle.label | pw indirection |
@@ -96,7 +101,9 @@ subpaths
96101
| tests2.cpp:81:14:81:19 | buffer indirection | tests2.cpp:78:18:78:38 | call to mysql_get_client_info indirection | tests2.cpp:81:14:81:19 | buffer indirection | This operation exposes system data from $@. | tests2.cpp:78:18:78:38 | call to mysql_get_client_info indirection | call to mysql_get_client_info indirection |
97102
| tests2.cpp:82:14:82:20 | global1 indirection | tests2.cpp:50:23:50:43 | call to mysql_get_client_info indirection | tests2.cpp:82:14:82:20 | global1 indirection | This operation exposes system data from $@. | tests2.cpp:50:23:50:43 | call to mysql_get_client_info indirection | call to mysql_get_client_info indirection |
98103
| tests2.cpp:82:14:82:20 | global1 indirection | tests2.cpp:50:23:50:43 | call to mysql_get_client_info indirection | tests2.cpp:82:14:82:20 | global1 indirection | This operation exposes system data from $@. | tests2.cpp:50:23:50:43 | call to mysql_get_client_info indirection | call to mysql_get_client_info indirection |
99-
| tests2.cpp:93:14:93:17 | str1 indirection | tests2.cpp:91:42:91:45 | str1 | tests2.cpp:93:14:93:17 | str1 indirection | This operation exposes system data from $@. | tests2.cpp:91:42:91:45 | str1 | str1 |
104+
| tests2.cpp:93:14:93:17 | str1 indirection | tests2.cpp:91:42:91:45 | str1 indirection | tests2.cpp:93:14:93:17 | str1 indirection | This operation exposes system data from $@. | tests2.cpp:91:42:91:45 | str1 indirection | str1 indirection |
105+
| tests2.cpp:93:14:93:17 | str1 indirection | tests2.cpp:91:42:91:45 | str1 indirection | tests2.cpp:93:14:93:17 | str1 indirection | This operation exposes system data from $@. | tests2.cpp:91:42:91:45 | str1 indirection | str1 indirection |
106+
| tests2.cpp:93:14:93:17 | str1 indirection | tests2.cpp:91:42:91:45 | str1 indirection | tests2.cpp:93:14:93:17 | str1 indirection | This operation exposes system data from $@. | tests2.cpp:91:42:91:45 | str1 indirection | str1 indirection |
100107
| tests2.cpp:102:14:102:15 | pw indirection | tests2.cpp:101:8:101:15 | call to getpwuid indirection | tests2.cpp:102:14:102:15 | pw indirection | This operation exposes system data from $@. | tests2.cpp:101:8:101:15 | call to getpwuid indirection | call to getpwuid indirection |
101108
| tests2.cpp:102:14:102:15 | pw indirection | tests2.cpp:101:8:101:15 | call to getpwuid indirection | tests2.cpp:102:14:102:15 | pw indirection | This operation exposes system data from $@. | tests2.cpp:101:8:101:15 | call to getpwuid indirection | call to getpwuid indirection |
102109
| tests2.cpp:111:14:111:19 | ptr indirection | tests2.cpp:109:12:109:17 | call to getenv indirection | tests2.cpp:111:14:111:19 | ptr indirection | This operation exposes system data from $@. | tests2.cpp:109:12:109:17 | call to getenv indirection | call to getenv indirection |

0 commit comments

Comments
 (0)