Skip to content

Commit 5222ba9

Browse files
committed
Swift: Suggestions from review.
1 parent 07b89b8 commit 5222ba9

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,17 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
5858
c.getAMember() = f and // TODO: will this even work if its defined in a parent class?
5959
call.getFunction().(ApplyExpr).getFunction().(DeclRefExpr).getDecl() = f and
6060
call.getFunction().(ApplyExpr).getFunction().toString() = methodName and // TODO: use of toString
61-
call.getFunction()
62-
.(ApplyExpr)
63-
.getFunction()
64-
.(DeclRefExpr)
65-
.getDecl()
66-
.(AbstractFunctionDecl)
67-
.getParam(arg)
68-
.getName() = argName and
61+
f.getParam(arg).getName() = argName and
6962
call.getArgument(arg).getExpr() = node.asExpr() and
7063
flowstate = "String" // `String` length flowing into `NSString`
7164
)
7265
or
7366
// arguments to function calls...
7467
exists(string funcName, string argName, CallExpr call, int arg |
7568
// `NSMakeRange`
76-
funcName = "NSMakeRange" and
69+
funcName = "NSMakeRange(_:_:)" and
7770
argName = ["loc", "len"] and
78-
call.getStaticTarget().getName().matches(funcName + "%") and
71+
call.getStaticTarget().getName() = funcName and
7972
call.getStaticTarget().getParam(arg).getName() = argName and
8073
call.getArgument(arg).getExpr() = node.asExpr() and
8174
flowstate = "String" // `String` length flowing into `NSString`
@@ -85,4 +78,4 @@ class StringLengthConflationConfiguration extends DataFlow::Configuration {
8578

8679
from StringLengthConflationConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
8780
where config.hasFlowPath(source, sink)
88-
select sink, source, sink, "RESULT"
81+
select sink.getNode(), source, sink, "RESULT"

0 commit comments

Comments
 (0)