Skip to content

Commit

Permalink
No crash on note with zero length name (#592)
Browse files Browse the repository at this point in the history
* No crash on note with zero length name

* Comment placement
  • Loading branch information
sevaa authored Jan 14, 2025
1 parent 12034a5 commit a916fe5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions elftools/elf/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ def iter_notes(elffile, offset, size):
note['n_offset'] = offset
offset += nhdr_size
elffile.stream.seek(offset)
# n_namesz is 4-byte aligned.
disk_namesz = roundup(note['n_namesz'], 2)
note['n_name'] = bytes2str(
CString('').parse(elffile.stream.read(disk_namesz)))
offset += disk_namesz
if note['n_namesz']:
# n_namesz is 4-byte aligned.
disk_namesz = roundup(note['n_namesz'], 2)
note['n_name'] = bytes2str(
CString('').parse(elffile.stream.read(disk_namesz)))
offset += disk_namesz
else:
note['n_name'] = None

desc_data = elffile.stream.read(note['n_descsz'])
note['n_descdata'] = desc_data
Expand Down

0 comments on commit a916fe5

Please sign in to comment.