From 1d1bda93b895a296c778ca01e5538f53a5eab734 Mon Sep 17 00:00:00 2001 From: Valentin Obst Date: Thu, 13 Jun 2024 14:39:11 +0200 Subject: [PATCH] lib: explicitly opt-in to overflowing arithmetic 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 --- src/cwe_checker_lib/src/abstract_domain/interval.rs | 5 ++++- .../src/analysis/pointer_inference/state/mod.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cwe_checker_lib/src/abstract_domain/interval.rs b/src/cwe_checker_lib/src/abstract_domain/interval.rs index bd811aa70..18f3ecc66 100644 --- a/src/cwe_checker_lib/src/abstract_domain/interval.rs +++ b/src/cwe_checker_lib/src/abstract_domain/interval.rs @@ -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, } } diff --git a/src/cwe_checker_lib/src/analysis/pointer_inference/state/mod.rs b/src/cwe_checker_lib/src/analysis/pointer_inference/state/mod.rs index d91b6f13e..8b170b310 100644 --- a/src/cwe_checker_lib/src/analysis/pointer_inference/state/mod.rs +++ b/src/cwe_checker_lib/src/analysis/pointer_inference/state/mod.rs @@ -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(), ),