Skip to content

Commit efa657d

Browse files
committed
C++: SqlPqxxTainted.ql Add namespace check
1 parent 5504562 commit efa657d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-089/SqlPqxxTainted.ql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ predicate pqxxTransactionSqlArgument(string function, int arg) {
5454
predicate pqxxConnectionSqlArgument(string function, int arg) { function = "prepare" and arg = 1 }
5555

5656
Expr getPqxxSqlArgument() {
57-
exists(FunctionCall fc, Expr e, int argIndex, Type t |
57+
exists(FunctionCall fc, Expr e, int argIndex, UserType t |
5858
// examples: 'work' for 'work.exec(...)'; '->' for 'tx->exec()'.
5959
e = fc.getQualifier() and
6060
// to find ConnectionHandle/TransationHandle and similar classes which override '->' operator behavior
6161
// and return pointer to a connection/transation object
6262
e.getType().refersTo(t) and
6363
// transaction exec and connection prepare variations
6464
(
65-
pqxxTransationClassNames(t.getName(), _) and
65+
pqxxTransationClassNames(t.getName(), t.getNamespace().getName()) and
6666
pqxxTransactionSqlArgument(fc.getTarget().getName(), argIndex)
6767
or
68-
pqxxConnectionClassNames(t.getName(), _) and
68+
pqxxConnectionClassNames(t.getName(), t.getNamespace().getName()) and
6969
pqxxConnectionSqlArgument(fc.getTarget().getName(), argIndex)
7070
) and
7171
result = fc.getArgument(argIndex)
@@ -78,14 +78,17 @@ predicate pqxxEscapeArgument(string function, int arg) {
7878
}
7979

8080
predicate isEscapedPqxxArgument(Expr argExpr) {
81-
exists(FunctionCall fc, Expr e, int argIndex, Type t |
81+
exists(FunctionCall fc, Expr e, int argIndex, UserType t |
8282
// examples: 'work' for 'work.exec(...)'; '->' for 'tx->exec()'.
8383
e = fc.getQualifier() and
8484
// to find ConnectionHandle/TransationHandle and similar classes which override '->' operator behavior
8585
// and return pointer to a connection/transation object
8686
e.getType().refersTo(t) and
8787
// transaction and connection escape functions
88-
(pqxxTransationClassNames(t.getName(), _) or pqxxConnectionClassNames(t.getName(), _)) and
88+
(
89+
pqxxTransationClassNames(t.getName(), t.getNamespace().getName()) or
90+
pqxxConnectionClassNames(t.getName(), t.getNamespace().getName())
91+
) and
8992
pqxxEscapeArgument(fc.getTarget().getName(), argIndex) and
9093
// is escaped arg == argExpr
9194
argExpr = fc.getArgument(argIndex)

0 commit comments

Comments
 (0)