/* Get ELF program header table.
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 Red Hat, Inc.
+ Copyright (C) 1998-2009 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 1998.
/* First see whether the information in the ELF header is
valid and it does not ask for too much. */
if (unlikely (ehdr->e_phoff >= elf->maximum_size)
- || unlikely (ehdr->e_phoff + size > elf->maximum_size))
+ || unlikely (elf->maximum_size - ehdr->e_phoff < size))
{
/* Something is wrong. */
__libelf_seterrno (ELF_E_INVALID_PHDR);
/* First see whether the information in the ELF header is
valid and it does not ask for too much. */
if (unlikely (ehdr->e_shoff >= elf->maximum_size)
- || unlikely (ehdr->e_shoff + size > elf->maximum_size))
+ || unlikely (elf->maximum_size - ehdr->e_shoff < size))
{
/* Something is wrong. */
__libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
/* Create descriptor for processing file.
- Copyright (C) 1998-2005, 2006, 2007, 2008 Red Hat, Inc.
+ Copyright (C) 1998-2009 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 1998.
if (unlikely (result == 0) && ehdr.e32->e_shoff != 0)
{
if (unlikely (ehdr.e32->e_shoff >= maxsize)
- || unlikely (ehdr.e32->e_shoff + sizeof (Elf32_Shdr) > maxsize))
+ || unlikely (maxsize - ehdr.e32->e_shoff < sizeof (Elf32_Shdr)))
/* Cannot read the first section header. */
return 0;
elf->state.elf32.ehdr = ehdr;
if (unlikely (ehdr->e_shoff >= maxsize)
- || unlikely (ehdr->e_shoff
- + scncnt * sizeof (Elf32_Shdr) > maxsize))
+ || unlikely (maxsize - ehdr->e_shoff
+ < scncnt * sizeof (Elf32_Shdr)))
{
free_and_out:
free (elf);
/* Assign a value only if there really is a program
header. Otherwise the value remains NULL. */
if (unlikely (ehdr->e_phoff >= maxsize)
- || unlikely (ehdr->e_phoff
- + ehdr->e_phnum
- * sizeof (Elf32_Phdr) > maxsize))
+ || unlikely (maxsize - ehdr->e_phoff
+ < ehdr->e_phnum * sizeof (Elf32_Phdr)))
goto free_and_out;
elf->state.elf32.phdr
= (Elf32_Phdr *) ((char *) ehdr + ehdr->e_phoff);
{
/* First see whether the information in the ELF header is
valid and it does not ask for too much. */
- if (unlikely (offset + sizeof (Elf32_Shdr)
- > elf->maximum_size))
+ if (unlikely (elf->maximum_size - offset
+ < sizeof (Elf32_Shdr)))
{
/* Something is wrong. */
__libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
goto out;
}
- /* We can directly access the memory. */
+ /* We can directly access the memory. */
num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset
+ offset))->sh_link;
}
{
/* First see whether the information in the ELF header is
valid and it does not ask for too much. */
- if (unlikely (offset + sizeof (Elf64_Shdr)
- > elf->maximum_size))
+ if (unlikely (elf->maximum_size - offset
+ < sizeof (Elf64_Shdr)))
{
/* Something is wrong. */
__libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
goto out;
}
- /* We can directly access the memory. */
- num = ((Elf64_Shdr *) (elf->map_address
- + elf->start_offset + offset))->sh_link;
+ /* We can directly access the memory. */
+ num = ((Elf64_Shdr *) (elf->map_address + elf->start_offset
+ + offset))->sh_link;
}
else
{