c - Stack Smashing attempt giving segfault -


I'm trying to make an example from C, but stuck on one point in a way, the following code I have Ubuntu 64-bit machine with 64-bit):

  int main () {int x; X = 0; Ceremony (1,2,3); X = 1; Printf ("x is:% d \ n", x); } Zero func (int a, int b, int c) {char buffer [1]; Int * ret; Rate = buffer + 17; (* Rate) + = 7; }  

The above code works fine and does not execute when returning the line x = 1 , but I ret = buffer + 17; , this ret = buffer + 16; should not be, 8bytes for buffer and 8 for the base pointer saved on the stack.

Secondly, I understand that buffer [1] is taking 8 bytes (due to the 64-bit arch) and if I call this buffer buffer [ 2] I say, still the same code should work fine, but this is not happening and it begins to blame.

Regards, Numan

8 on every architecture used on 'each' Bits even if it is 8 bit micro, a 16 bit micro, 32 bit PC or 64 bit new PC. On the other hand, in other words, words can be shaped.

The order placed on the stack can be unique to the local order. My guess is that if your compiler is putting "int * rate" on the stack before "four buffers", then to get to the return address, we need "four buffers" (1 byte), "int * rate" (8 bytes) , And have to go through the saved base pointer (8 bytes) for a total of 17 bytes. / P>

Here is a description of stack frame on x86 64-bit:


Comments