This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] Protect against broken STRTAB sections
On Fri, Jun 10, 2005 at 05:12:22PM -0700, Eric Christopher wrote:
>
> > - 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?
Sure, that's the possibility. But bfd_elf_get_str_section
is already a short function and the only potential caller of that
function.
Jakub