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