brintos

brintos / llvm-project-archived public Read only

0
0
Text · 982 B · ade5e5b Raw
28 lines · cpp
1// When we link a binary without the -debug flag, ASan should print out VAs2// instead of RVAs. The frames for main and do_uaf should be above 0x400000,3// which is the default image base of an executable.4 5// RUN: rm -f %t.pdb6// RUN: %clangxx_asan -c -O2 %s -o %t.obj7// RUN: lld-link /nologo /OUT:%t.exe %t.obj -defaultlib:libcmt -nodefaultlib:msvcrt -defaultlib:oldnames %asan_static_runtime_thunk %asan_lib8// RUN: not %run %t.exe 2>&1 | FileCheck %s9// REQUIRES: lld-available10 11#include "../defines.h"12#include <stdio.h>13#include <stdlib.h>14int ATTRIBUTE_NOINLINE do_uaf(void);15int main() {16  int r = do_uaf();17  printf("r: %d\n", r);18  return r;19}20int do_uaf(void) {21  char *x = (char*)malloc(10 * sizeof(char));22  free(x);23  return x[5];24  // CHECK: AddressSanitizer: heap-use-after-free25  // CHECK: #0 {{0x[a-f0-9]+ \(.*[\\/]unsymbolized.cpp.*.exe\+(0x40|0x14000)[a-f0-9]{4}\)}}26  // CHECK: #1 {{0x[a-f0-9]+ \(.*[\\/]unsymbolized.cpp.*.exe\+(0x40|0x14000)[a-f0-9]{4}\)}}27}28