fork download
  1. // buggy.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. void copy_input(const char *input) {
  7. char *buffer = (char *)malloc(100);
  8. strcpy(buffer, input); // Possible overflow
  9. printf("Copied: %s\n", buffer);
  10. free(buffer);
  11. }
  12.  
  13. void call_uninit() {
  14. char *p=malloc(100);
  15. strcpy(p, "Danger!"); // Using uninitialized pointer
  16. }
  17.  
  18. int main() {
  19. copy_input("This input is too long for the buffer!");
  20. call_uninit();
  21.  
  22. char *leak = malloc(100);
  23. strcpy(leak, "Memory not freed"); // Leak here
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5324KB
stdin
1
2
10
42
11
stdout
Copied: This input is too long for the buffer!