Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- char buffer[16];
- int main(int argc, char **argv) {
- if(argc < 2) {
- printf("no parameters specified\n");
- exit(-1);
- }
- char* allocated = malloc(32);
- strcpy(allocated, "test");
- printf("buffer address = %p\n", buffer);
- printf("allocated address = %p\n", allocated);
- printf("allocated address - buffer address = %lu\n", allocated - buffer);
- printf("allocated (before) = %s\n", allocated);
- // global buffer overflow may occur here
- // if argv[1] has more than 16 symbols
- strcpy(buffer, argv[1]);
- printf("allocated (after) = %s\n", allocated);
- free(allocated);
- }
Add Comment
Please, Sign In to add comment