I'm currently trying to do some tests with the buffer overflow vulnerability. Here is the vulnerable code
void win()
  {
      printf("code flow successfully changed\n");
  }
int main(int argc, char **argv)
  {
      volatile int (*fp)();
      char buffer[64];
      fp = 0;
      gets(buffer);
      if(fp) {
           printf("calling function pointer, jumping to 0x%08x\n", fp);
           fp();
             }
   }
The exploit is quite sample and very basic: all what I need here is to overflow the buffer and override the fp value to make it hold the address of win() function. While trying to debug the program, I figured out that fb is placed below the buffer (i.e with a lower address in memory), and thus I am not able to modify its value. I thought that once we declare a local variable x before y, x will be higher in memory (i.e at the bottom of the stack) so x can override y if it exceeds its boundaries which is not the case here. I'm compiling the program with gcc gcc version 5.2.1, no special flags (only tested -O0)
Any clue?
 
     
    