Skip to content

Commit e0c8a8e

Browse files
authored
Merge pull request github#11458 from geoffw0/simplify
Swift: Simplify some QL.
2 parents 0cd50aa + edb6325 commit e0c8a8e

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ class StaticInitializationVectorSource extends Expr {
3232
class EncryptionInitializationSink extends Expr {
3333
EncryptionInitializationSink() {
3434
// `iv` arg in `init` is a sink
35-
exists(CallExpr call, string fName, int arg |
35+
exists(CallExpr call, string fName |
3636
call.getStaticTarget()
3737
.(MethodDecl)
3838
.hasQualifiedName([
3939
"AES", "ChaCha20", "Blowfish", "Rabbit", "CBC", "CFB", "GCM", "OCB", "OFB", "PCBC",
4040
"CCM", "CTR"
4141
], fName) and
42-
fName.matches("%init(%iv:%") and
43-
arg = [0, 1] and
44-
call.getStaticTarget().(MethodDecl).getParam(pragma[only_bind_into](arg)).getName() = "iv" and
45-
call.getArgument(pragma[only_bind_into](arg)).getExpr() = this
42+
fName.matches("%init(%") and
43+
call.getArgumentWithLabel("iv").getExpr() = this
4644
)
4745
}
4846
}

swift/ql/src/queries/Security/CWE-135/StringLengthConflation.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
162162
call.getStaticTarget() = funcDecl and
163163
flowstate = "String"
164164
) and
165-
// match up `funcName`, `paramName`, `arg`, `node`.
165+
// match up `funcName`, `arg`, `node`.
166166
funcDecl.getName() = funcName and
167167
call.getArgument(arg).getExpr() = node.asExpr()
168168
)

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ 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, int arg |
35+
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call |
3636
c.getFullName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and
3737
c.getAMember() = f and
38-
f.getName().matches("%init(%password:%") and
38+
f.getName().matches("%init(%") and
3939
call.getStaticTarget() = f and
40-
f.getParam(pragma[only_bind_into](arg)).getName() = "password" and
41-
call.getArgument(pragma[only_bind_into](arg)).getExpr() = this
40+
call.getArgumentWithLabel("password").getExpr() = this
4241
)
4342
}
4443
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ 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, int arg |
35+
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call |
3636
c.getFullName() = ["HKDF", "PBKDF1", "PBKDF2", "Scrypt"] and
3737
c.getAMember() = f and
38-
f.getName().matches("%init(%salt:%") and
38+
f.getName().matches("%init(%") and
3939
call.getStaticTarget() = f and
40-
f.getParam(pragma[only_bind_into](arg)).getName() = "salt" and
41-
call.getArgument(pragma[only_bind_into](arg)).getExpr() = this
40+
call.getArgumentWithLabel("salt").getExpr() = this
4241
)
4342
}
4443
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ 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, int arg |
36+
exists(ClassOrStructDecl c, AbstractFunctionDecl f, CallExpr call |
3737
c.getFullName() = ["PBKDF1", "PBKDF2"] and
3838
c.getAMember() = f and
39-
f.getName().matches("init(%iterations:%") and
39+
f.getName().matches("init(%") and
4040
call.getStaticTarget() = f and
41-
f.getParam(pragma[only_bind_into](arg)).getName() = "iterations" and
42-
call.getArgument(pragma[only_bind_into](arg)).getExpr() = this
41+
call.getArgumentWithLabel("iterations").getExpr() = this
4342
)
4443
}
4544
}

0 commit comments

Comments
 (0)