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 | |
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(dest: s, src: "hello" ); |
21 | #endif |
22 | char *sp = s; |
23 | unsigned sz = 6; |
24 | bool_t res = xdr_bytes(&xdrs, &sp, &sz, sizeof(s)); |
25 | // CHECK: MemorySanitizer: use-of-uninitialized-value |
26 | // CHECK: {{in main.*sunrpc_bytes.cpp:}}[[@LINE-2]] |
27 | assert(res == TRUE); |
28 | xdr_destroy(&xdrs); |
29 | |
30 | xdrmem_create(&xdrs, buf, sizeof(buf), XDR_DECODE); |
31 | char s2[20]; |
32 | char *sp2 = s2; |
33 | unsigned sz2; |
34 | res = xdr_bytes(&xdrs, &sp2, &sz2, sizeof(s2)); |
35 | assert(res == TRUE); |
36 | assert(sz == sz2); |
37 | assert(strcmp(s, s2) == 0); |
38 | xdr_destroy(&xdrs); |
39 | return 0; |
40 | } |
41 | |