I just tripped over a segfault in libbacktrace. We apply strrchr to a possibly NULL filename, with predictable results when it is.

elf.c:3044 passes NULL as the filename parm:
          ret = elf_add (state, NULL, d, base_address, error_callback, data,
                         fileline_fn, found_sym, found_dwarf, NULL, 0, 1, NULL,
                         0);

This gets to elf_open_debugfile_by_debuglink which passes it on through:
  ddescriptor = elf_find_debugfile_by_debuglink (state, filename,
                                                 debuglink_name,
                                                 error_callback, data);

this patch avoids the strrchr when filename is null. I reordered the way prefix & prefix len got set, finding it prefereable to:
  slash  = filename ? NULL : strrchr (filename, '/');
but if you prefer to avoid the assignment in the conditional I'm fine with that too.

ok?

nathan

--
Nathan Sidwell
2019-01-24  Nathan Sidwell  <nat...@acm.org>

	* elf.c (elf_find_debugfile_by_debuglink): Protect against
	FILENAME being NULL.

Index: libbacktrace/elf.c
===================================================================
--- libbacktrace/elf.c	(revision 268252)
+++ libbacktrace/elf.c	(working copy)
@@ -970,13 +970,9 @@ elf_find_debugfile_by_debuglink (struct
 
   /* Look for DEBUGLINK_NAME in the same directory as FILENAME.  */
 
-  slash = strrchr (filename, '/');
-  if (slash == NULL)
-    {
-      prefix = "";
-      prefix_len = 0;
-    }
-  else
+  prefix = "";
+  prefix_len = 0;
+  if (filename && (slash = strrchr (filename, '/') != NULL)
     {
       slash++;
       prefix = filename;

Reply via email to