Skip to content

Commit c2c23c8

Browse files
committed
Swift: Address some modelling issues for Swift 6.
1 parent 570393f commit c2c23c8

File tree

4 files changed

+169
-29
lines changed

4 files changed

+169
-29
lines changed

swift/ql/lib/codeql/swift/frameworks/StandardLibrary/Numeric.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ private class NumericSummaries extends SummaryModelCsv {
3535
";BinaryInteger;true;formatted();;;Argument[-1];ReturnValue;taint",
3636
";BinaryInteger;true;formatted(_:);;;Argument[-1];ReturnValue;taint",
3737
";BinaryInteger;true;quotientAndRemainder(dividingBy:);;;Argument[-1..0];ReturnValue.TupleElement[0,1];taint",
38+
";BinaryInteger;true;advanced(by:);;;Argument[-1..0];ReturnValue;taint",
39+
";BinaryInteger;true;distance(to:);;;Argument[-1..0];ReturnValue;taint",
40+
";SignedInteger;true;init(_:);;;Argument[0];ReturnValue;taint",
41+
";SignedInteger;true;init(exactly:);;;Argument[0];ReturnValue.OptionalSome;value",
42+
";UnsignedInteger;true;init(_:);;;Argument[0];ReturnValue;taint",
43+
";UnsignedInteger;true;init(exactly:);;;Argument[0];ReturnValue.OptionalSome;value",
44+
";FixedWidthInteger;true;init(_:);;;Argument[0];ReturnValue;taint",
45+
";FixedWidthInteger;true;init(clamping:);;;Argument[0];ReturnValue;taint",
46+
";FixedWidthInteger;true;init(truncatingIfNeeded:);;;Argument[0];ReturnValue;taint",
47+
";FixedWidthInteger;true;init(bitPattern:);;;Argument[0];ReturnValue;taint", // actually implemented in Int, UInt, Double etc.
48+
";FixedWidthInteger;true;init(truncating:);;;Argument[0];ReturnValue;taint", // actually implemented in Int, UInt, Double etc.
3849
";FixedWidthInteger;true;init(_:radix:);;;Argument[0];ReturnValue.OptionalSome;taint",
3950
";FixedWidthInteger;true;init(littleEndian:);;;Argument[0];ReturnValue;taint",
4051
";FixedWidthInteger;true;init(bigEndian:);;;Argument[0];ReturnValue;taint",
@@ -92,7 +103,7 @@ private class NumericFieldsInheritTaint extends TaintInheritingContent,
92103
className = "BinaryInteger" and
93104
fieldName = "words"
94105
or
95-
className = "Numeric" and
106+
className = ["Numeric", "SignedInteger", "UnsignedInteger"] and
96107
fieldName = ["magnitude", "byteSwapped"]
97108
or
98109
className = "BinaryFloatingPoint" and

swift/ql/test/library-tests/dataflow/taint/core/LocalTaint.expected

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
| conversions.swift:25:33:25:33 | self | conversions.swift:25:33:25:33 | SSA def(self) |
1818
| conversions.swift:26:22:26:22 | SSA def(self) | conversions.swift:26:22:26:38 | self[return] |
1919
| conversions.swift:26:22:26:22 | self | conversions.swift:26:22:26:22 | SSA def(self) |
20+
| conversions.swift:33:16:33:35 | call to sourceInt(_:) | conversions.swift:33:12:33:36 | call to Self.init(_:) |
21+
| conversions.swift:34:17:34:36 | call to sourceInt(_:) | conversions.swift:34:12:34:37 | call to Self.init(_:) |
22+
| conversions.swift:35:18:35:37 | call to sourceInt(_:) | conversions.swift:35:12:35:38 | call to Self.init(_:) |
23+
| conversions.swift:36:18:36:37 | call to sourceInt(_:) | conversions.swift:36:12:36:38 | call to Self.init(_:) |
24+
| conversions.swift:37:18:37:37 | call to sourceInt(_:) | conversions.swift:37:12:37:38 | call to Self.init(_:) |
25+
| conversions.swift:39:17:39:36 | call to sourceInt(_:) | conversions.swift:39:12:39:37 | call to Self.init(_:) |
26+
| conversions.swift:40:18:40:37 | call to sourceInt(_:) | conversions.swift:40:12:40:38 | call to Self.init(_:) |
27+
| conversions.swift:41:19:41:39 | call to sourceInt(_:) | conversions.swift:41:12:41:40 | call to Self.init(_:) |
28+
| conversions.swift:42:19:42:39 | call to sourceInt(_:) | conversions.swift:42:12:42:40 | call to Self.init(_:) |
29+
| conversions.swift:43:19:43:39 | call to sourceInt(_:) | conversions.swift:43:12:43:40 | call to Self.init(_:) |
2030
| conversions.swift:45:18:45:38 | call to sourceInt(_:) | conversions.swift:45:12:45:39 | call to Float.init(_:) |
2131
| conversions.swift:46:19:46:39 | call to sourceInt(_:) | conversions.swift:46:12:46:40 | call to Double.init(_:) |
2232
| conversions.swift:47:19:47:39 | call to sourceInt(_:) | conversions.swift:47:12:47:40 | call to String.init(_:) |
@@ -51,9 +61,11 @@
5161
| conversions.swift:68:6:68:6 | SSA def(v5) | conversions.swift:69:12:69:12 | v5 |
5262
| conversions.swift:68:6:68:6 | v5 | conversions.swift:68:6:68:6 | SSA def(v5) |
5363
| conversions.swift:68:11:68:56 | call to Self.init(truncatingIfNeeded:) | conversions.swift:68:6:68:6 | v5 |
64+
| conversions.swift:68:36:68:55 | call to sourceInt(_:) | conversions.swift:68:11:68:56 | call to Self.init(truncatingIfNeeded:) |
5465
| conversions.swift:71:6:71:6 | SSA def(v6) | conversions.swift:72:12:72:12 | v6 |
5566
| conversions.swift:71:6:71:6 | v6 | conversions.swift:71:6:71:6 | SSA def(v6) |
5667
| conversions.swift:71:11:71:48 | call to UInt.init(bitPattern:) | conversions.swift:71:6:71:6 | v6 |
68+
| conversions.swift:71:28:71:47 | call to sourceInt(_:) | conversions.swift:71:11:71:48 | call to UInt.init(bitPattern:) |
5769
| conversions.swift:74:6:74:6 | SSA def(v7) | conversions.swift:75:12:75:12 | v7 |
5870
| conversions.swift:74:6:74:6 | v7 | conversions.swift:74:6:74:6 | SSA def(v7) |
5971
| conversions.swift:74:11:74:35 | call to abs(_:) | conversions.swift:74:6:74:6 | v7 |
@@ -64,13 +76,25 @@
6476
| conversions.swift:78:12:78:12 | [post] v8 | conversions.swift:79:12:79:12 | v8 |
6577
| conversions.swift:78:12:78:12 | v8 | conversions.swift:79:12:79:12 | v8 |
6678
| conversions.swift:79:12:79:12 | [post] v8 | conversions.swift:80:12:80:12 | v8 |
79+
| conversions.swift:79:12:79:12 | v8 | conversions.swift:79:12:79:29 | call to advanced(by:) |
6780
| conversions.swift:79:12:79:12 | v8 | conversions.swift:80:12:80:12 | v8 |
81+
| conversions.swift:79:28:79:28 | 1 | conversions.swift:79:12:79:29 | call to advanced(by:) |
6882
| conversions.swift:80:12:80:12 | [post] v8 | conversions.swift:81:12:81:12 | v8 |
83+
| conversions.swift:80:12:80:12 | v8 | conversions.swift:80:12:80:48 | call to advanced(by:) |
6984
| conversions.swift:80:12:80:12 | v8 | conversions.swift:81:12:81:12 | v8 |
85+
| conversions.swift:80:28:80:47 | call to sourceInt(_:) | conversions.swift:80:12:80:48 | call to advanced(by:) |
7086
| conversions.swift:81:12:81:12 | [post] v8 | conversions.swift:82:12:82:12 | v8 |
87+
| conversions.swift:81:12:81:12 | v8 | conversions.swift:81:12:81:29 | call to distance(to:) |
7188
| conversions.swift:81:12:81:12 | v8 | conversions.swift:82:12:82:12 | v8 |
89+
| conversions.swift:81:28:81:28 | 1 | conversions.swift:81:12:81:29 | call to distance(to:) |
90+
| conversions.swift:82:12:82:12 | v8 | conversions.swift:82:12:82:51 | call to distance(to:) |
91+
| conversions.swift:82:28:82:50 | call to sourceUInt64(_:) | conversions.swift:82:12:82:51 | call to distance(to:) |
7292
| conversions.swift:84:12:84:45 | call to Self.init(exactly:) | conversions.swift:84:12:84:46 | ...! |
7393
| conversions.swift:85:12:85:48 | call to Self.init(exactly:) | conversions.swift:85:12:85:49 | ...! |
94+
| conversions.swift:86:26:86:45 | call to sourceInt(_:) | conversions.swift:86:12:86:46 | call to Self.init(clamping:) |
95+
| conversions.swift:87:29:87:48 | call to sourceInt(_:) | conversions.swift:87:12:87:49 | call to Self.init(clamping:) |
96+
| conversions.swift:88:36:88:55 | call to sourceInt(_:) | conversions.swift:88:12:88:56 | call to Self.init(truncatingIfNeeded:) |
97+
| conversions.swift:89:39:89:58 | call to sourceInt(_:) | conversions.swift:89:12:89:59 | call to Self.init(truncatingIfNeeded:) |
7498
| conversions.swift:90:12:90:50 | call to Self.init(_:radix:) | conversions.swift:90:12:90:51 | ...! |
7599
| conversions.swift:91:12:91:53 | call to Self.init(_:radix:) | conversions.swift:91:12:91:54 | ...! |
76100
| conversions.swift:93:30:93:49 | call to sourceInt(_:) | conversions.swift:93:12:93:50 | call to Self.init(littleEndian:) |
@@ -122,6 +146,7 @@
122146
| conversions.swift:131:12:131:12 | [post] pair4 | conversions.swift:132:12:132:12 | pair4 |
123147
| conversions.swift:131:12:131:12 | pair4 | conversions.swift:132:12:132:12 | pair4 |
124148
| conversions.swift:137:18:137:39 | call to sourceFloat(_:) | conversions.swift:137:12:137:40 | call to Float.init(_:) |
149+
| conversions.swift:138:18:138:39 | call to sourceFloat(_:) | conversions.swift:138:12:138:40 | call to UInt8.init(_:) |
125150
| conversions.swift:139:19:139:40 | call to sourceFloat(_:) | conversions.swift:139:12:139:41 | call to String.init(_:) |
126151
| conversions.swift:140:12:140:41 | call to String.init(_:) | conversions.swift:140:12:140:43 | .utf8 |
127152
| conversions.swift:140:19:140:40 | call to sourceFloat(_:) | conversions.swift:140:12:140:41 | call to String.init(_:) |
@@ -144,6 +169,10 @@
144169
| conversions.swift:155:12:155:35 | call to sourceFloat80(_:) | conversions.swift:155:12:155:37 | .significand |
145170
| conversions.swift:156:12:156:34 | call to sourceDouble(_:) | conversions.swift:156:12:156:36 | .exponent |
146171
| conversions.swift:157:12:157:34 | call to sourceDouble(_:) | conversions.swift:157:12:157:36 | .significand |
172+
| conversions.swift:158:12:158:32 | call to sourceUInt(_:) | conversions.swift:158:12:158:34 | .byteSwapped |
173+
| conversions.swift:159:12:159:34 | call to sourceUInt64(_:) | conversions.swift:159:12:159:36 | .byteSwapped |
174+
| conversions.swift:160:12:160:31 | call to sourceInt(_:) | conversions.swift:160:12:160:33 | .magnitude |
175+
| conversions.swift:161:12:161:35 | call to sourceUInt64(_:) | conversions.swift:161:12:161:37 | .magnitude |
147176
| conversions.swift:166:19:166:42 | call to sourceString(_:) | conversions.swift:166:12:166:43 | call to String.init(_:) |
148177
| conversions.swift:168:6:168:6 | SSA def(ms1) | conversions.swift:169:12:169:12 | ms1 |
149178
| conversions.swift:168:6:168:6 | ms1 | conversions.swift:168:6:168:6 | SSA def(ms1) |
@@ -186,6 +215,8 @@
186215
| conversions.swift:186:40:186:40 | parent | conversions.swift:186:25:186:69 | call to unsafeDowncast(_:to:) |
187216
| conversions.swift:187:12:187:12 | [post] v3 | conversions.swift:188:12:188:12 | v3 |
188217
| conversions.swift:187:12:187:12 | v3 | conversions.swift:188:12:188:12 | v3 |
218+
| conversions.swift:195:24:195:24 | myCEnumConst | conversions.swift:195:12:195:36 | call to Self.init(_:) |
219+
| conversions.swift:196:24:196:41 | call to sourceInt(_:) | conversions.swift:196:12:196:42 | call to Self.init(_:) |
189220
| conversions.swift:199:7:199:7 | SSA def(self) | conversions.swift:199:7:199:7 | self[return] |
190221
| conversions.swift:199:7:199:7 | self | conversions.swift:199:7:199:7 | SSA def(self) |
191222
| conversions.swift:200:2:200:2 | SSA def(self) | conversions.swift:200:2:221:2 | self[return] |
@@ -248,6 +279,7 @@
248279
| conversions.swift:236:13:236:13 | withUInt | conversions.swift:237:14:237:14 | withUInt |
249280
| conversions.swift:237:3:237:22 | SSA def(self) | conversions.swift:238:12:238:12 | self |
250281
| conversions.swift:237:10:237:22 | call to Self.init(_:) | conversions.swift:237:3:237:22 | SSA def(self) |
282+
| conversions.swift:237:14:237:14 | withUInt | conversions.swift:237:10:237:22 | call to Self.init(_:) |
251283
| conversions.swift:238:12:238:12 | [post] self | conversions.swift:235:2:239:2 | self[return] |
252284
| conversions.swift:238:12:238:12 | self | conversions.swift:235:2:239:2 | self[return] |
253285
| conversions.swift:241:7:241:20 | SSA def(withMyValue) | conversions.swift:242:13:242:13 | withMyValue |

0 commit comments

Comments
 (0)