forked from espressif/esp-idf
elf: Fix for mismatched app ELF file not detected.
The check that the app ELF file SHA256 matches the one stored in the core dump would never fail, leading to gdb loading the wrong ELF file and either crashing or producing misleading debug information. Specifics: The note_sec.name field was incorrectly read back as b'ESP_CORE_DUMP_INFO\x00E', because the namesz length includes the terminating NUL byte and possible junk padding bytes: https://github.com/espressif/esp-idf/blob/master/components/espcoredump/src/core_dump_elf.c#L212 In addition, as 'note_sec.name' is a bytes object Python 3 would have never successfully compared it with a string.
This commit is contained in:
@@ -284,6 +284,13 @@ class ElfNoteSegment(ElfSegment):
|
||||
super(ElfNoteSegment, self).__init__(addr, data, flags)
|
||||
self.type = ElfFile.PT_NOTE
|
||||
self.note_secs = NoteSections.parse(self.data)
|
||||
for note in self.note_secs:
|
||||
# note.name should include a terminating NUL byte, plus possible
|
||||
# padding
|
||||
#
|
||||
# (note: construct.PaddingString can't parse this if there
|
||||
# are non-zero padding bytes after the NUL, it also parses those.)
|
||||
note.name = note.name.split(b'\x00')[0]
|
||||
|
||||
@staticmethod
|
||||
def _type_str(): # type: () -> str
|
||||
|
@@ -261,7 +261,7 @@ class EspCoreDumpLoader(EspCoreDumpVersion):
|
||||
for seg in core_elf.note_segments:
|
||||
for note_sec in seg.note_secs:
|
||||
# Check for version info note
|
||||
if note_sec.name == 'ESP_CORE_DUMP_INFO' \
|
||||
if note_sec.name == b'ESP_CORE_DUMP_INFO' \
|
||||
and note_sec.type == ESPCoreDumpElfFile.PT_INFO \
|
||||
and exe_name:
|
||||
exe_elf = ElfFile(exe_name)
|
||||
|
Reference in New Issue
Block a user