brintos

brintos / llvm-project-archived public Read only

0
0
Text · 865 B · 5c23d4d Raw
38 lines · cpp
1// Checks that the __sanitizer_on_print hook gets the exact same sanitizer2// report as what is printed to stderr.3//4// RUN: %clangxx %s -o %t5// RUN: %run %t %t-onprint.txt 2>%t-stderr.txt || true6// RUN: diff %t-onprint.txt %t-stderr.txt7//8// UNSUPPORTED: android9 10#include <cassert>11#include <cstdlib>12#include <fcntl.h>13#include <string.h>14#include <sys/stat.h>15#include <sys/types.h>16#include <unistd.h>17 18int f;19volatile void *buf;20volatile char sink;21 22__attribute__((disable_sanitizer_instrumentation)) extern "C" void23__sanitizer_on_print(const char *str) {24  write(f, str, strlen(str));25}26 27int main(int argc, char *argv[]) {28  assert(argc >= 2);29  f = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666);30 31  // Use-after-free to trigger ASan/TSan reports.32  void *ptr = malloc(1);33  buf = ptr;34  free(ptr);35  sink = *static_cast<char *>(ptr);36  return 0;37}38