diff options
author | Kostya Serebryany <kcc@google.com> | 2016-08-02 22:25:38 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-08-02 22:25:38 +0000 |
commit | 4ed012db1002fb2e8afa716fd17e6ad8912c18bc (patch) | |
tree | 7f179154995c5fe2f3acc82414a93659708fc89b /test/scudo/options.cpp | |
parent | 62d95f29b00657eb6177fc6ad5c4ec9590457e39 (diff) |
[sanitizer] Implement a __asan_default_options() equivalent for Scudo
Summary:
Currently, the Scudo Hardened Allocator only gets its flags via the SCUDO_OPTIONS environment variable.
With this patch, we offer the opportunity for programs to define their own options via __scudo_default_options() which behaves like __asan_default_options() (weak symbol).
A relevant test has been added as well, and the documentation updated accordingly.
I also used this patch as an opportunity to rename a few variables to comply with the LLVM naming scheme, and replaced a use of Report with dieWithMessage for consistency (and to avoid a callback).
Reviewers: llvm-commits, kcc
Differential Revision: https://reviews.llvm.org/D23018
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277536 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/scudo/options.cpp')
-rw-r--r-- | test/scudo/options.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/scudo/options.cpp b/test/scudo/options.cpp new file mode 100644 index 000000000..bccf7c8fb --- /dev/null +++ b/test/scudo/options.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_scudo %s -o %t +// RUN: %run %t 2>&1 +// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=0 %run %t 2>&1 +// RUN: SCUDO_OPTIONS=DeallocationTypeMismatch=1 not %run %t 2>&1 | FileCheck %s + +// Tests that the options can be passed using getScudoDefaultOptions, and that +// the environment ones take precedence over them. + +#include <stdlib.h> +#include <malloc.h> + +extern "C" const char* __scudo_default_options() { + return "DeallocationTypeMismatch=0"; // Defaults to true in scudo_flags.inc. +} + +int main(int argc, char **argv) +{ + int *p = (int *)malloc(16); + if (!p) + return 1; + delete p; + return 0; +} + +// CHECK: ERROR: allocation type mismatch on address |