mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-20 17:40:30 +00:00
Have ASAN errors show origin of memory
This commit is contained in:
parent
e20fcf02c1
commit
46a3b88594
6 changed files with 256 additions and 4 deletions
32
examples/auto-memory-safety-crash3.c
Normal file
32
examples/auto-memory-safety-crash3.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* ASAN use-after-free memory safety crash example.
|
||||
*
|
||||
* make -j8 MODE=dbg o/dbg/examples/auto-memory-safety-crash3.com
|
||||
* o/dbg/examples/auto-memory-safety-crash3.com
|
||||
*
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *buffer;
|
||||
ShowCrashReports(); /* not needed but yoinks appropriate symbols */
|
||||
buffer = malloc(13);
|
||||
strcpy(buffer, "hello");
|
||||
free(buffer);
|
||||
asm("" : "+r"(buffer)); /* prevent compiler being smart */
|
||||
buffer[0] = 1;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue