aboutsummaryrefslogtreecommitdiff
path: root/lib/msan/lit_tests/Linux
diff options
context:
space:
mode:
Diffstat (limited to 'lib/msan/lit_tests/Linux')
-rw-r--r--lib/msan/lit_tests/Linux/glob.cc1
-rw-r--r--lib/msan/lit_tests/Linux/glob_altdirfunc.cc78
-rw-r--r--lib/msan/lit_tests/Linux/glob_nomatch.cc21
-rw-r--r--lib/msan/lit_tests/Linux/syscalls.cc50
-rw-r--r--lib/msan/lit_tests/Linux/tcgetattr.cc21
5 files changed, 171 insertions, 0 deletions
diff --git a/lib/msan/lit_tests/Linux/glob.cc b/lib/msan/lit_tests/Linux/glob.cc
index 513679c6d3d7..387ce3cf5f1a 100644
--- a/lib/msan/lit_tests/Linux/glob.cc
+++ b/lib/msan/lit_tests/Linux/glob.cc
@@ -1,4 +1,5 @@
// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p 2>&1 | FileCheck %s
+// RUN: %clangxx_msan -m64 -O0 -D_FILE_OFFSET_BITS=64 %s -o %t && %t %p 2>&1 | FileCheck %s
// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t %p 2>&1 | FileCheck %s
#include <assert.h>
diff --git a/lib/msan/lit_tests/Linux/glob_altdirfunc.cc b/lib/msan/lit_tests/Linux/glob_altdirfunc.cc
new file mode 100644
index 000000000000..b8200c3ee899
--- /dev/null
+++ b/lib/msan/lit_tests/Linux/glob_altdirfunc.cc
@@ -0,0 +1,78 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p 2>&1 | FileCheck %s
+// RUN: %clangxx_msan -m64 -O0 -D_FILE_OFFSET_BITS=64 %s -o %t && %t %p 2>&1 | FileCheck %s
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t %p 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include <sanitizer/msan_interface.h>
+
+static void my_gl_closedir(void *dir) {
+ if (!dir)
+ exit(1);
+ closedir((DIR *)dir);
+}
+
+static struct dirent *my_gl_readdir(void *dir) {
+ if (!dir)
+ exit(1);
+ struct dirent *d = readdir((DIR *)dir);
+ if (d) __msan_poison(d, d->d_reclen); // hehe
+ return d;
+}
+
+static void *my_gl_opendir(const char *s) {
+ assert(__msan_test_shadow(s, strlen(s) + 1) == (size_t)-1);
+ return opendir(s);
+}
+
+static int my_gl_lstat(const char *s, struct stat *st) {
+ assert(__msan_test_shadow(s, strlen(s) + 1) == (size_t)-1);
+ if (!st)
+ exit(1);
+ return lstat(s, st);
+}
+
+static int my_gl_stat(const char *s, struct stat *st) {
+ assert(__msan_test_shadow(s, strlen(s) + 1) == (size_t)-1);
+ if (!st)
+ exit(1);
+ return lstat(s, st);
+}
+
+int main(int argc, char *argv[]) {
+ assert(argc == 2);
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "%s/%s", argv[1], "glob_test_root/*a");
+
+ glob_t globbuf;
+ globbuf.gl_closedir = my_gl_closedir;
+ globbuf.gl_readdir = my_gl_readdir;
+ globbuf.gl_opendir = my_gl_opendir;
+ globbuf.gl_lstat = my_gl_lstat;
+ globbuf.gl_stat = my_gl_stat;
+ for (int i = 0; i < 10000; ++i) {
+ int res = glob(buf, GLOB_ALTDIRFUNC | GLOB_MARK, 0, &globbuf);
+ assert(res == 0);
+ printf("%d %s\n", errno, strerror(errno));
+ assert(globbuf.gl_pathc == 2);
+ printf("%zu\n", strlen(globbuf.gl_pathv[0]));
+ printf("%zu\n", strlen(globbuf.gl_pathv[1]));
+ __msan_poison(globbuf.gl_pathv[0], strlen(globbuf.gl_pathv[0]) + 1);
+ __msan_poison(globbuf.gl_pathv[1], strlen(globbuf.gl_pathv[1]) + 1);
+ globfree(&globbuf);
+ }
+
+ printf("PASS\n");
+ // CHECK: PASS
+ return 0;
+}
diff --git a/lib/msan/lit_tests/Linux/glob_nomatch.cc b/lib/msan/lit_tests/Linux/glob_nomatch.cc
new file mode 100644
index 000000000000..0262034aec5b
--- /dev/null
+++ b/lib/msan/lit_tests/Linux/glob_nomatch.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && %t %p
+
+#include <assert.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+ assert(argc == 2);
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "%s/%s", argv[1], "glob_test_root/*c");
+
+ glob_t globbuf;
+ int res = glob(buf, 0, 0, &globbuf);
+ assert(res == GLOB_NOMATCH);
+ assert(globbuf.gl_pathc == 0);
+ if (globbuf.gl_pathv == 0)
+ exit(0);
+ return 0;
+}
diff --git a/lib/msan/lit_tests/Linux/syscalls.cc b/lib/msan/lit_tests/Linux/syscalls.cc
index c12eda39189e..ec308bfe30ca 100644
--- a/lib/msan/lit_tests/Linux/syscalls.cc
+++ b/lib/msan/lit_tests/Linux/syscalls.cc
@@ -7,6 +7,10 @@
#include <stdio.h>
#include <string.h>
+#include <linux/aio_abi.h>
+#include <sys/ptrace.h>
+#include <sys/stat.h>
+
#include <sanitizer/linux_syscall_hooks.h>
#include <sanitizer/msan_interface.h>
@@ -16,6 +20,7 @@
int main(int argc, char *argv[]) {
char buf[1000];
const int kTen = 10;
+ const int kFortyTwo = 42;
memset(buf, 0, sizeof(buf));
__msan_unpoison(buf, sizeof(buf));
__sanitizer_syscall_pre_recvmsg(0, buf, 0);
@@ -46,5 +51,50 @@ int main(int argc, char *argv[]) {
__msan_poison(buf, kTen + 1);
__sanitizer_syscall_post_getdents64(kTen, 0, buf, kTen);
assert(__msan_test_shadow(buf, sizeof(buf)) == kTen);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_clock_getres(0, 0, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(long) * 2);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_clock_gettime(0, 0, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(long) * 2);
+
+ // Failed syscall does not write to the buffer.
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_clock_gettime(-1, 0, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 0);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_read(5, 42, buf, 10);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 5);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_newfstatat(0, 5, "/path/to/file", buf, 0);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(struct stat));
+
+ __msan_poison(buf, sizeof(buf));
+ int prio = 0;
+ __sanitizer_syscall_post_mq_timedreceive(kFortyTwo, 5, buf, sizeof(buf), &prio, 0);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == kFortyTwo);
+ assert(__msan_test_shadow(&prio, sizeof(prio)) == -1);
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_ptrace(0, PTRACE_PEEKUSER, kFortyTwo, 0xABCD, buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == sizeof(void *));
+
+ __msan_poison(buf, sizeof(buf));
+ struct iocb iocb[2];
+ struct iocb *iocbp[2] = { &iocb[0], &iocb[1] };
+ memset(iocb, 0, sizeof(iocb));
+ iocb[0].aio_lio_opcode = IOCB_CMD_PREAD;
+ iocb[0].aio_buf = (__u64)buf;
+ iocb[0].aio_nbytes = kFortyTwo;
+ iocb[1].aio_lio_opcode = IOCB_CMD_PREAD;
+ iocb[1].aio_buf = (__u64)(&buf[kFortyTwo]);
+ iocb[1].aio_nbytes = kFortyTwo;
+ __sanitizer_syscall_post_io_submit(1, 0, 2, &iocbp);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == kFortyTwo);
+
return 0;
}
diff --git a/lib/msan/lit_tests/Linux/tcgetattr.cc b/lib/msan/lit_tests/Linux/tcgetattr.cc
new file mode 100644
index 000000000000..e6e101db884f
--- /dev/null
+++ b/lib/msan/lit_tests/Linux/tcgetattr.cc
@@ -0,0 +1,21 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t %p
+
+#include <assert.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+ int fd = getpt();
+ assert(fd >= 0);
+
+ struct termios t;
+ int res = tcgetattr(fd, &t);
+ assert(!res);
+
+ if (t.c_iflag == 0)
+ exit(0);
+ return 0;
+}