Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

elf: fix parsing of notes after patchelf mangling #3111

Merged
merged 2 commits into from May 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions snapcraft/internal/elf.py
Expand Up @@ -298,8 +298,10 @@ def __init__(self, *, path: str) -> None:
self.elf_type: str = "ET_NONE"

try:
logger.debug("Extracting ELF attributes:", path)
self._extract_attributes()
except (UnicodeDecodeError, AttributeError, ConstructError) as exception:
logger.debug("Extracting ELF attributes exception: ", str(exception))
raise errors.CorruptedElfFileError(path, exception)

def _extract_attributes(self) -> None: # noqa: C901
Expand Down Expand Up @@ -335,10 +337,15 @@ def _extract_attributes(self) -> None: # noqa: C901
self.execstack_set = True
elif isinstance(segment, elftools.elf.segments.InterpSegment):
self.interp = segment.get_interp_name()
elif isinstance(segment, elftools.elf.segments.NoteSegment):
for note in segment.iter_notes():
if note.n_name == "GNU" and note.n_type == "NT_GNU_BUILD_ID":
self.build_id = _ensure_str(note.n_desc)

build_id_section = elf.get_section_by_name(".note.gnu.build-id")
if (
isinstance(build_id_section, elftools.elf.sections.NoteSection)
and build_id_section.header["sh_type"] != "SHT_NOBITS"
):
for note in build_id_section.iter_notes():
if note.n_name == "GNU" and note.n_type == "NT_GNU_BUILD_ID":
self.build_id = _ensure_str(note.n_desc)

# If we are processing a detached debug info file, these
# sections will be present but empty.
Expand Down