From 5f4b151876a4c0222c9845c3430d242a65a33401 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 (a cherry-pick of commit 18fda2a1 from 'release-7_4') * 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 | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/os_dep.c b/os_dep.c index ad7d5f39..f51a61d2 100644 --- a/os_dep.c +++ b/os_dep.c @@ -4726,13 +4726,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 && nl < 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.40.0