23 lines · c
1// RUN: %clang -shared -fPIC -D_DSO -O2 -D_FORTIFY_SOURCE=2 %s -o %t.so2// RUN: %clang_asan %s -o %t %t.so3// RUN: not %run %t 2>&1 | FileCheck %s4// REQUIRES: glibc-2.275#ifdef _DSO6#include <stdarg.h>7#include <stdio.h>8#include <stdlib.h>9#include <string.h>10__attribute__((noinline)) char foo(const char *format, ...) {11 char *write_buffer = (char *)malloc(1);12 va_list ap;13 va_start(ap, format);14 // CHECK: AddressSanitizer: heap-buffer-overflow15 vsprintf(write_buffer, format, ap);16 va_end(ap);17 return write_buffer[0];18}19#else20extern int foo(const char *format, ...);21int main() { return foo("%s_%s", "one", "two"); }22#endif23