Skip to content

Commit

Permalink
lib: explicitly opt-in to overflowing arithmetic
Browse files Browse the repository at this point in the history
Replace integer arithmetic that might overflow with the appropriate
methods to explicitly opt-in to the behavior.

Since these methods have the same semantics as the bare operators (in
release builds) there should be no semantic changes here.

I did not investigate if the original code was aware that these
operations might overflow. In particual, it is not clear to me if the
right shift is expected to potentially overflow.

Signed-off-by: Valentin Obst <[email protected]>
  • Loading branch information
Valentin Obst committed Jun 14, 2024
1 parent b097b72 commit 1d1bda9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cwe_checker_lib/src/abstract_domain/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ impl IntervalDomain {
interval,
widening_lower_bound: lower_bound,
widening_upper_bound: upper_bound,
widening_delay: self.widening_delay >> low_byte.as_bit_length(),
widening_delay: self
.widening_delay
.overflowing_shr(low_byte.as_bit_length() as u32)
.0,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl State {
self.store_value(
&Data::from_target(
parent_id,
Bitvector::from_u64(address + offset as u64)
Bitvector::from_u64(address.wrapping_add(offset as u64))
.into_resize_signed(self.stack_id.bytesize())
.into(),
),
Expand Down

0 comments on commit 1d1bda9

Please sign in to comment.