From 05160258df8a4e34f323b2c6eb1f2c0f59591d05 Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Wed, 3 Jan 2024 11:59:02 -0800 Subject: [PATCH] When safety_check_fail, also embed hint msg in the abort function name because there are cases only logging crash stack traces. --- src/safety_check.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/safety_check.c b/src/safety_check.c index 7ffe1f4f..d3f68fbc 100644 --- a/src/safety_check.c +++ b/src/safety_check.c @@ -20,6 +20,20 @@ void safety_check_set_abort(safety_check_abort_hook_t abort_fn) { safety_check_abort = abort_fn; } +/* + * In addition to malloc_write, also embed hint msg in the abort function name + * because there are cases only logging crash stack traces. + */ +static void +safety_check_detected_heap_corruption___run_address_sanitizer_build_to_debug(const char *buf) { + if (safety_check_abort == NULL) { + malloc_write(buf); + abort(); + } else { + safety_check_abort(buf); + } +} + void safety_check_fail(const char *format, ...) { char buf[MALLOC_PRINTF_BUFSIZE]; @@ -28,10 +42,5 @@ void safety_check_fail(const char *format, ...) { malloc_vsnprintf(buf, MALLOC_PRINTF_BUFSIZE, format, ap); va_end(ap); - if (safety_check_abort == NULL) { - malloc_write(buf); - abort(); - } else { - safety_check_abort(buf); - } + safety_check_detected_heap_corruption___run_address_sanitizer_build_to_debug(buf); }