Skip to content

Commit 8836cba

Browse files
committed
C++: Make sure we use an indirect sink only for the sinks that receive a
pointer to the data. Also fix a bug where we used 'asExpr' instead of 'asIndirectExpr'.
1 parent 620c69d commit 8836cba

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
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
}

0 commit comments

Comments
 (0)