@@ -141,7 +141,7 @@ deprecated class ConversionWithoutBoundsCheckConfig extends TaintTracking::Confi
141
141
if sinkBitSize != 0 then bitSize = sinkBitSize else bitSize = 32
142
142
|
143
143
node = DataFlow:: BarrierGuard< upperBoundCheckGuard / 3 > :: getABarrierNodeForGuard ( g ) and
144
- g .isBoundFor ( bitSize , sinkIsSigned )
144
+ if sinkIsSigned = true then g .isBoundFor ( bitSize , 32 ) else g . isBoundFor ( bitSize - 1 , 32 )
145
145
)
146
146
or
147
147
exists ( int bitSize |
@@ -245,39 +245,6 @@ class UpperBoundCheckGuard extends DataFlow::RelationalComparisonNode {
245
245
expr .getAnOperand ( ) .getType ( ) .getUnderlyingType ( ) instanceof IntegerType
246
246
}
247
247
248
- /**
249
- * Holds if the upper bound check ensures the non-constant operand is less
250
- * than or equal to the maximum value for `bitSize` and `isSigned`. In this
251
- * case, the upper bound check is a barrier guard.
252
- *
253
- * Note that we have to use floats here because integers in CodeQL are
254
- * represented by 32-bit signed integers, which cannot represent some of the
255
- * integer values which we will encounter.
256
- */
257
- deprecated predicate isBoundFor ( int bitSize , boolean isSigned ) {
258
- bitSize = [ 8 , 16 , 32 ] and
259
- exists ( float bound , float strictnessOffset |
260
- // For `x < c` the bound is `c-1`. For `x >= c` we will be an upper bound
261
- // on the `branch` argument of `checks` is false, which is equivalent to
262
- // `x < c`.
263
- if expr instanceof LssExpr or expr instanceof GeqExpr
264
- then strictnessOffset = 1
265
- else strictnessOffset = 0
266
- |
267
- exists ( DeclaredConstant maxint , DeclaredConstant maxuint |
268
- maxint .hasQualifiedName ( "math" , "MaxInt" ) and maxuint .hasQualifiedName ( "math" , "MaxUint" )
269
- |
270
- if expr .getAnOperand ( ) = maxint .getAReference ( )
271
- then bound = getMaxIntValue ( 32 , true )
272
- else
273
- if expr .getAnOperand ( ) = maxuint .getAReference ( )
274
- then bound = getMaxIntValue ( 32 , false )
275
- else bound = expr .getAnOperand ( ) .getExactValue ( ) .toFloat ( )
276
- ) and
277
- bound - strictnessOffset <= getMaxIntValue ( bitSize , isSigned )
278
- )
279
- }
280
-
281
248
/**
282
249
* Holds if this upper bound check ensures the non-constant operand is less
283
250
* than or equal to `2^(bitsize) - 1`. In this case, the upper bound check
@@ -288,7 +255,7 @@ class UpperBoundCheckGuard extends DataFlow::RelationalComparisonNode {
288
255
* represented by 32-bit signed integers, which cannot represent some of the
289
256
* integer values which we will encounter.
290
257
*/
291
- predicate isBoundFor2 ( int bitSize , int architectureBitSize ) {
258
+ predicate isBoundFor ( int bitSize , int architectureBitSize ) {
292
259
bitSize = validBitSize ( ) and
293
260
architectureBitSize = [ 32 , 64 ] and
294
261
exists ( float bound , float strictnessOffset |
@@ -359,7 +326,7 @@ class UpperBoundCheck extends BarrierFlowStateTransformer {
359
326
override predicate barrierFor ( MaxValueState flowstate ) {
360
327
// Use a default value of 32 for `MaxValueState.getSinkBitSize` because
361
328
// this will find results that only exist on 32-bit architectures.
362
- g .isBoundFor2 ( flowstate .getBitSize ( ) , flowstate .getSinkBitSize ( 32 ) )
329
+ g .isBoundFor ( flowstate .getBitSize ( ) , flowstate .getSinkBitSize ( 32 ) )
363
330
}
364
331
365
332
override MaxValueState transform ( MaxValueState state ) {
@@ -370,7 +337,7 @@ class UpperBoundCheck extends BarrierFlowStateTransformer {
370
337
bitsize < state .getBitSize ( ) and
371
338
// Use a default value of 32 for `MaxValueState.getSinkBitSize` because
372
339
// this will find results that only exist on 32-bit architectures.
373
- not g .isBoundFor2 ( bitsize , state .getSinkBitSize ( 32 ) )
340
+ not g .isBoundFor ( bitsize , state .getSinkBitSize ( 32 ) )
374
341
) and
375
342
if exists ( state .getArchitectureBitSize ( ) )
376
343
then result .getArchitectureBitSize ( ) = state .getArchitectureBitSize ( )
0 commit comments