1 // RUN: %clangxx_msan -O0 %s -o %t && %run %t %p 2>&1 | FileCheck %s
2 // RUN: %clangxx_msan -O0 -D_FILE_OFFSET_BITS=64 %s -o %t && %run %t %p 2>&1 | FileCheck %s
3 // RUN: %clangxx_msan -O3 %s -o %t && %run %t %p 2>&1 | FileCheck %s
13 #include <sys/types.h>
17 #include <sanitizer/msan_interface.h>
19 static void my_gl_closedir(void *dir
) {
25 static struct dirent
*my_gl_readdir(void *dir
) {
28 struct dirent
*d
= readdir((DIR *)dir
);
29 if (d
) __msan_poison(d
, d
->d_reclen
); // hehe
33 static void *my_gl_opendir(const char *s
) {
34 assert(__msan_test_shadow(s
, strlen(s
) + 1) == (size_t)-1);
38 static int my_gl_lstat(const char *s
, struct stat
*st
) {
39 assert(__msan_test_shadow(s
, strlen(s
) + 1) == (size_t)-1);
45 static int my_gl_stat(const char *s
, struct stat
*st
) {
46 assert(__msan_test_shadow(s
, strlen(s
) + 1) == (size_t)-1);
52 int main(int argc
, char *argv
[]) {
55 snprintf(buf
, sizeof(buf
), "%s/%s", argv
[1], "glob_test_root/*a");
58 globbuf
.gl_closedir
= my_gl_closedir
;
59 globbuf
.gl_readdir
= my_gl_readdir
;
60 globbuf
.gl_opendir
= my_gl_opendir
;
61 globbuf
.gl_lstat
= my_gl_lstat
;
62 globbuf
.gl_stat
= my_gl_stat
;
63 for (int i
= 0; i
< 10000; ++i
) {
64 int res
= glob(buf
, GLOB_ALTDIRFUNC
| GLOB_MARK
, 0, &globbuf
);
66 printf("%d %s\n", errno
, strerror(errno
));
67 assert(globbuf
.gl_pathc
== 2);
68 printf("%zu\n", strlen(globbuf
.gl_pathv
[0]));
69 printf("%zu\n", strlen(globbuf
.gl_pathv
[1]));
70 __msan_poison(globbuf
.gl_pathv
[0], strlen(globbuf
.gl_pathv
[0]) + 1);
71 __msan_poison(globbuf
.gl_pathv
[1], strlen(globbuf
.gl_pathv
[1]) + 1);