]> granicus.if.org Git - gc/commitdiff
Fix null dereference in print_callers on backtrace_symbols failure
authorIvan Maidanski <ivmai@mail.ru>
Fri, 6 Apr 2018 16:07:50 +0000 (19:07 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 16 Apr 2018 07:29:36 +0000 (10:29 +0300)
* os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE
&& !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): If sym_name is
NULL then print info[i].ci_pc to buf and set name to buf (instead of
to sym_name[0]).
* os_dep.c [NEED_CALLINFO && GC_HAVE_BUILTIN_BACKTRACE
&& !GC_BACKTRACE_SYMBOLS_BROKEN] (GC_print_callers): Do not call
free(sym_name) if sym_name is NULL.

os_dep.c

index a7533a997ab0ad3cfba07e2ffd7cffd9d440d9c3..7ae84d37c7bedc25c307cb28b11bf0dae2562488 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -4613,18 +4613,22 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES])
             continue;
         }
         {
+          char buf[40];
+          char *name;
 #         if defined(GC_HAVE_BUILTIN_BACKTRACE) \
              && !defined(GC_BACKTRACE_SYMBOLS_BROKEN)
             char **sym_name =
               backtrace_symbols((void **)(&(info[i].ci_pc)), 1);
-            char *name = sym_name[0];
-#         else
-            char buf[40];
-            char *name = buf;
+            if (sym_name != NULL) {
+              name = sym_name[0];
+            } else
+#         endif
+          /* else */ {
             (void)snprintf(buf, sizeof(buf), "##PC##= 0x%lx",
                            (unsigned long)info[i].ci_pc);
             buf[sizeof(buf) - 1] = '\0';
-#         endif
+            name = buf;
+          }
 #         if defined(LINUX) && !defined(SMALL_CONFIG)
             /* Try for a line number. */
             {
@@ -4718,7 +4722,8 @@ GC_INNER void GC_print_callers(struct callinfo info[NFRAMES])
           GC_err_printf("\t\t%s\n", name);
 #         if defined(GC_HAVE_BUILTIN_BACKTRACE) \
              && !defined(GC_BACKTRACE_SYMBOLS_BROKEN)
-            free(sym_name);  /* May call GC_[debug_]free; that's OK */
+            if (sym_name != NULL)
+              free(sym_name);   /* May call GC_[debug_]free; that's OK  */
 #         endif
         }
     }