forked from OSchip/llvm-project
[asan] don't return from a never-return function. fix a test that had a chain of bugs instead of just one
llvm-svn: 160719
This commit is contained in:
parent
c145b02607
commit
bb0ade6daa
|
@ -387,9 +387,15 @@ void NOINLINE __asan_set_error_report_callback(void (*callback)(const char*)) {
|
|||
|
||||
void __asan_report_error(uptr pc, uptr bp, uptr sp,
|
||||
uptr addr, bool is_write, uptr access_size) {
|
||||
// Do not print more than one report, otherwise they will mix up.
|
||||
static atomic_uint32_t num_calls;
|
||||
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) return;
|
||||
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
|
||||
// Do not print more than one report, otherwise they will mix up.
|
||||
// We can not return here because the function is marked as never-return.
|
||||
AsanPrintf("AddressSanitizer: while reporting a bug found another one."
|
||||
"Ignoring.\n");
|
||||
SleepForSeconds(5);
|
||||
Die();
|
||||
}
|
||||
|
||||
AsanPrintf("===================================================="
|
||||
"=============\n");
|
||||
|
|
|
@ -670,20 +670,12 @@ TEST(AddressSanitizerInterface, DISABLED_InvalidPoisonAndUnpoisonCallsTest) {
|
|||
}
|
||||
|
||||
static void ErrorReportCallbackOneToZ(const char *report) {
|
||||
int len = strlen(report);
|
||||
char *dup = (char*)malloc(len);
|
||||
strcpy(dup, report);
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (dup[i] == '1') dup[i] = 'Z';
|
||||
}
|
||||
int written = write(2, dup, len);
|
||||
ASSERT_EQ(len, written);
|
||||
free(dup);
|
||||
write(2, "ABCDEF", 6);
|
||||
}
|
||||
|
||||
TEST(AddressSanitizerInterface, SetErrorReportCallbackTest) {
|
||||
__asan_set_error_report_callback(ErrorReportCallbackOneToZ);
|
||||
EXPECT_DEATH(__asan_report_error(0, 0, 0, 0, true, 1), "size Z");
|
||||
EXPECT_DEATH(__asan_report_error(0, 0, 0, 0, true, 1), "ABCDEF");
|
||||
__asan_set_error_report_callback(NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue