Skip to content

Commit

Permalink
intptrcast: only find strictly in-bounds pointers when we are not hit…
Browse files Browse the repository at this point in the history
…ting the base address
  • Loading branch information
RalfJung committed Oct 15, 2023
1 parent 7f0d71f commit 1cbb8fa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/intptrcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ impl<'mir, 'tcx> GlobalStateInner {
let (glb, alloc_id) = global_state.int_to_ptr_map[pos - 1];
// This never overflows because `addr >= glb`
let offset = addr - glb;
// If the offset exceeds the size of the allocation, don't use this `alloc_id`.
// We require this to be strict in-bounds of the allocation. This arm is only
// entered for addresses that are not the base address, so even zero-sized
// allocations will get recognized at their base address -- but all other
// allocations will *not* be recognized at their "end" address.
let size = ecx.get_alloc_info(alloc_id).0;
if offset <= size.bytes() { Some(alloc_id) } else { None }
if offset < size.bytes() { Some(alloc_id) } else { None }
}
}?;

Expand Down

0 comments on commit 1cbb8fa

Please sign in to comment.