Buffer overflows: quick mental model
The stack is just bytes. Functions place local buffers on the stack next to saved state (saved base pointer and the return address).
If input writes more than the buffer can hold, it overwrites whatever comes next. Classic target: the saved return address (RIP). If you overwrite it, you control where the program returns.
Tip: On x86_64, sometimes insert one extra ret to fix stack alignment.