This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Protect against broken STRTAB sections


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]