3 ms·
As I started reading the code my very first thought was "Well obviously the function we aren't being shown is free to wreak havoc". And it duly transpired that
by billforsternz 7y ago
As I started reading the code my very first thought was "Well obviously the function we aren't being shown is free to wreak havoc". And it duly transpired that thirdparty_process() was indeed wreaking havoc. Any C or C++ function with a parameter can take the address of that parameter and use it to overwrite random stuff on the stack frame if it wants too. In this case it's even less surprising as the parameter is already the address of a stack frame variable. Nothing really surprising here.
Thinking about it more you don't even need the parameter, just declare a local variable, take its address and go crazy. With great power (it's a systems programming language) comes great responsibility.
Wow, this is the most Hacker News comment I think I've ever posted, maybe I need to quit Hacker News :-).
- asveikau 7y ago> Thinking about it more you don't even need the parameter, just declare a local variable, take its address and go crazy. If you go one layer below with some assembly, you don't even need variables. Just take the stack pointer register (rsp on amd64) and start writing! Or maybe no assembly needed, just cast an arbitrary hexadecimal value you think is likely to be in range to be your stack pointer [may vary by platform, ASLR, how many frames are on the stack, etc.] into a pointer and go to town.