3 ms·
That's what i thought, but apparently this is wrong. Had a disscussion about this here: https://news.ycombinator.com/item?id=27804810 https://news.ycombinator
by 1ris 4y ago
That's what i thought, but apparently this is wrong.
Had a disscussion about this here:
https://news.ycombinator.com/item?id=27804810 https://news.ycombinator.com/item?id=27804810
- Jensson 4y agoI don't believe they are correct, or at least their arguments doesn't explain why it wouldn't work. Volatile wouldn't work with memset since memset doesn't take a pointer to volatile memory, that is true, but you could set the volatile data yourself and it shouldn't be optimized away as per the spec. The data living on a stack doesn't matter, it works perfectly fine having volatile data on the stack. I tried the following code in a few compilers, it works perfectly for overwriting buffer pointers that goes out of scope, also tested removing the volatile to ensure that the memory write was ignored and I reproduced the code vulnerability where the previous message was still there the second time I tried to read a message, and from the way I read the spec this shouldn't be optimized away by any compiler: void memset_explicit(char* p, char c, size_t n) { volatile char* vp = p; while (n--) *vp++ = c; } Casting other data types to a pointer to volatile data is within the spec, and the compiler should then treat it like any other volatile data.
- deleted 4y ago[deleted]