brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 12d9181 Raw
29 lines · cpp
1// RUN: %clangxx_msan %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=ON %s2// RUN: %clangxx_msan %s -o %t && env MSAN_OPTIONS=intercept_strndup=0 %run %t 2>&1 | FileCheck --check-prefix=OFF --allow-empty %s3 4// When built as C on Linux, strndup is transformed to __strndup.5// RUN: %clangxx_msan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=ON %s6 7// UNSUPPORTED: target={{.*windows-msvc.*}}8 9#include <assert.h>10#include <stdlib.h>11#include <string.h>12#include <sanitizer/msan_interface.h>13 14int main(int argc, char **argv) {15  char kString[4] = "abc";16  __msan_poison(kString + 2, 1);17  char *copy = strndup(kString, 4); // BOOM18  assert(__msan_test_shadow(copy, 4) == 2); // Poisoning is preserved.19  free(copy);20  return 0;21  // ON: Uninitialized bytes in {{(__)?}}strndup at offset 2 inside [{{.*}}, 4)22  // ON: MemorySanitizer: use-of-uninitialized-value23  // ON: #0 {{.*}}main {{.*}}strndup.cpp:[[@LINE-6]]24  // ON-LABEL: SUMMARY25  // ON: {{.*}}strndup.cpp:[[@LINE-8]]26  // OFF-NOT: MemorySanitizer27}28 29