4 ms·
Awesome explanation! Thank you! Does this mean also that function pointers inherently weaken security (by providing a means of code execution given other fault
by lubesGordi 7y ago
Awesome explanation! Thank you!
Does this mean also that function pointers inherently weaken security (by providing a means of code execution given other faults)?
- l33tman 7y agoThey are a very common design-pattern in traditional C, as you kind of emulate object-oriented virtual function overloading by using them in structs. I don't think it's realistic to avoid them just by principle.. As in network server hardening, you can usually start by following where user-provided data goes, and harden its path. In this case however the first problem was a clandestine bug (the double free in some cases), probably induced by the programmer trying to be a bit too clever with the management of these structs (if you're not threaded you could simply have a single static declaration for this info struct and forget the malloc/freeing, or at least malloc it just once upon each thread init, haven't looked at this code..). Generally keeping track of all malloc/free pairs is tricky and you can go a long way by trying to simplify your logic, I mean even if you don't get exploited like this, you might simply crash sometime or leak memory or in general behave badly. There are good reasons why there exist all kinds of memory-managed languages :)
- saagarjha 7y agoWell, yes, but the existence of function pointers is basically a given for most languages. For example, your C++ may not have an explicit function pointer in it anywhere, but its vtables are just as good.