]> granicus.if.org Git - gc/commitdiff
Fix 'pointer arithmetic with NULL' code defect in print_callers
authorIvan Maidanski <ivmai@mail.ru>
Wed, 11 Jul 2018 06:07:30 +0000 (09:07 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 19 Jul 2018 06:45:14 +0000 (09:45 +0300)
(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

index ad7d5f39fe870f8b0fa715e7a85122f9a58a1e71..f51a61d2f958d07c109f7fbb5720bc47b0655240 100644 (file)
--- 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 */