[PATCH] Protect against broken STRTAB sections

Eric Christopher echristo@redhat.com
Sat Jun 11 00:12:00 GMT 2005


> -      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



More information about the Binutils mailing list