Skip to content

Commit 96e04e7

Browse files
committed
Swift: Use ConstructorDecl in place of name matching.
1 parent e97aee5 commit 96e04e7

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

swift/ql/src/queries/Security/CWE-1204/StaticInitializationVector.ql

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ class EncryptionInitializationSink extends Expr {
3434
// `iv` arg in `init` is a sink
3535
exists(CallExpr call, string fName |
3636
call.getStaticTarget()
37-
.(MethodDecl)
37+
.(ConstructorDecl)
3838
.hasQualifiedName([
3939
"AES", "ChaCha20", "Blowfish", "Rabbit", "CBC", "CFB", "GCM", "OCB", "OFB", "PCBC",
4040
"CCM", "CTR"
4141
], fName) and
42-
fName.matches("%init(%") and
4342
call.getArgumentWithLabel("iv").getExpr() = this
4443
)
4544
}

swift/ql/src/queries/Security/CWE-259/ConstantPassword.ql

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ class ConstantPasswordSource extends Expr {
3232
class ConstantPasswordSink extends Expr {
3333
ConstantPasswordSink() {
3434
// `password` arg in `init` is a sink
35-
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call |
35+
exists(ClassOrStructDecl c, ConstructorDecl f, CallExpr call |
3636
c.getFullName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and
3737
c.getAMember() = f and
38-
f.getName().matches("%init(%") and
3938
call.getStaticTarget() = f and
4039
call.getArgumentWithLabel("password").getExpr() = this
4140
)

swift/ql/src/queries/Security/CWE-760/ConstantSalt.ql

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ class ConstantSaltSource extends Expr {
3232
class ConstantSaltSink extends Expr {
3333
ConstantSaltSink() {
3434
// `salt` arg in `init` is a sink
35-
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call |
35+
exists(ClassOrStructDecl c, ConstructorDecl f, CallExpr call |
3636
c.getFullName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and
3737
c.getAMember() = f and
38-
f.getName().matches("%init(%") and
3938
call.getStaticTarget() = f and
4039
call.getArgumentWithLabel("salt").getExpr() = this
4140
)

swift/ql/src/queries/Security/CWE-916/InsufficientHashIterations.ql

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ class IntLiteralSource extends IterationsSource instanceof IntegerLiteralExpr {
3333
class InsufficientHashIterationsSink extends Expr {
3434
InsufficientHashIterationsSink() {
3535
// `iterations` arg in `init` is a sink
36-
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call |
36+
exists(ClassOrStructDecl c, ConstructorDecl f, CallExpr call |
3737
c.getFullName() = ["PBKDF1", "PBKDF2"] and
3838
c.getAMember() = f and
39-
f.getName().matches("init(%") and
4039
call.getStaticTarget() = f and
4140
call.getArgumentWithLabel("iterations").getExpr() = this
4241
)

0 commit comments

Comments
 (0)