]> git.ipfire.org Git - thirdparty/elfutils.git/commit
elf_newdata: Make sure to set d_type to ELF_T_BYTE and d_align to one
authorMark Wielaard <mark@klomp.org>
Mon, 13 Apr 2026 12:29:27 +0000 (14:29 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 14 Apr 2026 00:06:49 +0000 (02:06 +0200)
commit7369e7d9f1711bb0ffdb9710665b84aa756dbcc2
tree78f924febb028535fa5ce3358a4e6d1837cfba3f
parent51d8c2d950c8dc2c3de572dc283a5046f901e8f4
elf_newdata: Make sure to set d_type to ELF_T_BYTE and d_align to one

If d_align isn't explicitly set in elf_newdata it will default to
zero. This confuses elf_update when more than one Elf_Data has been
added to a (new) Elf_Section. Only the last will appear to be added.
ELF_T_BYTE happens to be zero and so d_type did appear to be setup
correctly. Also set it explicitly to show the defaults.

The elf_newdata test happened to pass because it set d_align to 1
explicitly. But would fail if it wouldn't set it. Add some extra
checks.

Also update the elf_newdata man page with the new defaults.

* libelf/elf_newdata.c (elf_newdata): Explicitly set d_type
and d_align.
* tests/newdata.c (add_section_data): Check d_buf, d_size,
d_type, d_align and d_version default values.
* doc/elf_newdata.3: Document d_align defaults to one.

Signed-off-by: Mark Wielaard <mark@klomp.org>
doc/elf_newdata.3
libelf/elf_newdata.c
tests/newdata.c