Why would buffer overruns cause segmentation faults when accessing an integer?

前端 未结 5 1054
情书的邮戳
情书的邮戳 2021-01-19 09:39

During a call to function B() from function A(), B() allocates a 100-char array and fills it several times, including once with a 101-character string and once with a 110 ch

5条回答
  •  无人及你
    2021-01-19 10:34

    When A() calls B(), B's preamble instructions save A's frame pointer—the location on the stack where A keeps local variables, before replacing it with B's own frame pointer. It looks like this:

    Stack Frame

    When B overruns its local variables, it messes up the value which will be reloaded into the frame pointer. This is garbage as a frame pointer value, so all of A's local variables are trashed. Worse, future writes to local variables are messing with memory belonging to someone else.

提交回复
热议问题