Skip to content

Commit b16672d

Browse files
committedAug 31, 2016
Reify ErrorDoubleFree
Summary: Keep reifying other errors. Reviewers: kcc, samsonov Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23717 llvm-svn: 280201
1 parent 2c07a06 commit b16672d

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed
 

‎compiler-rt/lib/asan/asan_errors.cc

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "asan_errors.h"
16+
#include "asan_descriptions.h"
1617
#include "asan_stack.h"
1718

1819
namespace __asan {
@@ -33,4 +34,21 @@ void ErrorStackOverflow::Print() {
3334
ReportErrorSummary("stack-overflow", &stack);
3435
}
3536

37+
void ErrorDoubleFree::Print() {
38+
Decorator d;
39+
Printf("%s", d.Warning());
40+
char tname[128];
41+
Report(
42+
"ERROR: AddressSanitizer: attempting double-free on %p in "
43+
"thread T%d%s:\n",
44+
addr_description.addr, tid,
45+
ThreadNameWithParenthesis(tid, tname, sizeof(tname)));
46+
Printf("%s", d.EndWarning());
47+
GET_STACK_TRACE_FATAL(second_free_stack->trace[0],
48+
second_free_stack->top_frame_bp);
49+
stack.Print();
50+
addr_description.Print();
51+
ReportErrorSummary("double-free", &stack);
52+
}
53+
3654
} // namespace __asan

‎compiler-rt/lib/asan/asan_errors.h

+25
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,27 @@ struct ErrorStackOverflow : ErrorBase {
4444
void Print();
4545
};
4646

47+
struct ErrorDoubleFree : ErrorBase {
48+
u32 tid;
49+
HeapAddressDescription addr_description;
50+
// ErrorDoubleFree doesn't own the stack trace.
51+
BufferedStackTrace *second_free_stack;
52+
// VS2013 doesn't implement unrestricted unions, so we need a trivial default
53+
// constructor
54+
ErrorDoubleFree() = default;
55+
ErrorDoubleFree(uptr addr, u32 tid_, BufferedStackTrace *stack)
56+
: tid(tid_), second_free_stack(stack) {
57+
CHECK_GT(second_free_stack->size, 0);
58+
GetHeapAddressInformation(addr, 1, &addr_description);
59+
scariness.Scare(42, "double-free");
60+
}
61+
void Print();
62+
};
63+
4764
enum ErrorKind {
4865
kErrorKindInvalid = 0,
4966
kErrorKindStackOverflow,
67+
kErrorKindDoubleFree,
5068
};
5169

5270
struct ErrorDescription {
@@ -58,18 +76,25 @@ struct ErrorDescription {
5876
// add a lot of code and the benefit wouldn't be that big.
5977
union {
6078
ErrorStackOverflow stack_overflow;
79+
ErrorDoubleFree double_free;
6180
};
6281
ErrorDescription() { internal_memset(this, 0, sizeof(*this)); }
6382
ErrorDescription(const ErrorStackOverflow &e) // NOLINT
6483
: kind(kErrorKindStackOverflow),
6584
stack_overflow(e) {}
85+
ErrorDescription(const ErrorDoubleFree &e) // NOLINT
86+
: kind(kErrorKindDoubleFree),
87+
double_free(e) {}
6688

6789
bool IsValid() { return kind != kErrorKindInvalid; }
6890
void Print() {
6991
switch (kind) {
7092
case kErrorKindStackOverflow:
7193
stack_overflow.Print();
7294
return;
95+
case kErrorKindDoubleFree:
96+
double_free.Print();
97+
return;
7398
case kErrorKindInvalid:
7499
CHECK(0);
75100
}

‎compiler-rt/lib/asan/asan_report.cc

+2-15
Original file line numberDiff line numberDiff line change
@@ -388,21 +388,8 @@ void ReportDeadlySignal(const char *description, const SignalContext &sig) {
388388

389389
void ReportDoubleFree(uptr addr, BufferedStackTrace *free_stack) {
390390
ScopedInErrorReport in_report;
391-
Decorator d;
392-
Printf("%s", d.Warning());
393-
char tname[128];
394-
u32 curr_tid = GetCurrentTidOrInvalid();
395-
Report("ERROR: AddressSanitizer: attempting double-free on %p in "
396-
"thread T%d%s:\n",
397-
addr, curr_tid,
398-
ThreadNameWithParenthesis(curr_tid, tname, sizeof(tname)));
399-
Printf("%s", d.EndWarning());
400-
CHECK_GT(free_stack->size, 0);
401-
ScarinessScore::PrintSimple(42, "double-free");
402-
GET_STACK_TRACE_FATAL(free_stack->trace[0], free_stack->top_frame_bp);
403-
stack.Print();
404-
DescribeAddressIfHeap(addr);
405-
ReportErrorSummary("double-free", &stack);
391+
ErrorDoubleFree error{addr, GetCurrentTidOrInvalid(), free_stack}; // NOLINT
392+
in_report.ReportError(error);
406393
}
407394

408395
void ReportNewDeleteSizeMismatch(uptr addr, uptr alloc_size, uptr delete_size,

0 commit comments

Comments
 (0)
Please sign in to comment.