1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t
2 // RUN: not %run %t NTOP_READ 2>&1 | FileCheck %s --check-prefix=NTOP_READ
3 // RUN: not %run %t PTON_READ 2>&1 | FileCheck %s --check-prefix=PTON_READ
11 #include <sanitizer/msan_interface.h>
13 int main(int iArgc
, char *szArgv
[]) {
19 if (test
== nullptr) {
21 const char *src
= "base64 test data";
22 size_t src_len
= strlen(src
);
23 size_t dst_len
= ((src_len
+ 2) / 3) * 4 + 1;
25 int res
= b64_ntop(reinterpret_cast<const unsigned char *>(src
), src_len
,
28 __msan_check_mem_is_initialized(dst
, res
);
31 unsigned char target
[dst_len
];
32 res
= b64_pton(dst
, target
, dst_len
);
34 __msan_check_mem_is_initialized(target
, res
);
36 // Check NTOP writing for zero length src
38 src_len
= strlen(src
);
39 assert(((src_len
+ 2) / 3) * 4 + 1 < dst_len
);
40 res
= b64_ntop(reinterpret_cast<const unsigned char *>(src
), src_len
,
43 __msan_check_mem_is_initialized(dst
, res
);
45 // Check PTON writing for zero length src
47 res
= b64_pton(dst
, target
, dst_len
);
49 __msan_check_mem_is_initialized(target
, res
);
54 if (strcmp(test
, "NTOP_READ") == 0) {
58 __msan_poison(src
, src_len
);
59 size_t dst_len
= ((src_len
+ 2) / 3) * 4 + 1;
61 int res
= b64_ntop(reinterpret_cast<const unsigned char *>(src
), src_len
,
63 // NTOP_READ: Uninitialized bytes in __b64_ntop
67 if (strcmp(test
, "PTON_READ") == 0) {
71 strcpy(src
, "junk longer than zero");
72 // pretend it is uninitialized
73 __msan_poison(src
, src_len
);
74 unsigned char target
[src_len
];
75 int res
= b64_pton(src
, target
, src_len
);
76 // PTON_READ: Uninitialized bytes in __b64_pton