Skip to content

Commit e45e92e

Browse files
committed
Fix MaxIntOrMaxUint.isBoundFor
It was wrong for strictnessOffset = 1 before.
1 parent 36c4f5d commit e45e92e

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

go/ql/lib/semmle/go/security/IncorrectIntegerConversionLib.qll

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ abstract private class MaxIntOrMaxUint extends DeclaredConstant {
1515
*/
1616
predicate isBoundFor(int b, int architectureBitSize, float strictnessOffset) {
1717
// 2.pow(x) - 1 - strictnessOffset <= 2.pow(b) - 1
18-
exists(int x |
19-
x = this.getOrder(architectureBitSize) and
20-
b = validBitSize() and
21-
(
22-
strictnessOffset = 0 and x <= b
23-
or
24-
strictnessOffset = 1 and x <= b - 1
25-
)
26-
)
18+
// For the values that we are restricting `b` to, `strictnessOffset` has no
19+
// effect on the result, so we can ignore it.
20+
b = validBitSize() and
21+
strictnessOffset = [0, 1] and
22+
this.getOrder(architectureBitSize) <= b
2723
}
2824
}
2925

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
testFailures
2-
| IncorrectIntegerConversion.go:497:15:497:15 | i | Unexpected result: hasValueFlow="i" |
32
failures

0 commit comments

Comments
 (0)