This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils 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] strings: Produce error when section data falls outside file.


On 2014-12-27 14:42, Mark Wielaard wrote:
> On Sat, Dec 27, 2014 at 04:31:14AM +0300, Alexander Cherepanov wrote:
>> On 2014-12-27 01:00, Mark Wielaard wrote:
>>> diff --git a/src/strings.c b/src/strings.c
>>> index f60e4b4..d1eb7b2 100644
>>> --- a/src/strings.c
>>> +++ b/src/strings.c
>>> @@ -725,8 +725,21 @@ read_elf (Elf *elf, int fd, const char *fname, off64_t fdlen)
>>>   	 actually have content.  */
>>>         if (shdr != NULL && shdr->sh_type != SHT_NOBITS
>>>   	  && (shdr->sh_flags & SHF_ALLOC) != 0)
>>> -	result |= read_block (fd, fname, fdlen, shdr->sh_offset,
>>> -			      shdr->sh_offset + shdr->sh_size);
>>> +	{
>>> +	  if (shdr->sh_offset > fdlen
>>> +	      || fdlen - shdr->sh_offset < shdr->sh_size)
>>> +	    {
>>
>> It fails to build for me:
>>
>> strings.c: In function 'read_elf':
>> strings.c:729:24: error: comparison between signed and unsigned integer
>> expressions [-Werror=sign-compare]
>>      if (shdr->sh_offset > fdlen
>
> The compiler is correct. sh_offset is an unsigned Elf64_Off and fdlen is
> a signed off64_t. But just before we already checked fdlen >= 0, so we

I see.

> can just cast it to Elf64_Off safely for this comparison. As attached.

Thanks, mjw/pending is compiling fine now.

-- 
Alexander Cherepanov

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