xref: /llvm-project/compiler-rt/test/msan/Linux/sunrpc_string.cpp (revision d21b3d346af2f6189638d853182e389555e7ccb9)
1 // REQUIRES: sunrpc
2 
3 // RUN: %clangxx_msan -g -O0 %s -o %t && \
4 // RUN:     %run %t 2>&1
5 // RUN: %clangxx_msan -g -O0 -DUNINIT=1 %s -o %t && \
6 // RUN:     not %run %t 2>&1 | FileCheck %s
7 
8 #include <assert.h>
9 #include <string.h>
10 #include <rpc/xdr.h>
11 
12 #include <sanitizer/msan_interface.h>
13 
main(int argc,char * argv[])14 int main(int argc, char *argv[]) {
15   XDR xdrs;
16   char buf[100];
17   xdrmem_create(&xdrs, buf, sizeof(buf), XDR_ENCODE);
18   char s[20];
19 #ifndef UNINIT
20   strcpy(s, "hello");
21 #endif
22   char *sp = s;
23   bool_t res = xdr_string(&xdrs, &sp, sizeof(s));
24   // CHECK: MemorySanitizer: use-of-uninitialized-value
25   // CHECK: {{in main.*sunrpc_string.cpp:}}[[@LINE-2]]
26   assert(res == TRUE);
27   xdr_destroy(&xdrs);
28 
29   xdrmem_create(&xdrs, buf, sizeof(buf), XDR_DECODE);
30   char s2[20];
31   char *sp2 = s2;
32   res = xdr_string(&xdrs, &sp2, sizeof(s2));
33   assert(res == TRUE);
34   assert(strcmp(s, s2) == 0);
35   xdr_destroy(&xdrs);
36   return 0;
37 }
38