diff options
author | Vedant Kumar <vsk@apple.com> | 2017-07-25 19:34:23 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-07-25 19:34:23 +0000 |
commit | bbc953fed443409b1f342f6f0584047195705302 (patch) | |
tree | 3fe6e5df07dc23cbc3d726947aebb95bed679909 /clang/lib/Driver/SanitizerArgs.cpp | |
parent | 657ac14816febccd38c00c192ce18142d518210d (diff) | |
download | bcm5719-llvm-bbc953fed443409b1f342f6f0584047195705302.tar.gz bcm5719-llvm-bbc953fed443409b1f342f6f0584047195705302.zip |
[ubsan] Null-check pointers in -fsanitize=vptr (PR33881)
The instrumentation generated by -fsanitize=vptr does not null check a
user pointer before loading from it. This causes crashes in the face of
UB member calls (this=nullptr), i.e it's causing user programs to crash
only after UBSan is turned on.
The fix is to make run-time null checking a prerequisite for enabling
-fsanitize=vptr, and to then teach UBSan to reuse these run-time null
checks to make -fsanitize=vptr safe.
Testing: check-clang, check-ubsan, a stage2 ubsan-enabled build
Differential Revision: https://reviews.llvm.org/D35735
https://bugs.llvm.org/show_bug.cgi?id=33881
llvm-svn: 309007
Diffstat (limited to 'clang/lib/Driver/SanitizerArgs.cpp')
-rw-r--r-- | clang/lib/Driver/SanitizerArgs.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index f11917439b8..41f6d19a07f 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -306,6 +306,13 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC, Kinds &= ~Vptr; } + // Disable -fsanitize=vptr if -fsanitize=null is not enabled (the vptr + // instrumentation is broken without run-time null checks). + if ((Kinds & Vptr) && !(Kinds & Null)) { + Kinds &= ~Vptr; + D.Diag(diag::warn_drv_disabling_vptr_no_null_check); + } + // Check that LTO is enabled if we need it. if ((Kinds & NeedsLTO) && !D.isUsingLTO()) { D.Diag(diag::err_drv_argument_only_allowed_with) |