2013-08-30 18:12:58 +02:00
|
|
|
//===-- ubsan_diag.cc -----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Diagnostic reporting for the UBSan runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "ubsan_platform.h"
|
|
|
|
#if CAN_SANITIZE_UB
|
2013-08-30 18:12:58 +02:00
|
|
|
#include "ubsan_diag.h"
|
2014-09-23 19:59:53 +02:00
|
|
|
#include "ubsan_init.h"
|
|
|
|
#include "ubsan_flags.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
2013-08-30 18:12:58 +02:00
|
|
|
#include "sanitizer_common/sanitizer_report_decorator.h"
|
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
2014-11-13 21:41:38 +01:00
|
|
|
#include "sanitizer_common/sanitizer_stacktrace_printer.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "sanitizer_common/sanitizer_suppressions.h"
|
2013-08-30 18:12:58 +02:00
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
using namespace __ubsan;
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
static void MaybePrintStackTrace(uptr pc, uptr bp) {
|
2015-10-21 09:32:45 +02:00
|
|
|
// We assume that flags are already parsed, as UBSan runtime
|
2014-09-23 19:59:53 +02:00
|
|
|
// will definitely be called when we print the first diagnostics message.
|
|
|
|
if (!flags()->print_stacktrace)
|
|
|
|
return;
|
|
|
|
// We can only use slow unwind, as we don't have any information about stack
|
|
|
|
// top/bottom.
|
|
|
|
// FIXME: It's better to respect "fast_unwind_on_fatal" runtime flag and
|
|
|
|
// fetch stack top/bottom information if we have it (e.g. if we're running
|
|
|
|
// under ASan).
|
|
|
|
if (StackTrace::WillUseFastUnwind(false))
|
|
|
|
return;
|
2014-11-13 21:41:38 +01:00
|
|
|
BufferedStackTrace stack;
|
2014-09-23 19:59:53 +02:00
|
|
|
stack.Unwind(kStackTraceMax, pc, bp, 0, 0, 0, false);
|
|
|
|
stack.Print();
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
static const char *ConvertTypeToString(ErrorType Type) {
|
|
|
|
switch (Type) {
|
2016-11-08 23:04:09 +01:00
|
|
|
#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName) \
|
2015-10-21 09:32:45 +02:00
|
|
|
case ErrorType::Name: \
|
|
|
|
return SummaryKind;
|
|
|
|
#include "ubsan_checks.inc"
|
|
|
|
#undef UBSAN_CHECK
|
|
|
|
}
|
|
|
|
UNREACHABLE("unknown ErrorType!");
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
static const char *ConvertTypeToFlagName(ErrorType Type) {
|
|
|
|
switch (Type) {
|
|
|
|
#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName) \
|
|
|
|
case ErrorType::Name: \
|
|
|
|
return FSanitizeFlagName;
|
|
|
|
#include "ubsan_checks.inc"
|
|
|
|
#undef UBSAN_CHECK
|
|
|
|
}
|
|
|
|
UNREACHABLE("unknown ErrorType!");
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
static void MaybeReportErrorSummary(Location Loc, ErrorType Type) {
|
2014-09-23 19:59:53 +02:00
|
|
|
if (!common_flags()->print_summary)
|
|
|
|
return;
|
2015-10-21 09:32:45 +02:00
|
|
|
if (!flags()->report_error_type)
|
|
|
|
Type = ErrorType::GenericUB;
|
|
|
|
const char *ErrorKind = ConvertTypeToString(Type);
|
2014-09-23 19:59:53 +02:00
|
|
|
if (Loc.isSourceLocation()) {
|
|
|
|
SourceLocation SLoc = Loc.getSourceLocation();
|
|
|
|
if (!SLoc.isInvalid()) {
|
2015-10-21 09:32:45 +02:00
|
|
|
AddressInfo AI;
|
|
|
|
AI.file = internal_strdup(SLoc.getFilename());
|
|
|
|
AI.line = SLoc.getLine();
|
|
|
|
AI.column = SLoc.getColumn();
|
|
|
|
AI.function = internal_strdup(""); // Avoid printing ?? as function name.
|
|
|
|
ReportErrorSummary(ErrorKind, AI);
|
|
|
|
AI.Clear();
|
2014-09-23 19:59:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
} else if (Loc.isSymbolizedStack()) {
|
|
|
|
const AddressInfo &AI = Loc.getSymbolizedStack()->info;
|
|
|
|
ReportErrorSummary(ErrorKind, AI);
|
|
|
|
return;
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
ReportErrorSummary(ErrorKind);
|
2014-09-23 19:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class Decorator : public SanitizerCommonDecorator {
|
|
|
|
public:
|
|
|
|
Decorator() : SanitizerCommonDecorator() {}
|
|
|
|
const char *Highlight() const { return Green(); }
|
|
|
|
const char *EndHighlight() const { return Default(); }
|
|
|
|
const char *Note() const { return Black(); }
|
|
|
|
const char *EndNote() const { return Default(); }
|
|
|
|
};
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
SymbolizedStack *__ubsan::getSymbolizedLocation(uptr PC) {
|
|
|
|
InitAsStandaloneIfNecessary();
|
|
|
|
return Symbolizer::GetOrInit()->SymbolizePC(PC);
|
2013-08-30 18:12:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Diag &Diag::operator<<(const TypeDescriptor &V) {
|
|
|
|
return AddArg(V.getTypeName());
|
|
|
|
}
|
|
|
|
|
|
|
|
Diag &Diag::operator<<(const Value &V) {
|
|
|
|
if (V.getType().isSignedIntegerTy())
|
|
|
|
AddArg(V.getSIntValue());
|
|
|
|
else if (V.getType().isUnsignedIntegerTy())
|
|
|
|
AddArg(V.getUIntValue());
|
|
|
|
else if (V.getType().isFloatTy())
|
|
|
|
AddArg(V.getFloatValue());
|
|
|
|
else
|
|
|
|
AddArg("<unknown>");
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Hexadecimal printing for numbers too large for Printf to handle directly.
|
2016-11-08 23:04:09 +01:00
|
|
|
static void RenderHex(InternalScopedString *Buffer, UIntMax Val) {
|
2013-08-30 18:12:58 +02:00
|
|
|
#if HAVE_INT128_T
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer->append("0x%08x%08x%08x%08x", (unsigned int)(Val >> 96),
|
|
|
|
(unsigned int)(Val >> 64), (unsigned int)(Val >> 32),
|
|
|
|
(unsigned int)(Val));
|
2013-08-30 18:12:58 +02:00
|
|
|
#else
|
|
|
|
UNREACHABLE("long long smaller than 64 bits?");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
static void RenderLocation(InternalScopedString *Buffer, Location Loc) {
|
2013-08-30 18:12:58 +02:00
|
|
|
switch (Loc.getKind()) {
|
|
|
|
case Location::LK_Source: {
|
|
|
|
SourceLocation SLoc = Loc.getSourceLocation();
|
|
|
|
if (SLoc.isInvalid())
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer->append("<unknown>");
|
2013-12-05 10:18:38 +01:00
|
|
|
else
|
2016-11-08 23:04:09 +01:00
|
|
|
RenderSourceLocation(Buffer, SLoc.getFilename(), SLoc.getLine(),
|
2015-10-21 09:32:45 +02:00
|
|
|
SLoc.getColumn(), common_flags()->symbolize_vs_style,
|
|
|
|
common_flags()->strip_path_prefix);
|
2016-11-08 23:04:09 +01:00
|
|
|
return;
|
2014-11-13 21:41:38 +01:00
|
|
|
}
|
2013-08-30 18:12:58 +02:00
|
|
|
case Location::LK_Memory:
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer->append("%p", Loc.getMemoryLocation());
|
|
|
|
return;
|
2015-10-21 09:32:45 +02:00
|
|
|
case Location::LK_Symbolized: {
|
|
|
|
const AddressInfo &Info = Loc.getSymbolizedStack()->info;
|
2016-11-08 23:04:09 +01:00
|
|
|
if (Info.file)
|
|
|
|
RenderSourceLocation(Buffer, Info.file, Info.line, Info.column,
|
2015-10-21 09:32:45 +02:00
|
|
|
common_flags()->symbolize_vs_style,
|
|
|
|
common_flags()->strip_path_prefix);
|
2016-11-08 23:04:09 +01:00
|
|
|
else if (Info.module)
|
|
|
|
RenderModuleLocation(Buffer, Info.module, Info.module_offset,
|
2015-10-21 09:32:45 +02:00
|
|
|
common_flags()->strip_path_prefix);
|
2016-11-08 23:04:09 +01:00
|
|
|
else
|
|
|
|
Buffer->append("%p", Info.address);
|
|
|
|
return;
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
2013-08-30 18:12:58 +02:00
|
|
|
case Location::LK_Null:
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer->append("<unknown>");
|
|
|
|
return;
|
2013-08-30 18:12:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
static void RenderText(InternalScopedString *Buffer, const char *Message,
|
|
|
|
const Diag::Arg *Args) {
|
2013-08-30 18:12:58 +02:00
|
|
|
for (const char *Msg = Message; *Msg; ++Msg) {
|
|
|
|
if (*Msg != '%') {
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer->append("%c", *Msg);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const Diag::Arg &A = Args[*++Msg - '0'];
|
|
|
|
switch (A.Kind) {
|
|
|
|
case Diag::AK_String:
|
|
|
|
Buffer->append("%s", A.String);
|
|
|
|
break;
|
|
|
|
case Diag::AK_TypeName: {
|
|
|
|
if (SANITIZER_WINDOWS)
|
|
|
|
// The Windows implementation demangles names early.
|
|
|
|
Buffer->append("'%s'", A.String);
|
|
|
|
else
|
|
|
|
Buffer->append("'%s'", Symbolizer::GetOrInit()->Demangle(A.String));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Diag::AK_SInt:
|
|
|
|
// 'long long' is guaranteed to be at least 64 bits wide.
|
|
|
|
if (A.SInt >= INT64_MIN && A.SInt <= INT64_MAX)
|
|
|
|
Buffer->append("%lld", (long long)A.SInt);
|
|
|
|
else
|
|
|
|
RenderHex(Buffer, A.SInt);
|
|
|
|
break;
|
|
|
|
case Diag::AK_UInt:
|
|
|
|
if (A.UInt <= UINT64_MAX)
|
|
|
|
Buffer->append("%llu", (unsigned long long)A.UInt);
|
|
|
|
else
|
|
|
|
RenderHex(Buffer, A.UInt);
|
|
|
|
break;
|
|
|
|
case Diag::AK_Float: {
|
|
|
|
// FIXME: Support floating-point formatting in sanitizer_common's
|
|
|
|
// printf, and stop using snprintf here.
|
|
|
|
char FloatBuffer[32];
|
2015-10-21 09:32:45 +02:00
|
|
|
#if SANITIZER_WINDOWS
|
2016-11-08 23:04:09 +01:00
|
|
|
sprintf_s(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
|
2015-10-21 09:32:45 +02:00
|
|
|
#else
|
2016-11-08 23:04:09 +01:00
|
|
|
snprintf(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer->append("%s", FloatBuffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Diag::AK_Pointer:
|
|
|
|
Buffer->append("%p", A.Pointer);
|
|
|
|
break;
|
2013-08-30 18:12:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Find the earliest-starting range in Ranges which ends after Loc.
|
|
|
|
static Range *upperBound(MemoryLocation Loc, Range *Ranges,
|
|
|
|
unsigned NumRanges) {
|
|
|
|
Range *Best = 0;
|
|
|
|
for (unsigned I = 0; I != NumRanges; ++I)
|
|
|
|
if (Ranges[I].getEnd().getMemoryLocation() > Loc &&
|
|
|
|
(!Best ||
|
|
|
|
Best->getStart().getMemoryLocation() >
|
|
|
|
Ranges[I].getStart().getMemoryLocation()))
|
|
|
|
Best = &Ranges[I];
|
|
|
|
return Best;
|
|
|
|
}
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
static inline uptr subtractNoOverflow(uptr LHS, uptr RHS) {
|
|
|
|
return (LHS < RHS) ? 0 : LHS - RHS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uptr addNoOverflow(uptr LHS, uptr RHS) {
|
|
|
|
const uptr Limit = (uptr)-1;
|
|
|
|
return (LHS > Limit - RHS) ? Limit : LHS + RHS;
|
|
|
|
}
|
|
|
|
|
2013-08-30 18:12:58 +02:00
|
|
|
/// Render a snippet of the address space near a location.
|
2016-11-08 23:04:09 +01:00
|
|
|
static void PrintMemorySnippet(const Decorator &Decor, MemoryLocation Loc,
|
|
|
|
Range *Ranges, unsigned NumRanges,
|
|
|
|
const Diag::Arg *Args) {
|
2013-08-30 18:12:58 +02:00
|
|
|
// Show at least the 8 bytes surrounding Loc.
|
2014-09-23 19:59:53 +02:00
|
|
|
const unsigned MinBytesNearLoc = 4;
|
|
|
|
MemoryLocation Min = subtractNoOverflow(Loc, MinBytesNearLoc);
|
|
|
|
MemoryLocation Max = addNoOverflow(Loc, MinBytesNearLoc);
|
|
|
|
MemoryLocation OrigMin = Min;
|
2013-08-30 18:12:58 +02:00
|
|
|
for (unsigned I = 0; I < NumRanges; ++I) {
|
|
|
|
Min = __sanitizer::Min(Ranges[I].getStart().getMemoryLocation(), Min);
|
|
|
|
Max = __sanitizer::Max(Ranges[I].getEnd().getMemoryLocation(), Max);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have too many interesting bytes, prefer to show bytes after Loc.
|
2014-09-23 19:59:53 +02:00
|
|
|
const unsigned BytesToShow = 32;
|
2013-08-30 18:12:58 +02:00
|
|
|
if (Max - Min > BytesToShow)
|
2014-09-23 19:59:53 +02:00
|
|
|
Min = __sanitizer::Min(Max - BytesToShow, OrigMin);
|
|
|
|
Max = addNoOverflow(Min, BytesToShow);
|
|
|
|
|
|
|
|
if (!IsAccessibleMemoryRange(Min, Max - Min)) {
|
|
|
|
Printf("<memory cannot be printed>\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-08-30 18:12:58 +02:00
|
|
|
|
|
|
|
// Emit data.
|
2016-11-08 23:04:09 +01:00
|
|
|
InternalScopedString Buffer(1024);
|
2013-08-30 18:12:58 +02:00
|
|
|
for (uptr P = Min; P != Max; ++P) {
|
|
|
|
unsigned char C = *reinterpret_cast<const unsigned char*>(P);
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append("%s%02x", (P % 8 == 0) ? " " : " ", C);
|
2013-08-30 18:12:58 +02:00
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append("\n");
|
2013-08-30 18:12:58 +02:00
|
|
|
|
|
|
|
// Emit highlights.
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append(Decor.Highlight());
|
2013-08-30 18:12:58 +02:00
|
|
|
Range *InRange = upperBound(Min, Ranges, NumRanges);
|
|
|
|
for (uptr P = Min; P != Max; ++P) {
|
|
|
|
char Pad = ' ', Byte = ' ';
|
|
|
|
if (InRange && InRange->getEnd().getMemoryLocation() == P)
|
|
|
|
InRange = upperBound(P, Ranges, NumRanges);
|
|
|
|
if (!InRange && P > Loc)
|
|
|
|
break;
|
|
|
|
if (InRange && InRange->getStart().getMemoryLocation() < P)
|
|
|
|
Pad = '~';
|
|
|
|
if (InRange && InRange->getStart().getMemoryLocation() <= P)
|
|
|
|
Byte = '~';
|
2016-11-08 23:04:09 +01:00
|
|
|
if (P % 8 == 0)
|
|
|
|
Buffer.append("%c", Pad);
|
|
|
|
Buffer.append("%c", Pad);
|
|
|
|
Buffer.append("%c", P == Loc ? '^' : Byte);
|
|
|
|
Buffer.append("%c", Byte);
|
2013-08-30 18:12:58 +02:00
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append("%s\n", Decor.EndHighlight());
|
2013-08-30 18:12:58 +02:00
|
|
|
|
|
|
|
// Go over the line again, and print names for the ranges.
|
|
|
|
InRange = 0;
|
|
|
|
unsigned Spaces = 0;
|
|
|
|
for (uptr P = Min; P != Max; ++P) {
|
|
|
|
if (!InRange || InRange->getEnd().getMemoryLocation() == P)
|
|
|
|
InRange = upperBound(P, Ranges, NumRanges);
|
|
|
|
if (!InRange)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Spaces += (P % 8) == 0 ? 2 : 1;
|
|
|
|
|
|
|
|
if (InRange && InRange->getStart().getMemoryLocation() == P) {
|
|
|
|
while (Spaces--)
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append(" ");
|
|
|
|
RenderText(&Buffer, InRange->getText(), Args);
|
|
|
|
Buffer.append("\n");
|
2013-08-30 18:12:58 +02:00
|
|
|
// FIXME: We only support naming one range for now!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Spaces += 2;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
Printf("%s", Buffer.data());
|
2013-08-30 18:12:58 +02:00
|
|
|
// FIXME: Print names for anything we can identify within the line:
|
|
|
|
//
|
|
|
|
// * If we can identify the memory itself as belonging to a particular
|
|
|
|
// global, stack variable, or dynamic allocation, then do so.
|
|
|
|
//
|
|
|
|
// * If we have a pointer-size, pointer-aligned range highlighted,
|
|
|
|
// determine whether the value of that range is a pointer to an
|
|
|
|
// entity which we can name, and if so, print that name.
|
|
|
|
//
|
|
|
|
// This needs an external symbolizer, or (preferably) ASan instrumentation.
|
|
|
|
}
|
|
|
|
|
|
|
|
Diag::~Diag() {
|
2014-09-23 19:59:53 +02:00
|
|
|
// All diagnostics should be printed under report mutex.
|
|
|
|
CommonSanitizerReportMutex.CheckLocked();
|
|
|
|
Decorator Decor;
|
2016-11-08 23:04:09 +01:00
|
|
|
InternalScopedString Buffer(1024);
|
2013-08-30 18:12:58 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append(Decor.Bold());
|
|
|
|
RenderLocation(&Buffer, Loc);
|
|
|
|
Buffer.append(":");
|
2013-08-30 18:12:58 +02:00
|
|
|
|
|
|
|
switch (Level) {
|
|
|
|
case DL_Error:
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append("%s runtime error: %s%s", Decor.Warning(), Decor.EndWarning(),
|
|
|
|
Decor.Bold());
|
2013-08-30 18:12:58 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DL_Note:
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append("%s note: %s", Decor.Note(), Decor.EndNote());
|
2013-08-30 18:12:58 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
RenderText(&Buffer, Message, Args);
|
2013-08-30 18:12:58 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
Buffer.append("%s\n", Decor.Default());
|
|
|
|
Printf("%s", Buffer.data());
|
2013-08-30 18:12:58 +02:00
|
|
|
|
|
|
|
if (Loc.isMemoryLocation())
|
2016-11-08 23:04:09 +01:00
|
|
|
PrintMemorySnippet(Decor, Loc.getMemoryLocation(), Ranges, NumRanges, Args);
|
2013-08-30 18:12:58 +02:00
|
|
|
}
|
2014-09-23 19:59:53 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc,
|
|
|
|
ErrorType Type)
|
|
|
|
: Opts(Opts), SummaryLoc(SummaryLoc), Type(Type) {
|
|
|
|
InitAsStandaloneIfNecessary();
|
2014-09-23 19:59:53 +02:00
|
|
|
CommonSanitizerReportMutex.Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedReport::~ScopedReport() {
|
|
|
|
MaybePrintStackTrace(Opts.pc, Opts.bp);
|
2015-10-21 09:32:45 +02:00
|
|
|
MaybeReportErrorSummary(SummaryLoc, Type);
|
2014-09-23 19:59:53 +02:00
|
|
|
CommonSanitizerReportMutex.Unlock();
|
2016-11-08 23:04:09 +01:00
|
|
|
if (flags()->halt_on_error)
|
2014-09-23 19:59:53 +02:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
|
|
|
|
static SuppressionContext *suppression_ctx = nullptr;
|
|
|
|
static const char kVptrCheck[] = "vptr_check";
|
2016-11-08 23:04:09 +01:00
|
|
|
static const char *kSuppressionTypes[] = {
|
|
|
|
#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName) FSanitizeFlagName,
|
|
|
|
#include "ubsan_checks.inc"
|
|
|
|
#undef UBSAN_CHECK
|
|
|
|
kVptrCheck,
|
|
|
|
};
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
void __ubsan::InitializeSuppressions() {
|
|
|
|
CHECK_EQ(nullptr, suppression_ctx);
|
|
|
|
suppression_ctx = new (suppression_placeholder) // NOLINT
|
|
|
|
SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
|
|
|
|
suppression_ctx->ParseFromFile(flags()->suppressions);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool __ubsan::IsVptrCheckSuppressed(const char *TypeName) {
|
|
|
|
InitAsStandaloneIfNecessary();
|
|
|
|
CHECK(suppression_ctx);
|
2014-09-23 19:59:53 +02:00
|
|
|
Suppression *s;
|
2015-10-21 09:32:45 +02:00
|
|
|
return suppression_ctx->Match(TypeName, kVptrCheck, &s);
|
2014-09-23 19:59:53 +02:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
bool __ubsan::IsPCSuppressed(ErrorType ET, uptr PC, const char *Filename) {
|
|
|
|
InitAsStandaloneIfNecessary();
|
|
|
|
CHECK(suppression_ctx);
|
|
|
|
const char *SuppType = ConvertTypeToFlagName(ET);
|
|
|
|
// Fast path: don't symbolize PC if there is no suppressions for given UB
|
|
|
|
// type.
|
|
|
|
if (!suppression_ctx->HasSuppressionType(SuppType))
|
|
|
|
return false;
|
|
|
|
Suppression *s = nullptr;
|
|
|
|
// Suppress by file name known to runtime.
|
|
|
|
if (Filename != nullptr && suppression_ctx->Match(Filename, SuppType, &s))
|
|
|
|
return true;
|
|
|
|
// Suppress by module name.
|
|
|
|
if (const char *Module = Symbolizer::GetOrInit()->GetModuleNameForPc(PC)) {
|
|
|
|
if (suppression_ctx->Match(Module, SuppType, &s))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Suppress by function or source file name from debug info.
|
|
|
|
SymbolizedStackHolder Stack(Symbolizer::GetOrInit()->SymbolizePC(PC));
|
|
|
|
const AddressInfo &AI = Stack.get()->info;
|
|
|
|
return suppression_ctx->Match(AI.function, SuppType, &s) ||
|
|
|
|
suppression_ctx->Match(AI.file, SuppType, &s);
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif // CAN_SANITIZE_UB
|