Open In App

Analyzing BufferOverflow with GDB

Pre-requisite: GDB (Step by Step Introduction)

A BufferOverflow often occurs when the content inside the defined variable is copied to another variable without doing Bound Checks or considering the size of the buffer. Let’s analyze buffer overflow with the help GNU Debugger (GDB) which is inbuilt every Linux system.



The motive of this exercise is to get comfortable with debugging code and understand how does buffer overflow works in action.




#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
  
int main(int argc, char** argv)
{
    volatile int cantoverflowme;
    char buffer[64];
  
    cantoverflowme = 0;
    gets(buffer);
  
    if (cantoverflowme != 0) {
        printf("You OVERFLOW'ed Me\n");
    }
    else {
        printf("Can't Overflow Me\n");
    }
}


Article Tags :