diff options
| author | Roland McGrath <[email protected]> | 2010-01-07 20:11:42 -0800 |
|---|---|---|
| committer | Roland McGrath <[email protected]> | 2010-01-07 20:11:42 -0800 |
| commit | bd733cae5159e3a3c4c05f7685559fa3ae8b58c6 (patch) | |
| tree | d6ed85f1594d56f70f6ee1b5af04e2fed0b380ac /src/elfcmp.c | |
| parent | 6fd3cd104adf4107aa64e1c1e84028b4ea0b3296 (diff) | |
Handle extended phnum in elflint and elfcmp.
Diffstat (limited to 'src/elfcmp.c')
| -rw-r--r-- | src/elfcmp.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/elfcmp.c b/src/elfcmp.c index 7f871ecf..71a80092 100644 --- a/src/elfcmp.c +++ b/src/elfcmp.c @@ -1,5 +1,5 @@ /* Compare relevant content of two ELF files. - Copyright (C) 2005, 2006, 2007, 2008, 2009 Red Hat, Inc. + Copyright (C) 2005-2010 Red Hat, Inc. This file is part of Red Hat elfutils. Written by Ulrich Drepper <[email protected]>, 2005. @@ -192,6 +192,39 @@ main (int argc, char *argv[]) goto out; } + size_t shnum1; + size_t shnum2; + if (unlikely (elf_getshdrnum (elf1, &shnum1) != 0)) + error (2, 0, gettext ("cannot get section count of '%s': %s"), + fname1, elf_errmsg (-1)); + if (unlikely (elf_getshdrnum (elf2, &shnum2) != 0)) + error (2, 0, gettext ("cannot get section count of '%s': %s"), + fname2, elf_errmsg (-1)); + if (unlikely (shnum1 != shnum2)) + { + if (! quiet) + error (0, 0, gettext ("%s %s diff: section count"), fname1, fname2); + result = 1; + goto out; + } + + size_t phnum1; + size_t phnum2; + if (unlikely (elf_getphdrnum (elf1, &phnum1) != 0)) + error (2, 0, gettext ("cannot get program header count of '%s': %s"), + fname1, elf_errmsg (-1)); + if (unlikely (elf_getphdrnum (elf2, &phnum2) != 0)) + error (2, 0, gettext ("cannot get program header count of '%s': %s"), + fname2, elf_errmsg (-1)); + if (unlikely (phnum1 != phnum2)) + { + if (! quiet) + error (0, 0, gettext ("%s %s diff: program header count"), + fname1, fname2); + result = 1; + goto out; + } + /* Iterate over all sections. We expect the sections in the two files to match exactly. */ Elf_Scn *scn1 = NULL; @@ -410,7 +443,7 @@ main (int argc, char *argv[]) ehdr_region.next = &phdr_region; phdr_region.from = ehdr1->e_phoff; - phdr_region.to = ehdr1->e_phoff + ehdr1->e_phnum * ehdr1->e_phentsize; + phdr_region.to = ehdr1->e_phoff + phnum1 * ehdr1->e_phentsize; phdr_region.next = regions; regions = &ehdr_region; @@ -445,7 +478,7 @@ main (int argc, char *argv[]) } /* Compare the program header tables. */ - for (int ndx = 0; ndx < ehdr1->e_phnum; ++ndx) + for (unsigned int ndx = 0; ndx < phnum1; ++ndx) { GElf_Phdr phdr1_mem; GElf_Phdr *phdr1 = gelf_getphdr (elf1, ndx, &phdr1_mem); |
