3 ms·
The allocator used on that project sure seems to think that off by one errors never happen. Why on earth would you put the in use bit in the first byte in your
by hinkley 10y ago
The allocator used on that project sure seems to think that off by one errors never happen. Why on earth would you put the in use bit in the first byte in your object header? Good grief.
- tedunangst 10y agoLets just say that dlmalloc is the product of another era.
- ams6110 10y agoIndeed -- VERSION 2.6.6 Sun Mar 5 19:10:03 2000
- jcoffland 10y agoWhat would you do instead? Add a padding byte in case of a buffer overflow? If you write code with lots of what-if-this-happened cases instead of just concentrating on creating correct code then you're most likely going to create an even bigger mess.
- jacquesm 10y agoNot a padding byte, but a word sized sentinel before and after the allocated block that gets checked upon free. Sentinel gone? -> overwrite bug detected.
- sebcat 10y agoIf you also have a known (preferably random) value as padding, and you check it at deallocation, it is called a canary, as in canaries in coal mines. It's a commonly used method to find/protect against overflows. For stack overflows, see -fstack-protector(-...) for gcc and clang. For heap overflows, it would depend on the implementation of malloc. glibc has mcheck() and MALLOC_CHECK_. If you're doing this as a part of release testing, ASan (and other *Sans like MSan) is worth looking into.