4 ms·
do { => char prefix[pl+1]; Who do we git blame for this turd? Why hasn't their static analysis tooling found this?
by kevin_thibedeau 8y ago
do {
=> char prefix[pl+1];
Who do we git blame for this turd?
Why hasn't their static analysis tooling found this?
- saagarjha 8y agoTake a guess, or don't: https://github.com/systemd/systemd/commit/7286037fd438e93137571fa68a741cc894d8e549 https://github.com/systemd/systemd/commit/7286037fd438e93137...
- esjeon 8y agoB.e.a.utiful. I mean, he is a good programmer, but I’ve seen him (even in other projects) optimizing codes prematurely, which allows vulnerabilities to slip in. I understand the temptation, but many of his projects are mostly not performance critical. Not a good habit.
- alexeiz 8y agoWhat's your definition of a good programmer? Does the one who writes a lot of code and takes shortcuts meet that definition?
- kevin_thibedeau 8y agoThis isn't an optimization. It is pretending that C is like managed code and using the stack as a glorified garbage collector to avoid the responsibility of freeing memory. He did the same with his alloca() misuse. I would hope that they turn on -Wvla to find any more of these landmines.
- rambojazz 8y agoSorry what is wrong with "char prefix[pl+1]"? Isn't it just an array declaration?
- enqk 8y agopl is a variable. So this array size is variable. What would happen if the allocation cannot be made on the stack?
- ua16s1 8y agoI don't do much C, or any at all. What would happen? Would the allocation fail and you'd end up with prefix pointing to NULL? Or would it overwrite something else on the stack?
- rambojazz 8y agoAs far as I know if there is not enough space it should trigger a page fault, which in turn triggers an exception, which should probably result in a segmentation fault.
- pjmlp 8y agoNot necessarily, it might just corrupt neighbouring data, changing the behaviour of the exploited function.
- Someone 8y agoTraditionally, the allocation would nevertheless be made. Effect would be that the stack and the memory allocator shared memory. That typically doesn’t go well for long. The moment you write to that local variable (which technically need not happen, but if you don’t write to it, why have the variable at all?), you overwrite data in the heap and/or heap data structures. That will become a problem when the program reads that data or when the memory allocator walks the heap. Debugging this kind of problem is hard, as the buggy code often will run fine. It ‘just’ triggers problems at some unspecified later time, likely in a completely unrelated part of the program. So, guard pages ‘below’ the stack were added. They trigger exceptions that kill the offending program when it tries to write to or read from those pages. That doesn’t fully prevent this problem; large stack objects may jump over the protected area (especially in 32-bit code, you don’t want to give up lots of virtual address space to such guard pages, and the amount of address space ‘lost’ can add up fast in multi-threaded programs) Another way to detect this is to periodically (say in an interrupt handler, or whenever a call to the memory allocator is made) check that the stack pointer has a valid value. That isn’t sure-fire, either. Firstly, it can only detect problems after the fact and secondly, it may not see short violations of the rules.