summaryrefslogtreecommitdiff
path: root/test/msan
diff options
context:
space:
mode:
authorMaxim Ostapenko <chefmax7@gmail.com>2017-03-30 07:25:33 +0000
committerMaxim Ostapenko <chefmax7@gmail.com>2017-03-30 07:25:33 +0000
commit8b391d0ed5fc8278094b25299c01a953e932e942 (patch)
treed341d28dc485ecba4d2766a17a1a24c76c0d9bca /test/msan
parentb1170d7727ba630d3a0acc5588e773b030864c5c (diff)
[sanitizer] Move fread and fwrite interceptors to sanitizer_common
{M, T, E}San have fread and fwrite interceptors, let's move them to sanitizer_common to enable ASan checks as well. Differential Revision: https://reviews.llvm.org/D31456 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299061 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/msan')
-rw-r--r--test/msan/fread_fwrite.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/msan/fread_fwrite.cc b/test/msan/fread_fwrite.cc
new file mode 100644
index 000000000..3d500342a
--- /dev/null
+++ b/test/msan/fread_fwrite.cc
@@ -0,0 +1,34 @@
+// RUN: %clangxx_msan -g %s -o %t
+// RUN: not %t 2>&1 | FileCheck %s
+// RUN: %t 1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int test_fread() {
+ FILE *f = fopen("/dev/zero", "r");
+ char c;
+ unsigned read = fread(&c, sizeof(c), 1, f);
+ fclose(f);
+ if (c == '1') // No error
+ return 1;
+ return 0;
+}
+
+int test_fwrite() {
+ FILE *f = fopen("/dev/null", "w");
+ char c;
+ if (fwrite(&c, sizeof(c), 1, f) != sizeof(c)) // BOOM
+ return 1;
+ return fclose(f);
+}
+
+int main(int argc, char *argv[]) {
+ if (argc > 1)
+ test_fread();
+ else
+ test_fwrite();
+ return 0;
+}
+
+// CHECK: Uninitialized bytes in __interceptor_fwrite at offset 0 inside