Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <signal.h>
- #include <unistd.h>
- #include <stdlib.h>
- #define BUFFER_SIZE 32
- void signal_handler_seg_fault(int sig) {
- printf("Segmentation fault, accessing memory in page not mapped by process pid %d\n", getpid());
- exit(1);
- }
- int main()
- {
- int a = 0;
- char buffer[BUFFER_SIZE];
- printf("Difference: %ld bytes\n", (char*)&a - buffer);
- signal(SIGSEGV, signal_handler_seg_fault);
- gets(buffer);
- printf("Data: %s\n", buffer);
- printf("Value of a: %d\n", a);
- return 0;
- }
Advertisement
Comments
-
- Check the full blog at: https://syedumair327.blogspot.com/2025/12/buffer-overflow.html
Add Comment
Please, Sign In to add comment