Guest User

Untitled

a guest
Jan 6th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. char buffer[16];
  6.  
  7. int main(int argc, char **argv) {
  8. if(argc < 2) {
  9. printf("no parameters specified\n");
  10. exit(-1);
  11. }
  12.  
  13. char* allocated = malloc(32);
  14. strcpy(allocated, "test");
  15.  
  16. printf("buffer address = %p\n", buffer);
  17. printf("allocated address = %p\n", allocated);
  18. printf("allocated address - buffer address = %lu\n", allocated - buffer);
  19. printf("allocated (before) = %s\n", allocated);
  20.  
  21. // global buffer overflow may occur here
  22. // if argv[1] has more than 16 symbols
  23. strcpy(buffer, argv[1]);
  24.  
  25. printf("allocated (after) = %s\n", allocated);
  26.  
  27. free(allocated);
  28. }
Add Comment
Please, Sign In to add comment