Skip to content

Commit e360800

Browse files
authored
Merge pull request #21162 from owen-mc/cpp/mad-barriers
C++: Allow MaD barriers
2 parents 949fc37 + 82e2afc commit e360800

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added `taint` summary models and `sql-injection` barrier models for the mySQL `mysql_real_escape_string` and `mysql_real_escape_string_quote` escaping functions.

cpp/ql/lib/ext/MySql.model.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# partial model of the MySQL api
2+
extensions:
3+
- addsTo:
4+
pack: codeql/cpp-all
5+
extensible: summaryModel
6+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
7+
- ["", "", False, "mysql_real_escape_string", "", "", "Argument[*2]", "Argument[*1]", "taint", "manual"]
8+
- ["", "", False, "mysql_real_escape_string_quote", "", "", "Argument[*2]", "Argument[*1]", "taint", "manual"]
9+
- addsTo:
10+
pack: codeql/cpp-all
11+
extensible: barrierModel
12+
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
13+
- ["", "", False, "mysql_real_escape_string", "", "", "Argument[*1]", "sql-injection", "manual"]
14+
- ["", "", False, "mysql_real_escape_string_quote", "", "", "Argument[*1]", "sql-injection", "manual"]

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,3 @@ private class MySqlExecutionFunction extends SqlExecutionFunction {
1616

1717
override predicate hasSqlArgument(FunctionInput input) { input.isParameterDeref(1) }
1818
}
19-
20-
/**
21-
* The `mysql_real_escape_string` family of functions from the MySQL C API.
22-
*/
23-
private class MySqlBarrierFunction extends SqlBarrierFunction {
24-
MySqlBarrierFunction() {
25-
this.hasName(["mysql_real_escape_string", "mysql_real_escape_string_quote"])
26-
}
27-
28-
override predicate barrierSqlArgument(FunctionInput input, FunctionOutput output) {
29-
input.isParameterDeref(2) and
30-
output.isParameterDeref(1)
31-
}
32-
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ module SqlTaintedConfig implements DataFlow::ConfigSig {
5151
input.isParameterDeref(arg) and
5252
sql.barrierSqlArgument(input, _)
5353
)
54+
or
55+
// barrier defined using models-as-data
56+
barrierNode(node, "sql-injection")
5457
}
5558

5659
predicate observeDiffInformedIncrementalMode() { any() }

0 commit comments

Comments
 (0)