Could anyone help to solve the following practice problem related to buffer overflow?

enter image description here enter image description here

  1. On this problem, I am confused about how the variables and addresses should be stored within the stack. Here is my best guess, but I'm not confident that it is correct:

enter image description here

  1. On this problem, I would think you would just need to fill up the stack with values corresponding to '0x41414141' until you got to the stored frame pointer. However, I'm not really sure what these values would be or how many to use.

The stack grows "downwards", i.e. from high addresses to low addresses. In the stack diagram that you are supposed to fill, addresses are "reversed" (address 0x00000004 is below address 0x00000000, not above it), so, in that diagram, the stack grows "up".

(The point to understand here is that there is no notion of gravity in the computer; the "up" and "down" are relative to a conventional direction, which may be that of a table on a piece of paper, or that of numerically growing address values, or whatever. Here, the table indicates addresses explicitly, with arrows that confirm the convention.)

So the 0x12ab34cd word (local variable a) should appear at addresses 0x00000014 to 0x00000017, immediately above the stored frame pointer. The buffer array is then immediately above that (addresses 0x00000008 to 0x00000013).

While the stack grows towards "low" addresses (the stack pointer is decremented when a value is pushed on the stack), the buffer is ordered towards "high" addresses (buffer[0] is at address 0x00000008, buffer[11] is at address 0x00000013).

That the machine is "big-endian" matters only for the ordering of bytes within a single word. It does not impact the order of appearance of words within the stack. Said otherwise, that the stack is "growing down" is not a consequence of the machine being "big-endian".

(Note: there have been some architectures with stacks "growing up" but they are quite uncommon these days, and the exercise would make no sense with a "growing up" stack.)

| improve this answer | |
  • I think you've helped to explain the first problem to me. I think I was a little confused on the direction that the stack was growing and how that would effect the placement of the addresses. However, I'm still confused on what kind of string the second problem is asking for. Could you provide an example? – user2276280 Apr 23 '15 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.