Skip to content

Commit 797966f

Browse files
committed
C++: Change the names of the new classes and predicates to match the upcoming 'CommandExecutionFunction' class.
1 parent 947ab8a commit 797966f

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
private import semmle.code.cpp.models.interfaces.Sql
22
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs
33

4-
private class MySqlSink extends SqlSink {
5-
MySqlSink() { this.hasName(["mysql_query", "mysql_real_query"]) }
4+
private class MySqlExecutionFunction extends SqlExecutionFunction {
5+
MySqlExecutionFunction() { this.hasName(["mysql_query", "mysql_real_query"]) }
66

7-
override predicate getAnSqlParameter(FunctionInput input) { input.isParameterDeref(1) }
7+
override predicate hasSqlArgument(FunctionInput input) { input.isParameterDeref(1) }
88
}

cpp/ql/lib/semmle/code/cpp/models/implementations/PostgreSql.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ private predicate pqxxEscapeArgument(string function, int arg) {
4545
function in ["esc", "esc_raw", "quote", "quote_raw", "quote_name", "quote_table", "esc_like"]
4646
}
4747

48-
private class PostgreSqlSink extends SqlSink {
49-
PostgreSqlSink() {
48+
private class PostgreSqlExecutionFunction extends SqlExecutionFunction {
49+
PostgreSqlExecutionFunction() {
5050
exists(Class c |
5151
this.getDeclaringType() = c and
5252
// transaction exec and connection prepare variations
@@ -60,7 +60,7 @@ private class PostgreSqlSink extends SqlSink {
6060
)
6161
}
6262

63-
override predicate getAnSqlParameter(FunctionInput input) {
63+
override predicate hasSqlArgument(FunctionInput input) {
6464
exists(int argIndex |
6565
pqxxTransactionSqlArgument(this.getName(), argIndex)
6666
or
@@ -71,8 +71,8 @@ private class PostgreSqlSink extends SqlSink {
7171
}
7272
}
7373

74-
private class PostgreSqlBarrier extends SqlBarrier {
75-
PostgreSqlBarrier() {
74+
private class PostgreSqlEscapeFunction extends SqlEscapeFunction {
75+
PostgreSqlEscapeFunction() {
7676
exists(Class c |
7777
this.getDeclaringType() = c and
7878
// transaction and connection escape functions
@@ -84,7 +84,7 @@ private class PostgreSqlBarrier extends SqlBarrier {
8484
)
8585
}
8686

87-
override predicate getAnEscapedParameter(FunctionInput input, FunctionOutput output) {
87+
override predicate escapesSqlArgument(FunctionInput input, FunctionOutput output) {
8888
exists(int argIndex |
8989
input.isParameterDeref(argIndex) and
9090
output.isReturnValueDeref()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
private import semmle.code.cpp.models.interfaces.Sql
22
private import semmle.code.cpp.models.interfaces.FunctionInputsAndOutputs
33

4-
private class SqLite3Sink extends SqlSink {
5-
SqLite3Sink() { this.hasName("sqlite3_exec") }
4+
private class SqLite3ExecutionFunction extends SqlExecutionFunction {
5+
SqLite3ExecutionFunction() { this.hasName("sqlite3_exec") }
66

7-
override predicate getAnSqlParameter(FunctionInput input) { input.isParameterDeref(1) }
7+
override predicate hasSqlArgument(FunctionInput input) { input.isParameterDeref(1) }
88
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/**
22
* Provides abstract classes for modeling functions that execute and escape SQL query strings.
3-
* To use this QL library, create a QL class extending `SqlSink` or `SqlBarrier` with a
4-
* characteristic predicate that selects the function or set of functions you are modeling.
3+
* To use this QL library, create a QL class extending `SqlExecutionFunction` or `SqlEscapeFunction`
4+
* with a characteristic predicate that selects the function or set of functions you are modeling.
55
* Within that class, override the predicates provided by the class to match the way a
6-
* parameter flows into the function and, in the case of `SqlBarrier`, out of the function.
6+
* parameter flows into the function and, in the case of `SqlEscapeFunction`, out of the function.
77
*/
88

99
private import cpp
1010

1111
/**
1212
* An abstract class that represents a function that executes an SQL query.
1313
*/
14-
abstract class SqlSink extends Function {
14+
abstract class SqlExecutionFunction extends Function {
1515
/**
1616
* Holds if `input` to this function represents SQL code to be executed.
1717
*/
18-
abstract predicate getAnSqlParameter(FunctionInput input);
18+
abstract predicate hasSqlArgument(FunctionInput input);
1919
}
2020

2121
/**
2222
* An abstract class that represents a function that escapes an SQL query string.
2323
*/
24-
abstract class SqlBarrier extends Function {
24+
abstract class SqlEscapeFunction extends Function {
2525
/**
2626
* Holds if the `output` escapes the SQL input `input` such that is it safe to pass to
27-
* an `SqlSink`.
27+
* an `SqlExecutionFunction`.
2828
*/
29-
abstract predicate getAnEscapedParameter(FunctionInput input, FunctionOutput output);
29+
abstract predicate escapesSqlArgument(FunctionInput input, FunctionOutput output);
3030
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class SecurityOptions extends string {
3535
* An argument to a function that is passed to a SQL server.
3636
*/
3737
predicate sqlArgument(string function, int arg) {
38-
exists(FunctionInput input, SqlSink sqlSink |
39-
sqlSink.hasName(function) and
38+
exists(FunctionInput input, SqlExecutionFunction sql |
39+
sql.hasName(function) and
4040
input.isParameterDeref(arg) and
41-
sqlSink.getAnSqlParameter(input)
41+
sql.hasSqlArgument(input)
4242
)
4343
}
4444

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class Configuration extends TaintTrackingConfiguration {
3434
or
3535
e.getUnspecifiedType() instanceof IntegralType
3636
or
37-
exists(SqlBarrier sqlFunc, int arg, FunctionInput input |
38-
e = sqlFunc.getACallToThisFunction().getArgument(arg) and
37+
exists(SqlEscapeFunction sql, int arg, FunctionInput input |
38+
e = sql.getACallToThisFunction().getArgument(arg) and
3939
input.isParameterDeref(arg) and
40-
sqlFunc.getAnEscapedParameter(input, _)
40+
sql.escapesSqlArgument(input, _)
4141
)
4242
}
4343
}

0 commit comments

Comments
 (0)