File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed
lib/codeql/swift/elements/decl
src/queries/Security/CWE-089 Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 1
1
private import codeql.swift.generated.decl.AbstractFunctionDecl
2
+ private import codeql.swift.elements.decl.MethodDecl
2
3
3
4
class AbstractFunctionDecl extends Generated:: AbstractFunctionDecl {
4
5
override string toString ( ) { result = this .getName ( ) }
@@ -7,4 +8,12 @@ class AbstractFunctionDecl extends Generated::AbstractFunctionDecl {
7
8
* Holds if this function is called `funcName`.
8
9
*/
9
10
predicate hasName ( string funcName ) { this .getName ( ) = funcName }
11
+
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
+ }
10
19
}
Original file line number Diff line number Diff line change @@ -27,15 +27,14 @@ abstract class SqlSink extends DataFlow::Node { }
27
27
class CApiSqlSink extends SqlSink {
28
28
CApiSqlSink ( ) {
29
29
// `sqlite3_exec` and variants of `sqlite3_prepare`.
30
- exists ( AbstractFunctionDecl f , CallExpr call |
31
- f .getName ( ) =
32
- [
33
- "sqlite3_exec(_:_:_:_:_:)" , "sqlite3_prepare(_:_:_:_:_:)" ,
34
- "sqlite3_prepare_v2(_:_:_:_:_:)" , "sqlite3_prepare_v3(_:_:_:_:_:_:)" ,
35
- "sqlite3_prepare16(_:_:_:_:_:)" , "sqlite3_prepare16_v2(_:_:_:_:_:)" ,
36
- "sqlite3_prepare16_v3(_:_:_:_:_:_:)"
37
- ] and
38
- call .getStaticTarget ( ) = f and
30
+ exists ( CallExpr call |
31
+ call .getStaticTarget ( )
32
+ .hasGlobalName ( [
33
+ "sqlite3_exec(_:_:_:_:_:)" , "sqlite3_prepare(_:_:_:_:_:)" ,
34
+ "sqlite3_prepare_v2(_:_:_:_:_:)" , "sqlite3_prepare_v3(_:_:_:_:_:_:)" ,
35
+ "sqlite3_prepare16(_:_:_:_:_:)" , "sqlite3_prepare16_v2(_:_:_:_:_:)" ,
36
+ "sqlite3_prepare16_v3(_:_:_:_:_:_:)"
37
+ ] ) and
39
38
call .getArgument ( 1 ) .getExpr ( ) = this .asExpr ( )
40
39
)
41
40
}
You can’t perform that action at this time.
0 commit comments