Skip to content

Commit 416977d

Browse files
committed
Swift: Add test cases for removeFirst, removeLast.
1 parent 7a1c380 commit 416977d

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
edges
2-
| StringLengthConflation.swift:101:34:101:36 | .count : | StringLengthConflation.swift:101:34:101:44 | ... call to -(_:_:) ... |
3-
| StringLengthConflation.swift:102:36:102:38 | .count : | StringLengthConflation.swift:102:36:102:46 | ... call to -(_:_:) ... |
4-
| StringLengthConflation.swift:107:36:107:38 | .count : | StringLengthConflation.swift:107:36:107:46 | ... call to -(_:_:) ... |
5-
| StringLengthConflation.swift:108:38:108:40 | .count : | StringLengthConflation.swift:108:38:108:48 | ... call to -(_:_:) ... |
62
| StringLengthConflation.swift:113:34:113:36 | .count : | StringLengthConflation.swift:113:34:113:44 | ... call to -(_:_:) ... |
73
| StringLengthConflation.swift:114:36:114:38 | .count : | StringLengthConflation.swift:114:36:114:46 | ... call to -(_:_:) ... |
8-
| StringLengthConflation.swift:120:28:120:30 | .count : | StringLengthConflation.swift:120:28:120:38 | ... call to -(_:_:) ... |
4+
| StringLengthConflation.swift:119:36:119:38 | .count : | StringLengthConflation.swift:119:36:119:46 | ... call to -(_:_:) ... |
5+
| StringLengthConflation.swift:120:38:120:40 | .count : | StringLengthConflation.swift:120:38:120:48 | ... call to -(_:_:) ... |
6+
| StringLengthConflation.swift:125:34:125:36 | .count : | StringLengthConflation.swift:125:34:125:44 | ... call to -(_:_:) ... |
7+
| StringLengthConflation.swift:126:36:126:38 | .count : | StringLengthConflation.swift:126:36:126:46 | ... call to -(_:_:) ... |
8+
| StringLengthConflation.swift:132:28:132:30 | .count : | StringLengthConflation.swift:132:28:132:38 | ... call to -(_:_:) ... |
99
nodes
1010
| StringLengthConflation.swift:72:33:72:35 | .count | semmle.label | .count |
1111
| StringLengthConflation.swift:78:47:78:49 | .count | semmle.label | .count |
12-
| StringLengthConflation.swift:101:34:101:36 | .count : | semmle.label | .count : |
13-
| StringLengthConflation.swift:101:34:101:44 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
14-
| StringLengthConflation.swift:102:36:102:38 | .count : | semmle.label | .count : |
15-
| StringLengthConflation.swift:102:36:102:46 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
16-
| StringLengthConflation.swift:107:36:107:38 | .count : | semmle.label | .count : |
17-
| StringLengthConflation.swift:107:36:107:46 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
18-
| StringLengthConflation.swift:108:38:108:40 | .count : | semmle.label | .count : |
19-
| StringLengthConflation.swift:108:38:108:48 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
2012
| StringLengthConflation.swift:113:34:113:36 | .count : | semmle.label | .count : |
2113
| StringLengthConflation.swift:113:34:113:44 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
2214
| StringLengthConflation.swift:114:36:114:38 | .count : | semmle.label | .count : |
2315
| StringLengthConflation.swift:114:36:114:46 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
24-
| StringLengthConflation.swift:120:28:120:30 | .count : | semmle.label | .count : |
25-
| StringLengthConflation.swift:120:28:120:38 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
16+
| StringLengthConflation.swift:119:36:119:38 | .count : | semmle.label | .count : |
17+
| StringLengthConflation.swift:119:36:119:46 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
18+
| StringLengthConflation.swift:120:38:120:40 | .count : | semmle.label | .count : |
19+
| StringLengthConflation.swift:120:38:120:48 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
20+
| StringLengthConflation.swift:125:34:125:36 | .count : | semmle.label | .count : |
21+
| StringLengthConflation.swift:125:34:125:44 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
22+
| StringLengthConflation.swift:126:36:126:38 | .count : | semmle.label | .count : |
23+
| StringLengthConflation.swift:126:36:126:46 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
24+
| StringLengthConflation.swift:132:28:132:30 | .count : | semmle.label | .count : |
25+
| StringLengthConflation.swift:132:28:132:38 | ... call to -(_:_:) ... | semmle.label | ... call to -(_:_:) ... |
2626
subpaths
2727
#select
2828
| StringLengthConflation.swift:72:33:72:35 | .count | StringLengthConflation.swift:72:33:72:35 | .count | StringLengthConflation.swift:72:33:72:35 | .count | This String length is used in an NSString, but it may not be equivalent. |
2929
| StringLengthConflation.swift:78:47:78:49 | .count | StringLengthConflation.swift:78:47:78:49 | .count | StringLengthConflation.swift:78:47:78:49 | .count | This String length is used in an NSString, but it may not be equivalent. |
30-
| StringLengthConflation.swift:101:34:101:44 | ... call to -(_:_:) ... | StringLengthConflation.swift:101:34:101:36 | .count : | StringLengthConflation.swift:101:34:101:44 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
31-
| StringLengthConflation.swift:102:36:102:46 | ... call to -(_:_:) ... | StringLengthConflation.swift:102:36:102:38 | .count : | StringLengthConflation.swift:102:36:102:46 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
32-
| StringLengthConflation.swift:107:36:107:46 | ... call to -(_:_:) ... | StringLengthConflation.swift:107:36:107:38 | .count : | StringLengthConflation.swift:107:36:107:46 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
33-
| StringLengthConflation.swift:108:38:108:48 | ... call to -(_:_:) ... | StringLengthConflation.swift:108:38:108:40 | .count : | StringLengthConflation.swift:108:38:108:48 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
3430
| StringLengthConflation.swift:113:34:113:44 | ... call to -(_:_:) ... | StringLengthConflation.swift:113:34:113:36 | .count : | StringLengthConflation.swift:113:34:113:44 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
3531
| StringLengthConflation.swift:114:36:114:46 | ... call to -(_:_:) ... | StringLengthConflation.swift:114:36:114:38 | .count : | StringLengthConflation.swift:114:36:114:46 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
36-
| StringLengthConflation.swift:120:28:120:38 | ... call to -(_:_:) ... | StringLengthConflation.swift:120:28:120:30 | .count : | StringLengthConflation.swift:120:28:120:38 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
32+
| StringLengthConflation.swift:119:36:119:46 | ... call to -(_:_:) ... | StringLengthConflation.swift:119:36:119:38 | .count : | StringLengthConflation.swift:119:36:119:46 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
33+
| StringLengthConflation.swift:120:38:120:48 | ... call to -(_:_:) ... | StringLengthConflation.swift:120:38:120:40 | .count : | StringLengthConflation.swift:120:38:120:48 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
34+
| StringLengthConflation.swift:125:34:125:44 | ... call to -(_:_:) ... | StringLengthConflation.swift:125:34:125:36 | .count : | StringLengthConflation.swift:125:34:125:44 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
35+
| StringLengthConflation.swift:126:36:126:46 | ... call to -(_:_:) ... | StringLengthConflation.swift:126:36:126:38 | .count : | StringLengthConflation.swift:126:36:126:46 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |
36+
| StringLengthConflation.swift:132:28:132:38 | ... call to -(_:_:) ... | StringLengthConflation.swift:132:28:132:30 | .count : | StringLengthConflation.swift:132:28:132:38 | ... call to -(_:_:) ... | This String length is used in an NSString, but it may not be equivalent. |

swift/ql/test/query-tests/Security/CWE-135/StringLengthConflation.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ func test(s: String) {
9696
let str8 = s.suffix(ns.length - 1) // BAD: NSString length used in String [NOT DETECTED]
9797
print("suffix '\(str7)' / '\(str8)'")
9898

99+
var str9 = s
100+
str9.removeFirst(s.count - 1) // GOOD
101+
var str10 = s
102+
str10.removeFirst(ns.length - 1) // BAD: NSString length used in String [NOT DETECTED]
103+
print("removeFirst '\(str9)' / '\(str10)'")
104+
105+
var str11 = s
106+
str11.removeLast(s.count - 1) // GOOD
107+
var str12 = s
108+
str12.removeLast(ns.length - 1) // BAD: NSString length used in String [NOT DETECTED]
109+
print("removeLast '\(str11)' / '\(str12)'")
110+
99111
let nstr1 = ns.character(at: ns.length - 1) // GOOD
100112
let nmstr1 = nms.character(at: nms.length - 1) // GOOD
101113
let nstr2 = ns.character(at: s.count - 1) // BAD: String length used in NSString

0 commit comments

Comments
 (0)