Re:Warning: Implicit Backdoor
by lokedhs on Wednesday September 04, 2019 @09:28PM
(#20883082)
On Linux malloc doesn't crash if you give it a too large size. The cash only happens later once you're accessing a memory page that the kernel cannot allocate.
[ Parent
| on HN ]
Re:Warning: Implicit Backdoor
by deathanatos on Wednesday September 04, 2019 @10:30PM
(#20883373)
While malloc() won't "crash", it can and will, in some circumstances, return NULL. E.g., the following:
printf("%p\n", malloc(0x7fffffffffffffff));
prints (nil)
on my amd64 machine, as there is no way for the kernel to allocate that much virtual address space. (Even if it wouldn't back it w/ physical RAM.)The scenario being discussed in this subthread — having a negative number get inadvertently converted into a `size_t` and passed to `malloc()` is exactly the sort of way you end up getting a NULL back. But this is also not guaranteed.