2
0

heap_defense.cc 562 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // Copyright (c) 2013-2021 Winlin
  3. //
  4. // SPDX-License-Identifier: MIT
  5. //
  6. /**
  7. @see: https://blog.csdn.net/win_lin/article/details/50461709
  8. config srs with gperf(to make gperftools):
  9. ./configure --gperf=on --gmd=on --jobs=3
  10. to check mem corruption:
  11. make && env TCMALLOC_PAGE_FENCE=1 ./heap_defense
  12. */
  13. #include <stdio.h>
  14. void foo(char* buf) {
  15. buf[16] = 0x0f;
  16. }
  17. void bar(char* buf) {
  18. printf("buf[15]=%#x\n", (unsigned char)buf[15]);
  19. }
  20. int main(int argc, char** argv) {
  21. char* buf = new char[16];
  22. foo(buf);
  23. bar(buf);
  24. return 0;
  25. }