summaryrefslogtreecommitdiff
path: root/lib/ubsan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:22 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:22 +0000
commit3a1720af1d7f43edc5b214cde0be11bfb94d077e (patch)
tree029e0ff2d5e3c0eaf2405fd8e669555fdf5e1297 /lib/ubsan
parent8f3cadc28cb2bb9e8f9d69eeaaea1f57f2f7b2ab (diff)
Notes
Diffstat (limited to 'lib/ubsan')
-rw-r--r--lib/ubsan/ubsan_checks.inc5
-rw-r--r--lib/ubsan/ubsan_diag.cpp (renamed from lib/ubsan/ubsan_diag.cc)4
-rw-r--r--lib/ubsan/ubsan_diag_standalone.cpp (renamed from lib/ubsan/ubsan_diag_standalone.cc)2
-rw-r--r--lib/ubsan/ubsan_flags.cpp (renamed from lib/ubsan/ubsan_flags.cc)3
-rw-r--r--lib/ubsan/ubsan_handlers.cpp (renamed from lib/ubsan/ubsan_handlers.cc)25
-rw-r--r--lib/ubsan/ubsan_handlers_cxx.cpp (renamed from lib/ubsan/ubsan_handlers_cxx.cc)2
-rw-r--r--lib/ubsan/ubsan_init.cpp (renamed from lib/ubsan/ubsan_init.cc)2
-rw-r--r--lib/ubsan/ubsan_init_standalone.cpp (renamed from lib/ubsan/ubsan_init_standalone.cc)2
-rw-r--r--lib/ubsan/ubsan_init_standalone_preinit.cpp (renamed from lib/ubsan/ubsan_init_standalone_preinit.cc)2
-rw-r--r--lib/ubsan/ubsan_monitor.cpp (renamed from lib/ubsan/ubsan_monitor.cc)2
-rw-r--r--lib/ubsan/ubsan_signals_standalone.cpp (renamed from lib/ubsan/ubsan_signals_standalone.cc)8
-rw-r--r--lib/ubsan/ubsan_type_hash.cpp (renamed from lib/ubsan/ubsan_type_hash.cc)4
-rw-r--r--lib/ubsan/ubsan_type_hash_itanium.cpp (renamed from lib/ubsan/ubsan_type_hash_itanium.cc)2
-rw-r--r--lib/ubsan/ubsan_type_hash_win.cpp (renamed from lib/ubsan/ubsan_type_hash_win.cc)2
-rw-r--r--lib/ubsan/ubsan_value.cpp (renamed from lib/ubsan/ubsan_value.cc)2
-rw-r--r--lib/ubsan/ubsan_win_dll_thunk.cpp (renamed from lib/ubsan/ubsan_win_dll_thunk.cc)2
-rw-r--r--lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp (renamed from lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc)2
-rw-r--r--lib/ubsan/ubsan_win_weak_interception.cpp (renamed from lib/ubsan/ubsan_win_weak_interception.cc)2
18 files changed, 48 insertions, 25 deletions
diff --git a/lib/ubsan/ubsan_checks.inc b/lib/ubsan/ubsan_checks.inc
index 7e7216c5b4ab7..33a8dfcde0269 100644
--- a/lib/ubsan/ubsan_checks.inc
+++ b/lib/ubsan/ubsan_checks.inc
@@ -18,6 +18,11 @@
UBSAN_CHECK(GenericUB, "undefined-behavior", "undefined")
UBSAN_CHECK(NullPointerUse, "null-pointer-use", "null")
+UBSAN_CHECK(NullptrWithOffset, "nullptr-with-offset", "pointer-overflow")
+UBSAN_CHECK(NullptrWithNonZeroOffset, "nullptr-with-nonzero-offset",
+ "pointer-overflow")
+UBSAN_CHECK(NullptrAfterNonZeroOffset, "nullptr-after-nonzero-offset",
+ "pointer-overflow")
UBSAN_CHECK(PointerOverflow, "pointer-overflow", "pointer-overflow")
UBSAN_CHECK(MisalignedPointerUse, "misaligned-pointer-use", "alignment")
UBSAN_CHECK(AlignmentAssumption, "alignment-assumption", "alignment")
diff --git a/lib/ubsan/ubsan_diag.cc b/lib/ubsan/ubsan_diag.cpp
index 529cc6985763b..1b2828d236d6e 100644
--- a/lib/ubsan/ubsan_diag.cc
+++ b/lib/ubsan/ubsan_diag.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_diag.cc -----------------------------------------------------===//
+//===-- ubsan_diag.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -404,7 +404,7 @@ static const char *kSuppressionTypes[] = {
void __ubsan::InitializeSuppressions() {
CHECK_EQ(nullptr, suppression_ctx);
- suppression_ctx = new (suppression_placeholder) // NOLINT
+ suppression_ctx = new (suppression_placeholder)
SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
suppression_ctx->ParseFromFile(flags()->suppressions);
}
diff --git a/lib/ubsan/ubsan_diag_standalone.cc b/lib/ubsan/ubsan_diag_standalone.cpp
index c22fd17499725..300179adae28c 100644
--- a/lib/ubsan/ubsan_diag_standalone.cc
+++ b/lib/ubsan/ubsan_diag_standalone.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_diag_standalone.cc ------------------------------------------===//
+//===-- ubsan_diag_standalone.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_flags.cc b/lib/ubsan/ubsan_flags.cpp
index 8a9498011932b..721c2273f133a 100644
--- a/lib/ubsan/ubsan_flags.cc
+++ b/lib/ubsan/ubsan_flags.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_flags.cc ----------------------------------------------------===//
+//===-- ubsan_flags.cpp ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -54,7 +54,6 @@ void InitializeFlags() {
{
CommonFlags cf;
cf.CopyFrom(*common_flags());
- cf.print_summary = false;
cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
OverrideCommonFlags(cf);
}
diff --git a/lib/ubsan/ubsan_handlers.cc b/lib/ubsan/ubsan_handlers.cpp
index 938ac89750f36..3f9da75a12a8d 100644
--- a/lib/ubsan/ubsan_handlers.cc
+++ b/lib/ubsan/ubsan_handlers.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_handlers.cc -------------------------------------------------===//
+//===-- ubsan_handlers.cpp ------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -691,14 +691,33 @@ static void handlePointerOverflowImpl(PointerOverflowData *Data,
ValueHandle Result,
ReportOptions Opts) {
SourceLocation Loc = Data->Loc.acquire();
- ErrorType ET = ErrorType::PointerOverflow;
+ ErrorType ET;
+
+ if (Base == 0 && Result == 0)
+ ET = ErrorType::NullptrWithOffset;
+ else if (Base == 0 && Result != 0)
+ ET = ErrorType::NullptrWithNonZeroOffset;
+ else if (Base != 0 && Result == 0)
+ ET = ErrorType::NullptrAfterNonZeroOffset;
+ else
+ ET = ErrorType::PointerOverflow;
if (ignoreReport(Loc, Opts, ET))
return;
ScopedReport R(Opts, Loc, ET);
- if ((sptr(Base) >= 0) == (sptr(Result) >= 0)) {
+ if (ET == ErrorType::NullptrWithOffset) {
+ Diag(Loc, DL_Error, ET, "applying zero offset to null pointer");
+ } else if (ET == ErrorType::NullptrWithNonZeroOffset) {
+ Diag(Loc, DL_Error, ET, "applying non-zero offset %0 to null pointer")
+ << Result;
+ } else if (ET == ErrorType::NullptrAfterNonZeroOffset) {
+ Diag(
+ Loc, DL_Error, ET,
+ "applying non-zero offset to non-null pointer %0 produced null pointer")
+ << (void *)Base;
+ } else if ((sptr(Base) >= 0) == (sptr(Result) >= 0)) {
if (Base > Result)
Diag(Loc, DL_Error, ET,
"addition of unsigned offset to %0 overflowed to %1")
diff --git a/lib/ubsan/ubsan_handlers_cxx.cc b/lib/ubsan/ubsan_handlers_cxx.cpp
index 9c324cc19a11f..2a6d558de0342 100644
--- a/lib/ubsan/ubsan_handlers_cxx.cc
+++ b/lib/ubsan/ubsan_handlers_cxx.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_handlers_cxx.cc ---------------------------------------------===//
+//===-- ubsan_handlers_cxx.cpp --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_init.cc b/lib/ubsan/ubsan_init.cpp
index f0bbe1ef10768..1a3b7d3726743 100644
--- a/lib/ubsan/ubsan_init.cc
+++ b/lib/ubsan/ubsan_init.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_init.cc -----------------------------------------------------===//
+//===-- ubsan_init.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_init_standalone.cc b/lib/ubsan/ubsan_init_standalone.cpp
index 323c2c1f9a474..91c3f57b424b9 100644
--- a/lib/ubsan/ubsan_init_standalone.cc
+++ b/lib/ubsan/ubsan_init_standalone.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_init_standalone.cc ------------------------------------------===//
+//===-- ubsan_init_standalone.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_init_standalone_preinit.cc b/lib/ubsan/ubsan_init_standalone_preinit.cpp
index bf344a2a9fcdb..fabbf919a4022 100644
--- a/lib/ubsan/ubsan_init_standalone_preinit.cc
+++ b/lib/ubsan/ubsan_init_standalone_preinit.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_init_standalone_preinit.cc ---------------------------------===//
+//===-- ubsan_init_standalone_preinit.cpp --------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_monitor.cc b/lib/ubsan/ubsan_monitor.cpp
index cb97a8ff1b887..d064e95f76f72 100644
--- a/lib/ubsan/ubsan_monitor.cc
+++ b/lib/ubsan/ubsan_monitor.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_monitor.cc ----------------------------------------*- C++ -*-===//
+//===-- ubsan_monitor.cpp ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_signals_standalone.cc b/lib/ubsan/ubsan_signals_standalone.cpp
index cc7900cb13649..2c91db8ca3974 100644
--- a/lib/ubsan/ubsan_signals_standalone.cc
+++ b/lib/ubsan/ubsan_signals_standalone.cpp
@@ -1,5 +1,4 @@
-//=-- ubsan_signals_standalone.cc
-//------------------------------------------------===//
+//=-- ubsan_signals_standalone.cpp ----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -46,8 +45,9 @@ namespace __ubsan {
static void OnStackUnwind(const SignalContext &sig, const void *,
BufferedStackTrace *stack) {
- ubsan_GetStackTrace(stack, kStackTraceMax, sig.pc, sig.bp, sig.context,
- common_flags()->fast_unwind_on_fatal);
+ ubsan_GetStackTrace(stack, kStackTraceMax,
+ StackTrace::GetNextInstructionPc(sig.pc), sig.bp,
+ sig.context, common_flags()->fast_unwind_on_fatal);
}
static void UBsanOnDeadlySignal(int signo, void *siginfo, void *context) {
diff --git a/lib/ubsan/ubsan_type_hash.cc b/lib/ubsan/ubsan_type_hash.cpp
index 431495672b55a..8f4b9aee50bbd 100644
--- a/lib/ubsan/ubsan_type_hash.cc
+++ b/lib/ubsan/ubsan_type_hash.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_type_hash.cc ------------------------------------------------===//
+//===-- ubsan_type_hash.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +11,7 @@
// permitted to use language features which require a C++ ABI library.
//
// Most of the implementation lives in an ABI-specific source file
-// (ubsan_type_hash_{itanium,win}.cc).
+// (ubsan_type_hash_{itanium,win}.cpp).
//
//===----------------------------------------------------------------------===//
diff --git a/lib/ubsan/ubsan_type_hash_itanium.cc b/lib/ubsan/ubsan_type_hash_itanium.cpp
index c4b048f20a8c9..97846d4dd434b 100644
--- a/lib/ubsan/ubsan_type_hash_itanium.cc
+++ b/lib/ubsan/ubsan_type_hash_itanium.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_type_hash_itanium.cc ----------------------------------------===//
+//===-- ubsan_type_hash_itanium.cpp ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_type_hash_win.cc b/lib/ubsan/ubsan_type_hash_win.cpp
index c7b2e45af4e66..45dcb758ec445 100644
--- a/lib/ubsan/ubsan_type_hash_win.cc
+++ b/lib/ubsan/ubsan_type_hash_win.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_type_hash_win.cc --------------------------------------------===//
+//===-- ubsan_type_hash_win.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_value.cc b/lib/ubsan/ubsan_value.cpp
index ba336a6673ca7..60f0b5c993482 100644
--- a/lib/ubsan/ubsan_value.cc
+++ b/lib/ubsan/ubsan_value.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_value.cc ----------------------------------------------------===//
+//===-- ubsan_value.cpp ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_win_dll_thunk.cc b/lib/ubsan/ubsan_win_dll_thunk.cpp
index fd39e210af0a8..5ac7fc3e08e4c 100644
--- a/lib/ubsan/ubsan_win_dll_thunk.cc
+++ b/lib/ubsan/ubsan_win_dll_thunk.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_win_dll_thunk.cc --------------------------------------------===//
+//===-- ubsan_win_dll_thunk.cpp -------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc b/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp
index 87ada6131cde0..00722b4033a53 100644
--- a/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc
+++ b/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_win_dynamic_runtime_thunk.cc --------------------------------===//
+//===-- ubsan_win_dynamic_runtime_thunk.cpp -------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/ubsan/ubsan_win_weak_interception.cc b/lib/ubsan/ubsan_win_weak_interception.cpp
index 8cf6344ce1d80..01db0c0ce78ab 100644
--- a/lib/ubsan/ubsan_win_weak_interception.cc
+++ b/lib/ubsan/ubsan_win_weak_interception.cpp
@@ -1,4 +1,4 @@
-//===-- ubsan_win_weak_interception.cc ------------------------------------===//
+//===-- ubsan_win_weak_interception.cpp -----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.