Existing code checks that the first uint64_t ctfa_magic field is
available before reading but neglects to check that the last uint64_t
ctfa_ctfs is available before reading it in ctf_arc_bufpreamble.
ctf_arc_bufopen sets up a pointer to the struct ctf_archive in
ctf_new_archive_internal. Extend the check to cover the entire struct.
PR 33548
PR 33549
* ctf-archive.c (ctf_arc_bufpreamble, ctf_arc_bufopen): Check
that buffer contains at least an entire struct ctf_archive
when accessing such a struct.
ctf_arc_bufpreamble (const ctf_sect_t *ctfsect)
{
if (ctfsect->cts_data != NULL
- && ctfsect->cts_size > sizeof (uint64_t)
+ && ctfsect->cts_size >= sizeof (struct ctf_archive)
&& (le64toh ((*(uint64_t *) ctfsect->cts_data)) == CTFA_MAGIC))
{
struct ctf_archive *arc = (struct ctf_archive *) ctfsect->cts_data;
ctf_dict_t *fp = NULL;
if (ctfsect->cts_data != NULL
- && ctfsect->cts_size > sizeof (uint64_t)
+ && ctfsect->cts_size >= sizeof (struct ctf_archive)
&& (le64toh ((*(uint64_t *) ctfsect->cts_data)) == CTFA_MAGIC))
{
/* The archive is mmappable, so this operation is trivial.