@@ -68,22 +68,26 @@ abstract class BufferWrite extends Expr {
6868 /**
6969 * Gets an upper bound to the amount of data that's being written (if one
7070 * can be found).
71+ * DEPRECATED: getMaxData\1 should be used and overridden instead
7172 */
72- int getMaxData ( ) { result = max ( getMaxData ( _ ) ) }
73+ deprecated int getMaxData ( ) { none ( ) }
7374
7475 /**
7576 * 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
7978 */
80- int getMaxDataLimited ( ) { result = max ( getMaxDataLimited ( _) ) }
79+ int getMaxData ( BufferWriteEstimationReason reason ) {
80+ reason instanceof NoSpecifiedEstimateReason and result = getMaxData ( )
81+ }
8182
8283 /**
8384 * 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
8589 */
86- int getMaxData ( BufferWriteEstimationReason reason ) { none ( ) }
90+ deprecated int getMaxDataLimited ( ) { result = getMaxData ( ) }
8791
8892 /**
8993 * Gets an upper bound to the amount of data that's being written (if one
@@ -92,7 +96,9 @@ abstract class BufferWrite extends Expr {
9296 * than their true maximum length. This can be helpful in determining the
9397 * cause of a buffer overflow issue.
9498 */
95- int getMaxDataLimited ( BufferWriteEstimationReason reason ) { result = getMaxData ( reason ) }
99+ int getMaxDataLimited ( BufferWriteEstimationReason reason ) {
100+ result = getMaxData ( reason )
101+ }
96102
97103 /**
98104 * Gets the size of a single character of the type this
@@ -150,12 +156,16 @@ class StrCopyBW extends BufferWriteCall {
150156 result = this .getArgument ( this .getParamSize ( ) ) .getValue ( ) .toInt ( ) * this .getCharSize ( )
151157 }
152158
153- override int getMaxData ( BufferWriteEstimationReason reason ) {
159+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
154160 // when result exists, it is an exact flow analysis
155161 reason instanceof ValueFlowAnalysis and
156162 result =
157163 this .getArgument ( this .getParamSrc ( ) ) .( AnalysedString ) .getMaxLength ( ) * this .getCharSize ( )
158164 }
165+
166+ override int getMaxData ( BufferWriteEstimationReason reason ) { result = getMaxDataImpl ( reason ) }
167+
168+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
159169}
160170
161171/**
@@ -190,12 +200,20 @@ class StrCatBW extends BufferWriteCall {
190200 result = this .getArgument ( this .getParamSize ( ) ) .getValue ( ) .toInt ( ) * this .getCharSize ( )
191201 }
192202
193- override int getMaxData ( BufferWriteEstimationReason reason ) {
203+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
194204 // when result exists, it is an exact flow analysis
195205 reason instanceof ValueFlowAnalysis and
196206 result =
197207 this .getArgument ( this .getParamSrc ( ) ) .( AnalysedString ) .getMaxLength ( ) * this .getCharSize ( )
198208 }
209+
210+ override int getMaxData ( BufferWriteEstimationReason reason ) {
211+ result = getMaxDataImpl ( reason )
212+ }
213+
214+ deprecated override int getMaxData ( ) {
215+ result = max ( getMaxDataImpl ( _) )
216+ }
199217}
200218
201219/**
@@ -252,19 +270,27 @@ class SprintfBW extends BufferWriteCall {
252270
253271 override Expr getDest ( ) { result = this .getArgument ( f .getOutputParameterIndex ( false ) ) }
254272
255- override int getMaxData ( BufferWriteEstimationReason reason ) {
273+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
256274 exists ( FormatLiteral fl |
257275 fl = this .( FormattingFunctionCall ) .getFormat ( ) and
258276 result = fl .getMaxConvertedLengthWithReason ( reason ) * this .getCharSize ( )
259277 )
260278 }
261279
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 ) {
263285 exists ( FormatLiteral fl |
264286 fl = this .( FormattingFunctionCall ) .getFormat ( ) and
265287 result = fl .getMaxConvertedLengthLimitedWithReason ( reason ) * this .getCharSize ( )
266288 )
267289 }
290+
291+ override int getMaxDataLimited ( BufferWriteEstimationReason reason ) { result = getMaxDataLimitedImpl ( reason ) }
292+
293+ deprecated override int getMaxDataLimited ( ) { result = max ( getMaxDataLimitedImpl ( _) ) }
268294}
269295
270296/**
@@ -355,19 +381,27 @@ class SnprintfBW extends BufferWriteCall {
355381 result = this .getArgument ( this .getParamSize ( ) ) .getValue ( ) .toInt ( ) * this .getCharSize ( )
356382 }
357383
358- override int getMaxData ( BufferWriteEstimationReason reason ) {
384+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
359385 exists ( FormatLiteral fl |
360386 fl = this .( FormattingFunctionCall ) .getFormat ( ) and
361387 result = fl .getMaxConvertedLengthWithReason ( reason ) * this .getCharSize ( )
362388 )
363389 }
364390
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 ) {
366396 exists ( FormatLiteral fl |
367397 fl = this .( FormattingFunctionCall ) .getFormat ( ) and
368398 result = fl .getMaxConvertedLengthLimitedWithReason ( reason ) * this .getCharSize ( )
369399 )
370400 }
401+
402+ override int getMaxDataLimited ( BufferWriteEstimationReason reason ) { result = getMaxDataLimitedImpl ( reason ) }
403+
404+ deprecated override int getMaxDataLimited ( ) { result = max ( getMaxDataLimitedImpl ( _) ) }
371405}
372406
373407/**
@@ -455,7 +489,7 @@ class ScanfBW extends BufferWrite {
455489
456490 override Expr getDest ( ) { result = this }
457491
458- override int getMaxData ( BufferWriteEstimationReason reason ) {
492+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
459493 // when this returns, it is based on exact flow analysis
460494 reason instanceof ValueFlowAnalysis and
461495 exists ( ScanfFunctionCall fc , ScanfFormatLiteral fl , int arg |
@@ -465,6 +499,12 @@ class ScanfBW extends BufferWrite {
465499 )
466500 }
467501
502+ override int getMaxData ( BufferWriteEstimationReason reason ) {
503+ result = getMaxDataImpl ( reason )
504+ }
505+
506+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
507+
468508 override string getBWDesc ( ) {
469509 exists ( FunctionCall fc |
470510 this = fc .getArgument ( _) and
@@ -495,10 +535,14 @@ class RealpathBW extends BufferWriteCall {
495535
496536 override Expr getASource ( ) { result = this .getArgument ( 0 ) }
497537
498- override int getMaxData ( BufferWriteEstimationReason reason ) {
538+ private int getMaxDataImpl ( BufferWriteEstimationReason reason ) {
499539 // 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
500540 reason instanceof ValueFlowAnalysis and
501541 result = path_max ( ) and
502542 this = this // Suppress a compiler warning
503543 }
544+
545+ override int getMaxData ( BufferWriteEstimationReason reason ) { result = getMaxDataImpl ( reason ) }
546+
547+ deprecated override int getMaxData ( ) { result = max ( getMaxDataImpl ( _) ) }
504548}
0 commit comments