test_setenv_leak.c 385 B

123456789101112131415161718
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. int main(int argc, char **argv)
  5. {
  6. char buf[256];
  7. int i = argv[1] ? atoi(argv[1]) : 999999;
  8. while (--i > 0) {
  9. sprintf(buf, "%d", i);
  10. setenv("VAR", buf, 1);
  11. }
  12. printf("Check size of [heap] mapping:\n");
  13. freopen("/proc/self/maps", "r", stdin);
  14. while (fgets(buf, sizeof(buf), stdin))
  15. fputs(buf, stdout);
  16. return 0;
  17. }