bytecodealliance / wasm-micro-runtime

WebAssembly Micro Runtime (WAMR)
Apache License 2.0
4.98k stars 628 forks source link

Fix out of bounds issue in is_native_addr_in_shared_heap function #3886

Closed lum1n0us closed 3 weeks ago

lum1n0us commented 3 weeks ago

When checking for integer overflow, you may often write tests like p + i < p. This works fine if p and i are unsigned integers, since any overflow in the addition will cause the value to simply "wrap around." However, using this pattern when p is a pointer is problematic because pointer overflow has undefined behavior according to the C and C++ standards. If the addition overflows and has an undefined result, the comparison will likewise be undefined; it may produce an unintended result, or may be deleted entirely by an optimizing compiler.

TianlongLiang commented 3 weeks ago

LGTM