This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] Protect against broken STRTAB sections
- From: Eric Christopher <echristo at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Fri, 10 Jun 2005 17:12:22 -0700
- Subject: Re: [PATCH] Protect against broken STRTAB sections
- References: <20050611000411.GD7663@sunsite.mff.cuni.cz>
> - shstrtab = elf_read (abfd, offset, shstrtabsize);
> +
> + /* Allocate and clear an extra byte at the end, to prevent crashes
> + in case the string table is not terminated. */
> + if (shstrtabsize + 1 == 0
> + || (shstrtab = bfd_alloc (abfd, shstrtabsize + 1)) == NULL
> + || bfd_seek (abfd, offset, SEEK_SET) != 0)
> + shstrtab = NULL;
> + else if (bfd_bread (shstrtab, shstrtabsize, abfd) != shstrtabsize)
> + {
> + if (bfd_get_error () != bfd_error_system_call)
> + bfd_set_error (bfd_error_file_truncated);
> + shstrtab = NULL;
> + }
> + else
> + shstrtab[shstrtabsize] = '\0';
Perhaps a silly question, but why not just put all of this in, say,
elf_read_shstrtab?
-eric