Skip to content

Commit e0b61b2

Browse files
committed
Reduce the number of UpperBoundChecks
No need to have a separate class for each state being blocked.
1 parent c0b579c commit e0b61b2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,28 +227,28 @@ abstract class BarrierFlowStateTransformer extends DataFlow::Node {
227227
}
228228

229229
class UpperBoundCheck extends BarrierFlowStateTransformer {
230-
MaxValueState state1;
231230
UpperBoundCheckGuard g;
232231

233232
UpperBoundCheck() {
234-
this = DataFlow::BarrierGuard<upperBoundCheckGuard/3>::getABarrierNodeForGuard(g) and
235-
g.isBoundFor2(state1.getBitSize(), state1.getSinkBitSize())
233+
this = DataFlow::BarrierGuard<upperBoundCheckGuard/3>::getABarrierNodeForGuard(g)
236234
}
237235

238-
override predicate barrierFor(MaxValueState flowstate) { flowstate = state1 }
236+
override predicate barrierFor(MaxValueState flowstate) {
237+
g.isBoundFor2(flowstate.getBitSize(), flowstate.getSinkBitSize())
238+
}
239239

240240
override MaxValueState transform(MaxValueState state) {
241-
state = state1 and
241+
this.barrierFor(state) and
242242
result.getBitSize() =
243243
max(int bitsize |
244244
bitsize = validBitSize() and
245-
bitsize < state1.getBitSize() and
245+
bitsize < state.getBitSize() and
246246
not g.isBoundFor2(bitsize, state.getSinkBitSize())
247247
|
248248
bitsize
249249
) and
250-
if exists(state1.getArchitectureBitSize())
251-
then result.getArchitectureBitSize() = state1.getArchitectureBitSize()
250+
if exists(state.getArchitectureBitSize())
251+
then result.getArchitectureBitSize() = state.getArchitectureBitSize()
252252
else not exists(result.getArchitectureBitSize())
253253
}
254254
}

0 commit comments

Comments
 (0)