@@ -16,21 +16,14 @@ private class StdBasicString extends ClassTemplateInstantiation {
16
16
}
17
17
18
18
/**
19
- * Additional model for `std::string` constructors that reference the character
20
- * type of the container, or an iterator. For example construction from
21
- * iterators:
22
- * ```
23
- * std::string b(a.begin(), a.end());
24
- * ```
19
+ * A `std::string` function for which taint should be propagated.
25
20
*/
26
- private class StdStringConstructor extends Constructor , TaintFunction {
27
- StdStringConstructor ( ) { this .getDeclaringType ( ) instanceof StdBasicString }
28
-
21
+ abstract private class StdStringTaintFunction extends TaintFunction {
29
22
/**
30
23
* Gets the index of a parameter to this function that is a string (or
31
24
* character).
32
25
*/
33
- int getAStringParameterIndex ( ) {
26
+ final int getAStringParameterIndex ( ) {
34
27
exists ( Type paramType | paramType = this .getParameter ( result ) .getUnspecifiedType ( ) |
35
28
// e.g. `std::basic_string::CharT *`
36
29
paramType instanceof PointerType
@@ -41,15 +34,28 @@ private class StdStringConstructor extends Constructor, TaintFunction {
41
34
this .getDeclaringType ( ) .getTemplateArgument ( 2 ) .( Type ) .getUnspecifiedType ( )
42
35
or
43
36
// i.e. `std::basic_string::CharT`
44
- this .getParameter ( result ) .getUnspecifiedType ( ) =
45
- this .getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( )
37
+ paramType = this .getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( )
46
38
)
47
39
}
48
40
49
41
/**
50
42
* Gets the index of a parameter to this function that is an iterator.
51
43
*/
52
- int getAnIteratorParameterIndex ( ) { this .getParameter ( result ) .getType ( ) instanceof Iterator }
44
+ final int getAnIteratorParameterIndex ( ) {
45
+ this .getParameter ( result ) .getType ( ) instanceof Iterator
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Additional model for `std::string` constructors that reference the character
51
+ * type of the container, or an iterator. For example construction from
52
+ * iterators:
53
+ * ```
54
+ * std::string b(a.begin(), a.end());
55
+ * ```
56
+ */
57
+ private class StdStringConstructor extends Constructor , StdStringTaintFunction {
58
+ StdStringConstructor ( ) { this .getDeclaringType ( ) instanceof StdBasicString }
53
59
54
60
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
55
61
// taint flow from any parameter of the value type to the returned object
@@ -68,7 +74,7 @@ private class StdStringConstructor extends Constructor, TaintFunction {
68
74
/**
69
75
* The `std::string` function `c_str`.
70
76
*/
71
- private class StdStringCStr extends TaintFunction {
77
+ private class StdStringCStr extends StdStringTaintFunction {
72
78
StdStringCStr ( ) { this .getClassAndName ( "c_str" ) instanceof StdBasicString }
73
79
74
80
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -81,7 +87,7 @@ private class StdStringCStr extends TaintFunction {
81
87
/**
82
88
* The `std::string` function `data`.
83
89
*/
84
- private class StdStringData extends TaintFunction {
90
+ private class StdStringData extends StdStringTaintFunction {
85
91
StdStringData ( ) { this .getClassAndName ( "data" ) instanceof StdBasicString }
86
92
87
93
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -99,7 +105,7 @@ private class StdStringData extends TaintFunction {
99
105
/**
100
106
* The `std::string` function `push_back`.
101
107
*/
102
- private class StdStringPush extends TaintFunction {
108
+ private class StdStringPush extends StdStringTaintFunction {
103
109
StdStringPush ( ) { this .getClassAndName ( "push_back" ) instanceof StdBasicString }
104
110
105
111
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -112,7 +118,7 @@ private class StdStringPush extends TaintFunction {
112
118
/**
113
119
* The `std::string` functions `front` and `back`.
114
120
*/
115
- private class StdStringFrontBack extends TaintFunction {
121
+ private class StdStringFrontBack extends StdStringTaintFunction {
116
122
StdStringFrontBack ( ) { this .getClassAndName ( [ "front" , "back" ] ) instanceof StdBasicString }
117
123
118
124
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -125,7 +131,7 @@ private class StdStringFrontBack extends TaintFunction {
125
131
/**
126
132
* The (non-member) `std::string` function `operator+`.
127
133
*/
128
- private class StdStringPlus extends TaintFunction {
134
+ private class StdStringPlus extends StdStringTaintFunction {
129
135
StdStringPlus ( ) {
130
136
this .hasQualifiedName ( [ "std" , "bsl" ] , "operator+" ) and
131
137
this .getUnspecifiedType ( ) instanceof StdBasicString
@@ -146,27 +152,11 @@ private class StdStringPlus extends TaintFunction {
146
152
* All of these functions combine the existing string with a new
147
153
* string (or character) from one of the arguments.
148
154
*/
149
- private class StdStringAppend extends TaintFunction {
155
+ private class StdStringAppend extends StdStringTaintFunction {
150
156
StdStringAppend ( ) {
151
157
this .getClassAndName ( [ "operator+=" , "append" , "replace" ] ) instanceof StdBasicString
152
158
}
153
159
154
- /**
155
- * Gets the index of a parameter to this function that is a string (or
156
- * character).
157
- */
158
- int getAStringParameterIndex ( ) {
159
- this .getParameter ( result ) .getType ( ) instanceof PointerType or // e.g. `std::basic_string::CharT *`
160
- this .getParameter ( result ) .getType ( ) instanceof ReferenceType or // e.g. `std::basic_string &`
161
- this .getParameter ( result ) .getUnspecifiedType ( ) =
162
- this .getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( ) // i.e. `std::basic_string::CharT`
163
- }
164
-
165
- /**
166
- * Gets the index of a parameter to this function that is an iterator.
167
- */
168
- int getAnIteratorParameterIndex ( ) { this .getParameter ( result ) .getType ( ) instanceof Iterator }
169
-
170
160
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
171
161
// flow from string and parameter to string (qualifier) and return value
172
162
(
@@ -189,26 +179,8 @@ private class StdStringAppend extends TaintFunction {
189
179
/**
190
180
* The `std::string` function `insert`.
191
181
*/
192
- private class StdStringInsert extends TaintFunction {
193
- StdStringInsert ( ) {
194
- this .getClassAndName ( "insert" ) instanceof StdBasicString
195
- }
196
-
197
- /**
198
- * Gets the index of a parameter to this function that is a string (or
199
- * character).
200
- */
201
- int getAStringParameterIndex ( ) {
202
- this .getParameter ( result ) .getType ( ) instanceof PointerType or // e.g. `std::basic_string::CharT *`
203
- this .getParameter ( result ) .getType ( ) instanceof ReferenceType or // e.g. `std::basic_string &`
204
- this .getParameter ( result ) .getUnspecifiedType ( ) =
205
- this .getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( ) // i.e. `std::basic_string::CharT`
206
- }
207
-
208
- /**
209
- * Gets the index of a parameter to this function that is an iterator.
210
- */
211
- int getAnIteratorParameterIndex ( ) { this .getParameter ( result ) .getType ( ) instanceof Iterator }
182
+ private class StdStringInsert extends StdStringTaintFunction {
183
+ StdStringInsert ( ) { this .getClassAndName ( "insert" ) instanceof StdBasicString }
212
184
213
185
/**
214
186
* Holds if the return type is an iterator.
@@ -239,25 +211,9 @@ private class StdStringInsert extends TaintFunction {
239
211
/**
240
212
* The standard function `std::string.assign`.
241
213
*/
242
- private class StdStringAssign extends TaintFunction {
214
+ private class StdStringAssign extends StdStringTaintFunction {
243
215
StdStringAssign ( ) { this .getClassAndName ( "assign" ) instanceof StdBasicString }
244
216
245
- /**
246
- * Gets the index of a parameter to this function that is a string (or
247
- * character).
248
- */
249
- int getAStringParameterIndex ( ) {
250
- this .getParameter ( result ) .getType ( ) instanceof PointerType or // e.g. `std::basic_string::CharT *`
251
- this .getParameter ( result ) .getType ( ) instanceof ReferenceType or // e.g. `std::basic_string &`
252
- this .getParameter ( result ) .getUnspecifiedType ( ) =
253
- this .getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( ) // i.e. `std::basic_string::CharT`
254
- }
255
-
256
- /**
257
- * Gets the index of a parameter to this function that is an iterator.
258
- */
259
- int getAnIteratorParameterIndex ( ) { this .getParameter ( result ) .getType ( ) instanceof Iterator }
260
-
261
217
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
262
218
// flow from parameter to string itself (qualifier) and return value
263
219
(
@@ -279,7 +235,7 @@ private class StdStringAssign extends TaintFunction {
279
235
/**
280
236
* The standard function `std::string.copy`.
281
237
*/
282
- private class StdStringCopy extends TaintFunction {
238
+ private class StdStringCopy extends StdStringTaintFunction {
283
239
StdStringCopy ( ) { this .getClassAndName ( "copy" ) instanceof StdBasicString }
284
240
285
241
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -292,7 +248,7 @@ private class StdStringCopy extends TaintFunction {
292
248
/**
293
249
* The standard function `std::string.substr`.
294
250
*/
295
- private class StdStringSubstr extends TaintFunction {
251
+ private class StdStringSubstr extends StdStringTaintFunction {
296
252
StdStringSubstr ( ) { this .getClassAndName ( "substr" ) instanceof StdBasicString }
297
253
298
254
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -305,7 +261,7 @@ private class StdStringSubstr extends TaintFunction {
305
261
/**
306
262
* The `std::string` functions `at` and `operator[]`.
307
263
*/
308
- private class StdStringAt extends TaintFunction {
264
+ private class StdStringAt extends StdStringTaintFunction {
309
265
StdStringAt ( ) { this .getClassAndName ( [ "at" , "operator[]" ] ) instanceof StdBasicString }
310
266
311
267
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
0 commit comments