Created
October 21, 2020 20:03
-
-
Save 505e06b2/f4a7835c58a70e61e233987411636d5b to your computer and use it in GitHub Desktop.
Check for buffer overflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
struct { | |
char buffer[sizeof(int)]; //must be word aligned or will be forced by the compiler | |
volatile int modified; | |
} container; | |
container.modified = 0; | |
printf("System word size is: %lu\nEnter Text: ", sizeof(int)); | |
gets(container.buffer); | |
if(container.modified) { | |
printf("Buffer overflow detected\n"); | |
} else { | |
printf("You didn't overflow\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment