]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
libctf: allow ctf_arc_bufpreamble to fail users/nalcock/try-fix-ctf-archive-overrun
authorNick Alcock <nick.alcock@oracle.com>
Mon, 3 Nov 2025 17:15:32 +0000 (17:15 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Mon, 3 Nov 2025 19:45:16 +0000 (19:45 +0000)
commit0970b8c458a341d2bdfd88232159f4d08d2fea4a
tree771d568a6cd2e5d818e25914fc6cd3a35cc1c52c
parent7c8311eca77b13275d15d54edbb0141e647f870c
libctf: allow ctf_arc_bufpreamble to fail

The recent libctf fix for ctf_arc_bufpreamble missed a case:
what if the input is exactly sizeof (ctf_archive_t) in size (which can
happen if the archive has no members at all, so returning the preamble
from one of the members is in any case impossible?).  In this case
it'll return an off-the-end pointer, and its caller will overrun.

Allow it to fail in this case, returning NULL, and adjust its sole
caller.  The caller's conclusions in this case will be wrong (it will
conclude that the archive is connected to .symtab), but the incorrect
conclusions are harmless because the lack of archive members will
immediately cause a failure in ctf_arc_bufopen(), and an error return.

Thanks to Alan Modra for the original fix this soups up.

libctf/
* ctf-archive.c (ctf_arc_bufpreamble): Fail if the archive is
too short (or empty, with no dicts to contain preambles),
returning NULL.
* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Handle a NULL return.
libctf/ctf-archive.c
libctf/ctf-open-bfd.c