Skip to content

Commit b136790

Browse files
committed
Swift: Clean up isSink (3 - rename f -> funcDecl and move that out as well; in the other two cases this variable didn't exist, now it does).
1 parent 0bd94a6 commit b136790

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
4141
}
4242

4343
override predicate isSink(DataFlow::Node node, string flowstate) {
44-
exists(CallExpr call, string funcName, string paramName, int arg |
44+
exists(
45+
AbstractFunctionDecl funcDecl, CallExpr call, string funcName, string paramName, int arg
46+
|
4547
// arguments to method calls...
46-
exists(string className, ClassDecl c, AbstractFunctionDecl f |
48+
exists(string className, ClassDecl c |
4749
(
4850
// `NSRange.init`
4951
className = "NSRange" and
@@ -71,10 +73,10 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
7173
paramName = "at"
7274
) and
7375
c.getName() = className and
74-
c.getAMember() = f and // TODO: will this even work if its defined in a parent class?
75-
call.getFunction().(ApplyExpr).getStaticTarget() = f and
76-
f.getName() = funcName and
77-
f.getParam(pragma[only_bind_into](arg)).getName() = paramName and
76+
c.getAMember() = funcDecl and // TODO: will this even work if its defined in a parent class?
77+
call.getFunction().(ApplyExpr).getStaticTarget() = funcDecl and
78+
funcDecl.getName() = funcName and
79+
funcDecl.getParam(pragma[only_bind_into](arg)).getName() = paramName and
7880
call.getArgument(pragma[only_bind_into](arg)).getExpr() = node.asExpr() and
7981
flowstate = "String" // `String` length flowing into `NSString`
8082
)
@@ -83,8 +85,9 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
8385
// `NSMakeRange`
8486
funcName = "NSMakeRange(_:_:)" and
8587
paramName = ["loc", "len"] and
86-
call.getStaticTarget().getName() = funcName and
87-
call.getStaticTarget().getParam(pragma[only_bind_into](arg)).getName() = paramName and
88+
call.getStaticTarget() = funcDecl and
89+
funcDecl.getName() = funcName and
90+
funcDecl.getParam(pragma[only_bind_into](arg)).getName() = paramName and
8891
call.getArgument(pragma[only_bind_into](arg)).getExpr() = node.asExpr() and
8992
flowstate = "String" // `String` length flowing into `NSString`
9093
or
@@ -110,12 +113,9 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
110113
funcName = ["formIndex(_:offsetBy:)", "formIndex(_:offsetBy:limitBy:)"] and
111114
paramName = "distance"
112115
) and
113-
call.getFunction().(ApplyExpr).getStaticTarget().getName() = funcName and
114-
call.getFunction()
115-
.(ApplyExpr)
116-
.getStaticTarget()
117-
.getParam(pragma[only_bind_into](arg))
118-
.getName() = paramName and
116+
call.getFunction().(ApplyExpr).getStaticTarget() = funcDecl and
117+
funcDecl.getName() = funcName and
118+
funcDecl.getParam(pragma[only_bind_into](arg)).getName() = paramName and
119119
call.getArgument(pragma[only_bind_into](arg)).getExpr() = node.asExpr() and
120120
flowstate = "NSString" // `NSString` length flowing into `String`
121121
)

0 commit comments

Comments
 (0)