]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/msan/strndup.cc
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / msan / strndup.cc
1 // RUN: %clangxx_msan %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=ON %s
2 // RUN: %clangxx_msan %s -o %t && MSAN_OPTIONS=intercept_strndup=0 %run %t 2>&1 | FileCheck --check-prefix=OFF --allow-empty %s
3
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 %s
6
7 // UNSUPPORTED: win32
8
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <sanitizer/msan_interface.h>
13
14 int main(int argc, char **argv) {
15 char kString[4] = "abc";
16 __msan_poison(kString + 2, 1);
17 char *copy = strndup(kString, 4); // BOOM
18 assert(__msan_test_shadow(copy, 4) == 2); // Poisoning is preserved.
19 free(copy);
20 return 0;
21 // ON: Uninitialized bytes in __interceptor_{{(__)?}}strndup at offset 2 inside [{{.*}}, 4)
22 // ON: MemorySanitizer: use-of-uninitialized-value
23 // ON: #0 {{.*}}main {{.*}}strndup.cc:[[@LINE-6]]
24 // ON-LABEL: SUMMARY
25 // ON: {{.*}}strndup.cc:[[@LINE-8]]
26 // OFF-NOT: MemorySanitizer
27 }
28