public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [backtrace] Avoid segfault
@ 2019-01-25  0:15 Nathan Sidwell
  2019-01-25  1:49 ` Ian Lance Taylor
  0 siblings, 1 reply; 24+ messages in thread
From: Nathan Sidwell @ 2019-01-25  0:15 UTC (permalink / raw)
  To: GCC Patches, Ian Lance Taylor

[-- Attachment #1: Type: text/plain, Size: 816 bytes --]

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

[-- Attachment #2: backtrace.diff --]
[-- Type: text/x-patch, Size: 704 bytes --]

2019-01-24  Nathan Sidwell  <nathan@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;

^ permalink raw reply	[flat|nested] 24+ messages in thread
* Re: [backtrace] Avoid segfault
@ 2019-02-25 15:14 Gerald Pfeifer
  2019-02-25 21:49 ` Tom de Vries
  0 siblings, 1 reply; 24+ messages in thread
From: Gerald Pfeifer @ 2019-02-25 15:14 UTC (permalink / raw)
  To: Tom de Vries, gcc-patches; +Cc: Ian Lance Taylor, Nathan Sidwell

Hi Tom,

I'm afraid this triggers on my (FreeBSD-based) testers:

  2019-01-29  Tom de Vries  <tdevries@suse.de>

        * install-debuginfo-for-buildid.sh.in: New script.
        * Makefile.am (check_PROGRAMS): Add b2test and b3test.
        (TESTS): Add b2test_buildid and b3test_dwz_buildid.
        * Makefile.in: Regenerate.
        * configure.ac (HAVE_ELF): Set with AM_CONDITIONAL.
        (READELF): Set with AC_CHECK_PROG.
        (install-debuginfo-for-buildid.sh): Generate with AC_CONFIG_FILES.
        * configure: Regenerate.
        * elf.c (SYSTEM_BUILD_ID_DIR): Factor out of ...
        (elf_open_debugfile_by_buildid): ... here.

Specifically I am now seeing

  gmake[4]: *** No rule to make target 'b3test_dwz_buildid', 
  needed by 'b3test_dwz_buildid.log'.

in my build/test logs.  (Note, this is GNU make 4.2.1, so might reproduce 
on your SUSE systems as well?)

Gerald

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2019-02-26 20:48 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25  0:15 [backtrace] Avoid segfault Nathan Sidwell
2019-01-25  1:49 ` Ian Lance Taylor
2019-01-25 13:23   ` Tom de Vries
2019-01-25 14:10     ` Tom de Vries
2019-01-25 14:31       ` Ian Lance Taylor
2019-01-25 17:20       ` Nathan Sidwell
2019-01-25 17:31         ` Marek Polacek
2019-01-27 21:53         ` Tom de Vries
2019-01-28  1:39           ` Ian Lance Taylor
2019-01-28  9:35             ` [libbacktrace] Fix and simplify xcoff_%.c pattern rule Tom de Vries
2019-01-28 11:31               ` [libbacktrace] Add gen-xcoff-n.sh Tom de Vries
2019-01-28 22:29                 ` Ian Lance Taylor
2019-01-28 18:43               ` [libbacktrace] Fix and simplify xcoff_%.c pattern rule Ian Lance Taylor
2019-01-29  8:52             ` [backtrace] Avoid segfault Tom de Vries
2019-01-29 15:29               ` Ian Lance Taylor
2019-01-29 23:53             ` Segher Boessenkool
2019-01-30  2:21               ` Ian Lance Taylor
2019-01-28 23:19           ` [libbacktrace] Don't assign check_PROGRAMS to TESTS Tom de Vries
2019-01-29  1:08             ` Ian Lance Taylor
2019-01-25 14:23     ` [backtrace] Avoid segfault Ian Lance Taylor
2019-02-25 15:14 Gerald Pfeifer
2019-02-25 21:49 ` Tom de Vries
2019-02-26  8:37   ` Tom de Vries
2019-02-26 21:08     ` Gerald Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).