@@ -7,47 +7,63 @@ import swift
7
7
import codeql.swift.dataflow.DataFlow
8
8
import codeql.swift.dataflow.ExternalFlow
9
9
10
+ private newtype TStringType =
11
+ TString ( ) or
12
+ TNsString ( ) or
13
+ TStringUtf8 ( ) or
14
+ TStringUtf16 ( ) or
15
+ TStringUnicodeScalars ( )
16
+
10
17
/**
11
18
* A type of Swift string encoding. This class is used as a flow state for
12
19
* the string length conflation taint tracking configuration.
13
20
*/
14
- class StringType extends string {
21
+ class StringType extends TStringType {
22
+ string name ;
15
23
string singular ;
16
- string equivClass ;
24
+ TStringType equivClass ;
17
25
string csvLabel ;
18
26
19
27
StringType ( ) {
20
- this = "String" and
28
+ this = TString ( ) and
29
+ name = "String" and
21
30
singular = "a String" and
22
- equivClass = "String" and
31
+ equivClass = this and
23
32
csvLabel = "string-length"
24
33
or
25
- this = "NSString" and
34
+ this = TNsString ( ) and
35
+ name = "NSString" and
26
36
singular = "an NSString" and
27
- equivClass = "NSString" and
37
+ equivClass = this and
28
38
csvLabel = "nsstring-length"
29
39
or
30
- this = "String.utf8" and
40
+ this = TStringUtf8 ( ) and
41
+ name = "String.utf8" and
31
42
singular = "a String.utf8" and
32
- equivClass = "String.utf8" and
43
+ equivClass = this and
33
44
csvLabel = "string-utf8-length"
34
45
or
35
- this = "String.utf16" and
46
+ this = TStringUtf16 ( ) and
47
+ name = "String.utf16" and
36
48
singular = "a String.utf16" and
37
- equivClass = "NSString" and
49
+ equivClass = TNsString ( ) and
38
50
csvLabel = "string-utf16-length"
39
51
or
40
- this = "String.unicodeScalars" and
52
+ this = TStringUnicodeScalars ( ) and
53
+ name = "String.unicodeScalars" and
41
54
singular = "a String.unicodeScalars" and
42
- equivClass = "String.unicodeScalars" and
55
+ equivClass = this and
43
56
csvLabel = "string-unicodescalars-length"
44
57
}
45
58
59
+ /** Gets a textual representation of this string type. */
60
+ string toString ( ) { result = name }
61
+
46
62
/**
47
63
* Gets the equivalence class for this string type. If these are equal,
48
64
* they should be treated as equivalent.
49
65
*/
50
- string getEquivClass ( ) { result = equivClass }
66
+ StringType getEquivClass ( ) { result = equivClass }
51
67
52
68
/**
53
69
* Gets text for the singular form of this string type.
@@ -130,15 +146,15 @@ private class ExtraStringLengthConflationSource extends StringLengthConflationSo
130
146
(
131
147
// result of a call to `String.utf8.count`
132
148
typeName = "String.UTF8View" and
133
- stringType = "String.utf8"
149
+ stringType = TStringUtf8 ( )
134
150
or
135
151
// result of a call to `String.utf16.count`
136
152
typeName = "String.UTF16View" and
137
- stringType = "String.utf16"
153
+ stringType = TStringUtf16 ( )
138
154
or
139
155
// result of a call to `String.unicodeScalars.count`
140
156
typeName = "String.UnicodeScalarView" and
141
- stringType = "String.unicodeScalars"
157
+ stringType = TStringUnicodeScalars ( )
142
158
) and
143
159
memberRef .getBase ( ) .getType ( ) .( NominalType ) .getName ( ) = typeName and
144
160
memberRef .getMember ( ) .( VarDecl ) .getName ( ) = "count" and
0 commit comments