[backtrace] Avoid segfault

Nathan Sidwell nathan@acm.org
Fri Jan 25 00:15:00 GMT 2019


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace.diff
Type: text/x-patch
Size: 704 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190125/0c3162da/attachment.bin>


More information about the Gcc-patches mailing list