@@ -68,22 +68,26 @@ abstract class BufferWrite extends Expr {
68
68
/**
69
69
* Gets an upper bound to the amount of data that's being written (if one
70
70
* can be found).
71
+ * DEPRECATED: getMaxData\1 should be used and overridden instead
71
72
*/
72
- int getMaxData ( ) { result = max ( getMaxData ( _ ) ) }
73
+ deprecated int getMaxData ( ) { none ( ) }
73
74
74
75
/**
75
76
* Gets an upper bound to the amount of data that's being written (if one
76
- * can be found), except that float to string conversions are assumed to be
77
- * much smaller (8 bytes) than their true maximum length. This can be
78
- * helpful in determining the cause of a buffer overflow issue.
77
+ * can be found), specifying the reason for the estimation
79
78
*/
80
- int getMaxDataLimited ( ) { result = max ( getMaxDataLimited ( _) ) }
79
+ int getMaxData ( BufferWriteEstimationReason reason ) {
80
+ reason instanceof NoSpecifiedEstimateReason and result = getMaxData ( )
81
+ }
81
82
82
83
/**
83
84
* Gets an upper bound to the amount of data that's being written (if one
84
- * can be found), specifying the reason for the estimation
85
+ * can be found), except that float to string conversions are assumed to be
86
+ * much smaller (8 bytes) than their true maximum length. This can be
87
+ * helpful in determining the cause of a buffer overflow issue.
88
+ * DEPRECATED: getMaxDataLimited\1 should be used and overridden instead
85
89
*/
86
- int getMaxData ( BufferWriteEstimationReason reason ) { none ( ) }
90
+ deprecated int getMaxDataLimited ( ) { result = getMaxData ( ) }
87
91
88
92
/**
89
93
* Gets an upper bound to the amount of data that's being written (if one
@@ -92,7 +96,9 @@ abstract class BufferWrite extends Expr {
92
96
* than their true maximum length. This can be helpful in determining the
93
97
* cause of a buffer overflow issue.
94
98
*/
95
- int getMaxDataLimited ( BufferWriteEstimationReason reason ) { result = getMaxData ( reason ) }
99
+ int getMaxDataLimited ( BufferWriteEstimationReason reason ) {
100
+ result = getMaxData ( reason )
101
+ }
96
102
97
103
/**
98
104
* Gets the size of a single character of the type this
@@ -150,12 +156,16 @@ class StrCopyBW extends BufferWriteCall {
150
156
result = this .getArgument ( this .getParamSize ( ) ) .getValue ( ) .toInt ( ) * this .getCharSize ( )
151
157
}
152
158
153
- override int getMaxData ( BufferWriteEstimationReason reason ) {
159
+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
154
160
// when result exists, it is an exact flow analysis
155
161
reason instanceof ValueFlowAnalysis and
156
162
result =
157
163
this .getArgument ( this .getParamSrc ( ) ) .( AnalysedString ) .getMaxLength ( ) * this .getCharSize ( )
158
164
}
165
+
166
+ override int getMaxData ( BufferWriteEstimationReason reason ) { result = getMaxDataImpl ( reason ) }
167
+
168
+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
159
169
}
160
170
161
171
/**
@@ -190,12 +200,20 @@ class StrCatBW extends BufferWriteCall {
190
200
result = this .getArgument ( this .getParamSize ( ) ) .getValue ( ) .toInt ( ) * this .getCharSize ( )
191
201
}
192
202
193
- override int getMaxData ( BufferWriteEstimationReason reason ) {
203
+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
194
204
// when result exists, it is an exact flow analysis
195
205
reason instanceof ValueFlowAnalysis and
196
206
result =
197
207
this .getArgument ( this .getParamSrc ( ) ) .( AnalysedString ) .getMaxLength ( ) * this .getCharSize ( )
198
208
}
209
+
210
+ override int getMaxData ( BufferWriteEstimationReason reason ) {
211
+ result = getMaxDataImpl ( reason )
212
+ }
213
+
214
+ deprecated override int getMaxData ( ) {
215
+ result = max ( getMaxDataImpl ( _) )
216
+ }
199
217
}
200
218
201
219
/**
@@ -252,19 +270,27 @@ class SprintfBW extends BufferWriteCall {
252
270
253
271
override Expr getDest ( ) { result = this .getArgument ( f .getOutputParameterIndex ( false ) ) }
254
272
255
- override int getMaxData ( BufferWriteEstimationReason reason ) {
273
+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
256
274
exists ( FormatLiteral fl |
257
275
fl = this .( FormattingFunctionCall ) .getFormat ( ) and
258
276
result = fl .getMaxConvertedLengthWithReason ( reason ) * this .getCharSize ( )
259
277
)
260
278
}
261
279
262
- override int getMaxDataLimited ( BufferWriteEstimationReason reason ) {
280
+ override int getMaxData ( BufferWriteEstimationReason reason ) { result = getMaxDataImpl ( reason ) }
281
+
282
+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
283
+
284
+ private int getMaxDataLimitedImpl ( BufferWriteEstimationReason reason ) {
263
285
exists ( FormatLiteral fl |
264
286
fl = this .( FormattingFunctionCall ) .getFormat ( ) and
265
287
result = fl .getMaxConvertedLengthLimitedWithReason ( reason ) * this .getCharSize ( )
266
288
)
267
289
}
290
+
291
+ override int getMaxDataLimited ( BufferWriteEstimationReason reason ) { result = getMaxDataLimitedImpl ( reason ) }
292
+
293
+ deprecated override int getMaxDataLimited ( ) { result = max ( getMaxDataLimitedImpl ( _) ) }
268
294
}
269
295
270
296
/**
@@ -355,19 +381,27 @@ class SnprintfBW extends BufferWriteCall {
355
381
result = this .getArgument ( this .getParamSize ( ) ) .getValue ( ) .toInt ( ) * this .getCharSize ( )
356
382
}
357
383
358
- override int getMaxData ( BufferWriteEstimationReason reason ) {
384
+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
359
385
exists ( FormatLiteral fl |
360
386
fl = this .( FormattingFunctionCall ) .getFormat ( ) and
361
387
result = fl .getMaxConvertedLengthWithReason ( reason ) * this .getCharSize ( )
362
388
)
363
389
}
364
390
365
- override int getMaxDataLimited ( BufferWriteEstimationReason reason ) {
391
+ override int getMaxData ( BufferWriteEstimationReason reason ) { result = getMaxDataImpl ( reason ) }
392
+
393
+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
394
+
395
+ private int getMaxDataLimitedImpl ( BufferWriteEstimationReason reason ) {
366
396
exists ( FormatLiteral fl |
367
397
fl = this .( FormattingFunctionCall ) .getFormat ( ) and
368
398
result = fl .getMaxConvertedLengthLimitedWithReason ( reason ) * this .getCharSize ( )
369
399
)
370
400
}
401
+
402
+ override int getMaxDataLimited ( BufferWriteEstimationReason reason ) { result = getMaxDataLimitedImpl ( reason ) }
403
+
404
+ deprecated override int getMaxDataLimited ( ) { result = max ( getMaxDataLimitedImpl ( _) ) }
371
405
}
372
406
373
407
/**
@@ -455,7 +489,7 @@ class ScanfBW extends BufferWrite {
455
489
456
490
override Expr getDest ( ) { result = this }
457
491
458
- override int getMaxData ( BufferWriteEstimationReason reason ) {
492
+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
459
493
// when this returns, it is based on exact flow analysis
460
494
reason instanceof ValueFlowAnalysis and
461
495
exists ( ScanfFunctionCall fc , ScanfFormatLiteral fl , int arg |
@@ -465,6 +499,12 @@ class ScanfBW extends BufferWrite {
465
499
)
466
500
}
467
501
502
+ override int getMaxData ( BufferWriteEstimationReason reason ) {
503
+ result = getMaxDataImpl ( reason )
504
+ }
505
+
506
+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
507
+
468
508
override string getBWDesc ( ) {
469
509
exists ( FunctionCall fc |
470
510
this = fc .getArgument ( _) and
@@ -495,10 +535,14 @@ class RealpathBW extends BufferWriteCall {
495
535
496
536
override Expr getASource ( ) { result = this .getArgument ( 0 ) }
497
537
498
- override int getMaxData ( BufferWriteEstimationReason reason ) {
538
+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
499
539
// although there may be some unknown invariants guaranteeing that a real path is shorter than PATH_MAX, we can consider providing less than PATH_MAX a problem with high precision
500
540
reason instanceof ValueFlowAnalysis and
501
541
result = path_max ( ) and
502
542
this = this // Suppress a compiler warning
503
543
}
544
+
545
+ override int getMaxData ( BufferWriteEstimationReason reason ) { result = getMaxDataImpl ( reason ) }
546
+
547
+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
504
548
}
0 commit comments