fork download
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/mman.h>
  6.  
  7. // Bypass -Werror on ideone.
  8. #pragma GCC diagnostic warning "-Wnonnull"
  9. #pragma GCC diagnostic warning "-Wformat"
  10.  
  11. static void look_ma_i_have_page_zero(void)
  12. {
  13. if (mmap(NULL, 4096, PROT_READ | PROT_WRITE,
  14. MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED) {
  15. perror("mmap() failed");
  16. exit(1);
  17. }
  18. }
  19.  
  20. int main(void)
  21. {
  22. look_ma_i_have_page_zero();
  23.  
  24. // Теперь можно так:
  25. strcpy(NULL, "sup /pr/");
  26. printf("%s\n", NULL);
  27.  
  28. // Или так.
  29. int *ptr = NULL;
  30. printf("Reading at %p: %i\n", ptr, *ptr);
  31. }
  32.  
Runtime error #stdin #stdout #stderr 0s 4204KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
mmap() failed: Operation not permitted