Skip to content

Commit f3b703a

Browse files
committed
updates for module system; include a db
1 parent c1b3c8d commit f3b703a

267 files changed

Lines changed: 56982 additions & 32 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.org

Lines changed: 15 additions & 14 deletions

SqlInjection.ql

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@
22
* @name SQLI Vulnerability
33
* @description Using untrusted strings in a sql query allows sql injection attacks.
44
* @kind path-problem
5-
* @id cpp/SQLIVulnerable
5+
* @id cpp/sqlivulnerable
66
* @problem.severity warning
77
*/
88

99
import cpp
10-
import semmle.code.cpp.dataflow.TaintTracking
11-
import DataFlow::PathGraph
10+
import semmle.code.cpp.dataflow.new.TaintTracking
1211

13-
class SqliFlowConfig extends TaintTracking::Configuration {
14-
SqliFlowConfig() { this = "SqliFlow" }
12+
module SqliFlowConfig implements DataFlow::ConfigSig {
1513

16-
override predicate isSource(DataFlow::Node source) {
14+
predicate isSource(DataFlow::Node source) {
1715
// count = read(STDIN_FILENO, buf, BUFSIZE);
1816
exists(FunctionCall read |
1917
read.getTarget().getName() = "read" and
2018
read.getArgument(1) = source.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr()
2119
)
2220
}
2321

24-
override predicate isSanitizer(DataFlow::Node sanitizer) { none() }
22+
predicate isBarrier(DataFlow::Node sanitizer) { none() }
2523

26-
override predicate isAdditionalTaintStep(DataFlow::Node into, DataFlow::Node out) {
24+
predicate isAdditionalFlowStep(DataFlow::Node into, DataFlow::Node out) {
2725
// Extra taint step
2826
// snprintf(query, bufsize, "INSERT INTO users VALUES (%d, '%s')", id, info);
2927
// But snprintf is a macro on mac os. The actual function's name is
@@ -39,7 +37,7 @@ class SqliFlowConfig extends TaintTracking::Configuration {
3937
)
4038
}
4139

42-
override predicate isSink(DataFlow::Node sink) {
40+
predicate isSink(DataFlow::Node sink) {
4341
// rc = sqlite3_exec(db, query, NULL, 0, &zErrMsg);
4442
exists(FunctionCall exec |
4543
exec.getTarget().getName() = "sqlite3_exec" and
@@ -48,6 +46,9 @@ class SqliFlowConfig extends TaintTracking::Configuration {
4846
}
4947
}
5048

51-
from SqliFlowConfig conf, DataFlow::PathNode source, DataFlow::PathNode sink
52-
where conf.hasFlowPath(source, sink)
49+
module MyFlow = TaintTracking::Global<SqliFlowConfig>;
50+
import MyFlow::PathGraph
51+
52+
from MyFlow::PathNode source, MyFlow::PathNode sink
53+
where MyFlow::flowPath(source, sink)
5354
select sink, source, sink, "Possible SQL injection"

codeql-dataflow-sql-injection.code-workspace

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
}
1313
],
1414
"settings": {
15-
"codeQL.runningQueries.autoSave": true
15+
"codeQL.runningQueries.autoSave": true,
16+
"sarif-viewer.connectToGithubCodeScanning": "off"
1617
}
1718
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"languages":{"cpp":{"displayName":"C/C++","files":["add-user.c"],"linesOfCode":78,"name":"cpp"}}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
sourceLocationPrefix: /Users/hohn/local/codeql-dataflow-sql-injection
3+
baselineLinesOfCode: 78
4+
unicodeNewlines: false
5+
columnKind: utf8
6+
primaryLanguage: cpp
7+
creationMetadata:
8+
sha: c1b3c8d901eacddbb7949a8ca3b8acc11ffbda86
9+
cliVersion: 2.20.0
10+
creationTime: 2025-02-18T01:07:10.558137Z
11+
finalised: true
2.42 KB
Binary file not shown.
Binary file not shown.
896 Bytes
Binary file not shown.
12 Bytes
Binary file not shown.
528 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)