The allocate family takes a uinteger as its param causing overflow and misleading results if passed larger types/values than uinteger
Affects:
-arch 32bit, both GAS and GCC
Description:
Passing a value larger than MAX_UINTEGER causes an overflow, which can cause code that should fail to succeed with no indicator to the user of any issue.
See the code for an example.
Solution:
Add a check to ensure the passed value is less than or equal to MAX_UINTEGER
Code to reproduce, compile for -arch 32:
Code: Select all
'fbcs: -arch 32
'// "Bug" in 32bit allocate accepting values larger than 32bit causing overflow and success
const as uinteger _mb = (1024 * 1024)
const as uinteger _gb = (1024 * _mb)
dim as ulongint size = 4.5 * _gb '// 4.5 GB
print "Allocating "& size \ _mb &" MB"
dim as any ptr p = allocate(size)
if p then
print " ""Successfully"" allocated "& size \ _mb &" MB on a 32bit system, p is 0x"& hex(p)
print " In reality the block is only the lower 32bits (overflow), which is "& (size and &h00000000ffffffffull) \ _mb &" MB"
print " This can cause some serious buffer overflow bugs"
deallocate p
p = 0
else
print " Failed as expected!"
end if
sleep
end