Summary: | readelf -wf segfaults on most (all?) debug info files | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Mark Johnston <markj> | ||||||
Component: | bin | Assignee: | Mark Johnston <markj> | ||||||
Status: | Closed FIXED | ||||||||
Severity: | Affects Only Me | CC: | emaste, me | ||||||
Priority: | --- | Keywords: | patch | ||||||
Version: | CURRENT | ||||||||
Hardware: | Any | ||||||||
OS: | Any | ||||||||
Attachments: |
|
Created attachment 206840 [details]
Proposed patch
Created attachment 206867 [details]
Robustness patch
Adding logic similar to the "robustness patch" I provided may be worthwhile. If another programmer using libdwarf makes a similar mistake, having it fail gracefully may be preferable over a segfault. For example, running readelf without the "proposed patch" would yield:
$ readelf -wf /usr/lib/debug/bin/cat.debug
The section .eh_frame contains:
Assertion failed: (ds->ds_data != NULL), function _dwarf_frame_section_init, file /usr/src/contrib/elftoolchain/libdwarf/libdwarf_frame.c, line 465.
Abort trap
$
(In reply to Paco Pascal from comment #2) My apologies for not following up sooner! I think you indeed found the root cause, thanks. Thinking about this some more, I suspect that libdwarf should be handling this case itself, rather than forcing it into consumers. I looked at SGI libdwarf, and it appears to handle this: dwarf_elf_object_access_load_section() looks for a NULL d_buf in the data descriptor of the target ELF section, which indicates that the section is SHT_NOBITS. I proposed a patch here: https://reviews.freebsd.org/D25626 (In reply to Mark Johnston from comment #3) You're welcome and thanks for the reference on the review! I agree. Not pushing this responsibility onto consumers is the better way to go. A commit references this bug: Author: markj Date: Mon Jul 20 18:22:38 UTC 2020 New revision: 363375 URL: https://svnweb.freebsd.org/changeset/base/363375 Log: libdwarf: Hide SHT_NOBITS sections. gnu_debuglink external debug files will contain an .eh_frame section of type SHT_NOBITS. libdwarf does not handle such sections (or rather, it expects all debug sections to not have type SHT_NOBITS). Avoid loading SHT_NOBITS sections, to be consistent with SGI libdwarf's handling of this case. PR: 239516 Diagnosed by: Paco Pascal <me@pacopascal.com> Reviewed by: emaste (previous version) Event: July 2020 Bugathon MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25626 Changes: head/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c A commit references this bug: Author: markj Date: Mon Jul 27 14:08:30 UTC 2020 New revision: 363600 URL: https://svnweb.freebsd.org/changeset/base/363600 Log: MFC r363375: libdwarf: Hide SHT_NOBITS sections. PR: 239516 Changes: _U stable/12/ stable/12/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c A commit references this bug: Author: markj Date: Mon Jul 27 14:09:38 UTC 2020 New revision: 363601 URL: https://svnweb.freebsd.org/changeset/base/363601 Log: MFC r363375: libdwarf: Hide SHT_NOBITS sections. PR: 239516 Changes: _U stable/11/ stable/11/contrib/elftoolchain/libdwarf/libdwarf_elf_init.c |
> readelf -wf /usr/lib/debug/bin/cat.debug The section .eh_frame contains: Segmentation fault (core dumped) >