Skip to content

Commit 0dd8f57

Browse files
committed
Swift: Redesign as a FreeFunctionDecl class + add some qldoc.
1 parent cf9c3af commit 0dd8f57

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
private import codeql.swift.generated.decl.AbstractFunctionDecl
22
private import codeql.swift.elements.decl.MethodDecl
33

4+
/**
5+
* A function.
6+
*/
47
class AbstractFunctionDecl extends Generated::AbstractFunctionDecl {
58
override string toString() { result = this.getName() }
69

710
/**
811
* Holds if this function is called `funcName`.
912
*/
1013
predicate hasName(string funcName) { this.getName() = funcName }
14+
}
1115

12-
/**
13-
* Holds if this is a global (non-member) function called `funcName`.
14-
*/
15-
predicate hasGlobalName(string funcName) {
16-
this.hasName(funcName) and
17-
not this instanceof MethodDecl
18-
}
16+
/**
17+
* A free (non-member) function.
18+
*/
19+
class FreeFunctionDecl extends AbstractFunctionDecl {
20+
FreeFunctionDecl() { not this instanceof MethodDecl }
1921
}

swift/ql/lib/codeql/swift/elements/decl/MethodDecl.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ private Decl getAMember(IterableDeclContext ctx) {
99
)
1010
}
1111

12+
/**
13+
* A function that is a member of a class, struct, enum or protocol.
14+
*/
1215
class MethodDecl extends AbstractFunctionDecl {
1316
MethodDecl() {
1417
this = getAMember(any(ClassDecl c))

swift/ql/src/queries/Security/CWE-089/SqlInjection.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class CApiSqlSink extends SqlSink {
2929
// `sqlite3_exec` and variants of `sqlite3_prepare`.
3030
exists(CallExpr call |
3131
call.getStaticTarget()
32-
.hasGlobalName([
32+
.(FreeFunctionDecl)
33+
.hasName([
3334
"sqlite3_exec(_:_:_:_:_:)", "sqlite3_prepare(_:_:_:_:_:)",
3435
"sqlite3_prepare_v2(_:_:_:_:_:)", "sqlite3_prepare_v3(_:_:_:_:_:_:)",
3536
"sqlite3_prepare16(_:_:_:_:_:)", "sqlite3_prepare16_v2(_:_:_:_:_:)",

0 commit comments

Comments
 (0)