Skip to content

Commit 222cd41

Browse files
committed
C++: Use the new SQL interface in 'Security.qll' and 'SqlTainted.ql'.
1 parent 092fbd6 commit 222cd41

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

cpp/ql/src/Security/CWE/CWE-089/SqlTainted.ql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import cpp
1616
import semmle.code.cpp.security.Security
1717
import semmle.code.cpp.security.FunctionWithWrappers
1818
import semmle.code.cpp.security.TaintTracking
19+
import semmle.code.cpp.security.Sql
1920
import TaintedWithPath
2021

2122
class SQLLikeFunction extends FunctionWithWrappers {
@@ -30,7 +31,15 @@ class Configuration extends TaintTrackingConfiguration {
3031
}
3132

3233
override predicate isBarrier(Expr e) {
33-
super.isBarrier(e) or e.getUnspecifiedType() instanceof IntegralType
34+
super.isBarrier(e)
35+
or
36+
e.getUnspecifiedType() instanceof IntegralType
37+
or
38+
exists(SqlFunctionality sql, int arg, Function func, FunctionInput input |
39+
e = func.getACallToThisFunction().getArgument(arg) and
40+
input.isParameterDeref(arg) and
41+
sql.getAnEscapedParameter(func, input, _)
42+
)
3443
}
3544
}
3645

cpp/ql/src/semmle/code/cpp/security/Security.qll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import semmle.code.cpp.exprs.Expr
77
import semmle.code.cpp.commons.Environment
88
import semmle.code.cpp.security.SecurityOptions
99
import semmle.code.cpp.models.interfaces.FlowSource
10+
private import Sql
1011

1112
/**
1213
* Extend this class to customize the security queries for
@@ -34,13 +35,11 @@ class SecurityOptions extends string {
3435
* An argument to a function that is passed to a SQL server.
3536
*/
3637
predicate sqlArgument(string function, int arg) {
37-
// MySQL C API
38-
function = "mysql_query" and arg = 1
39-
or
40-
function = "mysql_real_query" and arg = 1
41-
or
42-
// SQLite3 C API
43-
function = "sqlite3_exec" and arg = 1
38+
exists(Function func, FunctionInput input, SqlFunctionality sql |
39+
func.hasName(function) and
40+
input.isParameterDeref(arg) and
41+
sql.getAnSqlParameter(func, input)
42+
)
4443
}
4544

4645
/**

0 commit comments

Comments
 (0)