From c88c621500984442369e0ae4ceeec54cfb9a6ce4 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 11 Jul 2018 09:07:30 +0300 Subject: [PATCH] Fix 'pointer arithmetic with NULL' code defect in print_callers * os_dep.c [NEED_CALLINFO && LINUX && !SMALL_CONFIG] (GC_print_callers): If nl is null then pass result_len (instead of nl-result_buf) to strncmp; adjust code indentation. --- os_dep.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/os_dep.c b/os_dep.c index 3a53195..a4b5e86 100644 --- a/os_dep.c +++ b/os_dep.c @@ -4801,14 +4801,16 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES]) } /* Get rid of embedded newline, if any. Test for "main" */ { - char * nl = strchr(result_buf, '\n'); - if (nl != NULL - && (word)nl < (word)(result_buf + result_len)) { - *nl = ':'; - } - if (strncmp(result_buf, "main", nl - result_buf) == 0) { - stop = TRUE; - } + char * nl = strchr(result_buf, '\n'); + if (nl != NULL + && (word)nl < (word)(result_buf + result_len)) { + *nl = ':'; + } + if (strncmp(result_buf, "main", + nl != NULL ? (size_t)(nl - result_buf) + : result_len) == 0) { + stop = TRUE; + } } if (result_len < RESULT_SZ - 25) { /* Add in hex address */ -- 2.7.4