]> git.ipfire.org Git - thirdparty/elfutils.git/commit
elf_getarhdr: Replace per-archive Elf_Arhdr storage with per-member storage main users/amerey/try-arhdr
authorAaron Merey <amerey@redhat.com>
Mon, 11 Aug 2025 00:26:35 +0000 (20:26 -0400)
committerAaron Merey <amerey@redhat.com>
Wed, 20 Aug 2025 14:26:25 +0000 (10:26 -0400)
commitcc459edfe10f2e76b82cccb8543c2f264f478209
treeee797c318a8d942a8f42e55ebb32f22fa9b052e3
parent36602dbd840532b9ca6d31c1612bf1d539241e7a
elf_getarhdr: Replace per-archive Elf_Arhdr storage with per-member storage

Currently each archive descriptor maintains a single Elf_Arhdr for the
current archive member (as determined by elf_next or elf_rand) which is
returned by elf_getarhdr.

A single per-archive Elf_Arhdr is not ideal since elf_next and elf_rand
can invalidate an archive member's reference to its own Elf_Arhdr.

Avoid this possible invalidation by storing each Elf_Arhdr in its
archive member descriptor.

The existing Elf_Arhdr parsing and storage in the archive descriptor
internal state is left mostly untouched.  When an archive member is
created with elf_begin it is given its own copy of its Elf_Arhdr from
the archive descriptor.

Also update tests/arextract.c with verification that each Elf_Arhdr
is distinct and remains valid after calls to elf_next that would
have previously invalidated the Elf_Arhdr.

Signed-off-by: Aaron Merey <amerey@redhat.com>
libelf/elf_begin.c
libelf/elf_end.c
libelf/elf_getarhdr.c
libelf/libelfP.h
tests/arextract.c