@@ -7,47 +7,63 @@ import swift
77import codeql.swift.dataflow.DataFlow
88import codeql.swift.dataflow.ExternalFlow
99
10+ private newtype TStringType =
11+ TString ( ) or
12+ TNsString ( ) or
13+ TStringUtf8 ( ) or
14+ TStringUtf16 ( ) or
15+ TStringUnicodeScalars ( )
16+
1017/**
1118 * A type of Swift string encoding. This class is used as a flow state for
1219 * the string length conflation taint tracking configuration.
1320 */
14- class StringType extends string {
21+ class StringType extends TStringType {
22+ string name ;
1523 string singular ;
16- string equivClass ;
24+ TStringType equivClass ;
1725 string csvLabel ;
1826
1927 StringType ( ) {
20- this = "String" and
28+ this = TString ( ) and
29+ name = "String" and
2130 singular = "a String" and
22- equivClass = "String" and
31+ equivClass = this and
2332 csvLabel = "string-length"
2433 or
25- this = "NSString" and
34+ this = TNsString ( ) and
35+ name = "NSString" and
2636 singular = "an NSString" and
27- equivClass = "NSString" and
37+ equivClass = this and
2838 csvLabel = "nsstring-length"
2939 or
30- this = "String.utf8" and
40+ this = TStringUtf8 ( ) and
41+ name = "String.utf8" and
3142 singular = "a String.utf8" and
32- equivClass = "String.utf8" and
43+ equivClass = this and
3344 csvLabel = "string-utf8-length"
3445 or
35- this = "String.utf16" and
46+ this = TStringUtf16 ( ) and
47+ name = "String.utf16" and
3648 singular = "a String.utf16" and
37- equivClass = "NSString" and
49+ equivClass = TNsString ( ) and
3850 csvLabel = "string-utf16-length"
3951 or
40- this = "String.unicodeScalars" and
52+ this = TStringUnicodeScalars ( ) and
53+ name = "String.unicodeScalars" and
4154 singular = "a String.unicodeScalars" and
42- equivClass = "String.unicodeScalars" and
55+ equivClass = this and
4356 csvLabel = "string-unicodescalars-length"
4457 }
4558
59+ /** Gets a textual representation of this string type. */
60+ string toString ( ) { result = name }
61+
4662 /**
4763 * Gets the equivalence class for this string type. If these are equal,
4864 * they should be treated as equivalent.
4965 */
50- string getEquivClass ( ) { result = equivClass }
66+ StringType getEquivClass ( ) { result = equivClass }
5167
5268 /**
5369 * Gets text for the singular form of this string type.
@@ -130,15 +146,15 @@ private class ExtraStringLengthConflationSource extends StringLengthConflationSo
130146 (
131147 // result of a call to `String.utf8.count`
132148 typeName = "String.UTF8View" and
133- stringType = "String.utf8"
149+ stringType = TStringUtf8 ( )
134150 or
135151 // result of a call to `String.utf16.count`
136152 typeName = "String.UTF16View" and
137- stringType = "String.utf16"
153+ stringType = TStringUtf16 ( )
138154 or
139155 // result of a call to `String.unicodeScalars.count`
140156 typeName = "String.UnicodeScalarView" and
141- stringType = "String.unicodeScalars"
157+ stringType = TStringUnicodeScalars ( )
142158 ) and
143159 memberRef .getBase ( ) .getType ( ) .( NominalType ) .getName ( ) = typeName and
144160 memberRef .getMember ( ) .( VarDecl ) .getName ( ) = "count" and
0 commit comments