Skip to content

Commit 5504562

Browse files
committed
C++: SqlPqxxTainted.ql style fixes
1 parent b1a6394 commit 5504562

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ to <code>sprintf</code>. This leaves the code vulnerable to attack by SQL Inject
1212
<recommendation>
1313

1414
<p>Use a library routine to escape characters in the user-supplied
15-
string before converting it to SQL. Use esc and quote pqxx library functions.</p>
15+
string before converting it to SQL. Use <code>esc</code> and <code>quote</code> pqxx library functions.</p>
1616

1717
</recommendation>
1818
<example>
19-
<sample src="SqlPqxxTainted.c" />
19+
<sample src="SqlPqxxTainted.cpp" />
2020

2121
</example>
2222
<references>

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

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,17 @@ import semmle.code.cpp.security.Security
1616
import semmle.code.cpp.dataflow.TaintTracking
1717
import DataFlow::PathGraph
1818

19-
predicate pqxxTransationClassNames(string class_name, string namespace) {
20-
class_name = "dbtransaction" and namespace = "pqxx"
21-
or
22-
class_name = "nontransaction" and namespace = "pqxx"
23-
or
24-
class_name = "basic_robusttransaction" and namespace = "pqxx"
25-
or
26-
class_name = "robusttransaction" and namespace = "pqxx"
27-
or
28-
class_name = "subtransaction" and namespace = "pqxx"
29-
or
30-
class_name = "transaction" and namespace = "pqxx"
31-
or
32-
class_name = "basic_transaction" and namespace = "pqxx"
33-
or
34-
class_name = "transaction_base" and namespace = "pqxx"
35-
or
36-
class_name = "work" and namespace = "pqxx"
19+
predicate pqxxTransationClassNames(string className, string namespace) {
20+
namespace = "pqxx" and
21+
className in [
22+
"dbtransaction", "nontransaction", "basic_robusttransaction", "robusttransaction",
23+
"subtransaction", "transaction", "basic_transaction", "transaction_base", "work"
24+
]
3725
}
3826

39-
predicate pqxxConnectionClassNames(string class_name, string namespace) {
40-
class_name = "connection_base" and namespace = "pqxx"
41-
or
42-
class_name = "basic_connection" and namespace = "pqxx"
43-
or
44-
class_name = "connection" and namespace = "pqxx"
27+
predicate pqxxConnectionClassNames(string className, string namespace) {
28+
namespace = "pqxx" and
29+
className in ["connection_base", "basic_connection", "connection"]
4530
}
4631

4732
predicate pqxxTransactionSqlArgument(string function, int arg) {
@@ -89,21 +74,7 @@ Expr getPqxxSqlArgument() {
8974

9075
predicate pqxxEscapeArgument(string function, int arg) {
9176
arg = 0 and
92-
(
93-
function = "esc"
94-
or
95-
function = "esc_raw"
96-
or
97-
function = "quote"
98-
or
99-
function = "quote_raw"
100-
or
101-
function = "quote_name"
102-
or
103-
function = "quote_table"
104-
or
105-
function = "esc_like"
106-
)
77+
function in ["esc", "esc_raw", "quote", "quote_raw", "quote_name", "quote_table", "esc_like"]
10778
}
10879

10980
predicate isEscapedPqxxArgument(Expr argExpr) {

0 commit comments

Comments
 (0)