diff options
| author | Alexey Samsonov <samsonov@google.com> | 2014-02-14 14:06:10 +0000 |
|---|---|---|
| committer | Alexey Samsonov <samsonov@google.com> | 2014-02-14 14:06:10 +0000 |
| commit | 9f20d6703479a952465f7db0c2fbd70904c030c2 (patch) | |
| tree | 165b5b998b1e69a1186b403115919f3b9f3fc1fa /compiler-rt/test/asan/TestCases/Linux/interception_readdir_r_test.cc | |
| parent | 8434e60f7e2d8e5da48d94f612cf980a5d63bcec (diff) | |
| download | bcm5719-llvm-9f20d6703479a952465f7db0c2fbd70904c030c2.tar.gz bcm5719-llvm-9f20d6703479a952465f7db0c2fbd70904c030c2.zip | |
Move ASan lit-tests under test/asan
llvm-svn: 201413
Diffstat (limited to 'compiler-rt/test/asan/TestCases/Linux/interception_readdir_r_test.cc')
| -rw-r--r-- | compiler-rt/test/asan/TestCases/Linux/interception_readdir_r_test.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/Linux/interception_readdir_r_test.cc b/compiler-rt/test/asan/TestCases/Linux/interception_readdir_r_test.cc new file mode 100644 index 00000000000..198e1f3884d --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Linux/interception_readdir_r_test.cc @@ -0,0 +1,59 @@ +// RUN: %clangxx_asan -O0 %s -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O1 %s -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O2 %s -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// +// RUN: %clangxx_asan -O0 %s -D_FILE_OFFSET_BITS=64 -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O1 %s -D_FILE_OFFSET_BITS=64 -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O2 %s -D_FILE_OFFSET_BITS=64 -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O3 %s -D_FILE_OFFSET_BITS=64 -DTEMP_DIR='"'"%T"'"' -o %t && %t 2>&1 | FileCheck %s + +#include <dirent.h> +#include <memory.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + + +int main() { + // Ensure the readdir_r interceptor doesn't erroneously mark the entire dirent + // as written when the end of the directory pointer is reached. + fputs("test1: reading the " TEMP_DIR " directory...\n", stderr); + DIR *d = opendir(TEMP_DIR); + struct dirent *result = (struct dirent *)(0xfeedbeef); + // We assume the temp dir for this test doesn't have crazy long file names. + char entry_buffer[4096]; + memset(entry_buffer, 0xab, sizeof(entry_buffer)); + unsigned count = 0; + do { + // Stamp the entry struct to try to trick the interceptor. + ((struct dirent *)entry_buffer)->d_reclen = 9999; + if (readdir_r(d, (struct dirent *)entry_buffer, &result) != 0) + abort(); + ++count; + } while (result != NULL); + fprintf(stderr, "read %d entries\n", count); + closedir(d); + // CHECK: test1: reading the {{.*}} directory... + // CHECK-NOT: stack-buffer-overflow + // CHECK: read {{.*}} entries + + // Ensure the readdir64_r interceptor doesn't have the bug either. + fputs("test2: reading the " TEMP_DIR " directory...\n", stderr); + d = opendir(TEMP_DIR); + struct dirent64 *result64; + memset(entry_buffer, 0xab, sizeof(entry_buffer)); + count = 0; + do { + // Stamp the entry struct to try to trick the interceptor. + ((struct dirent64 *)entry_buffer)->d_reclen = 9999; + if (readdir64_r(d, (struct dirent64 *)entry_buffer, &result64) != 0) + abort(); + ++count; + } while (result64 != NULL); + fprintf(stderr, "read %d entries\n", count); + closedir(d); + // CHECK: test2: reading the {{.*}} directory... + // CHECK-NOT: stack-buffer-overflow + // CHECK: read {{.*}} entries +} |

