Skip to content

Commit 8bcc5f4

Browse files
authored
Merge pull request github#17989 from geoffw0/swift6models2
Swift: More model repairs for Swift 6
2 parents 51f7129 + fa43207 commit 8bcc5f4

File tree

15 files changed

+971
-752
lines changed

15 files changed

+971
-752
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ private class CollectionSummaries extends SummaryModelCsv {
3232
";Collection;true;dropLast(_:);;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value",
3333
";Collection;true;flatMap(_:);;;Argument[-1];ReturnValue;taint",
3434
";Collection;true;flatMap(_:);;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value",
35-
";Collection;true;map(_:);;;Argument[-1];ReturnValue;taint",
36-
";Collection;true;map(_:);;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value",
35+
//";Collection;true;map(_:);;;Argument[-1];ReturnValue;taint", --- disabled due to dubious results in practice
36+
//";Collection;true;map(_:);;;Argument[-1].CollectionElement;ReturnValue.CollectionElement;value", --- disabled due to dubious results in practice
3737
";Collection;true;split(maxSplits:omittingEmptySubsequences:whereSeparator:);;;Argument[-1];ReturnValue;taint",
3838
";Collection;true;split(separator:maxSplits:omittingEmptySubsequences:);;;Argument[-1];ReturnValue;taint",
3939
";Collection;true;removeFirst();;;Argument[-1];ReturnValue;taint",

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/lib/codeql/swift/security/CommandInjectionExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private class CommandInjectionSinks extends SinkModelCsv {
6363
private class CommandInjectionDefaultBarrier extends CommandInjectionBarrier {
6464
CommandInjectionDefaultBarrier() {
6565
// any numeric type
66-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
66+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
67+
["Numeric", "SignedInteger", "UnsignedInteger"]
6768
}
6869
}

swift/ql/lib/codeql/swift/security/PredicateInjectionExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private class PredicateInjectionSinkCsv extends SinkModelCsv {
4646
private class PredicateInjectionDefaultBarrier extends PredicateInjectionBarrier {
4747
PredicateInjectionDefaultBarrier() {
4848
// any numeric type
49-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
49+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
50+
["Numeric", "SignedInteger", "UnsignedInteger"]
5051
}
5152
}

swift/ql/lib/codeql/swift/security/SqlInjectionExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ private class DefaultSqlInjectionSink extends SqlInjectionSink {
190190
private class SqlInjectionDefaultBarrier extends SqlInjectionBarrier {
191191
SqlInjectionDefaultBarrier() {
192192
// any numeric type
193-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
193+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
194+
["Numeric", "SignedInteger", "UnsignedInteger"]
194195
}
195196
}

swift/ql/lib/codeql/swift/security/UncontrolledFormatStringExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class HeuristicUncontrolledFormatStringSink extends UncontrolledFormatStringSink
9494
private class UncontrolledFormatStringDefaultBarrier extends UncontrolledFormatStringBarrier {
9595
UncontrolledFormatStringDefaultBarrier() {
9696
// any numeric type
97-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
97+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
98+
["Numeric", "SignedInteger", "UnsignedInteger"]
9899
}
99100
}

swift/ql/lib/codeql/swift/security/UnsafeJsEvalExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private class DefaultUnsafeJsEvalSink extends UnsafeJsEvalSink {
127127
private class UnsafeJsEvalDefaultBarrier extends UnsafeJsEvalBarrier {
128128
UnsafeJsEvalDefaultBarrier() {
129129
// any numeric type
130-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
130+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
131+
["Numeric", "SignedInteger", "UnsignedInteger"]
131132
}
132133
}

swift/ql/lib/codeql/swift/security/UnsafeUnpackExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private class UnsafeUnpackAdditionalDataFlowStep extends UnsafeUnpackAdditionalF
7373
private class UnsafeUnpackDefaultBarrier extends UnsafeUnpackBarrier {
7474
UnsafeUnpackDefaultBarrier() {
7575
// any numeric type
76-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
76+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
77+
["Numeric", "SignedInteger", "UnsignedInteger"]
7778
}
7879
}

swift/ql/lib/codeql/swift/security/regex/RegexInjectionExtensions.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private class RegexInjectionSinks extends SinkModelCsv {
6464
private class RegexInjectionDefaultBarrier extends RegexInjectionBarrier {
6565
RegexInjectionDefaultBarrier() {
6666
// any numeric type
67-
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() = "Numeric"
67+
this.asExpr().getType().getUnderlyingType().getABaseType*().getName() =
68+
["Numeric", "SignedInteger", "UnsignedInteger"]
6869
}
6970
}

0 commit comments

Comments
 (0)