[PATCH] strip: Harden against bogus input files. Don't leak temp debug file on error.

Mark Wielaard mjw at redhat.com
Fri May 15 09:55:22 UTC 2015


On Tue, 2015-05-12 at 16:01 +0200, Mark Wielaard wrote:
> There were various places where a bogus/unexpected input file would cause
> eu-strip to crash. Also on an unexpected error eu-strip would leak the temp
> debug file it was writing.

After some more fuzzing another issue popped up. We should check
nbuckets isn't zero before using it.

diff --git a/src/strip.c b/src/strip.c
index 27c9927..d63b6a8 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1585,7 +1585,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 
                    const char *name = elf_strptr (elf, strshndx,
                                                   sym->st_name);
-                   elf_assert (name != NULL);
+                   elf_assert (name != NULL && nbucket != 0);
                    size_t hidx = elf_hash (name) % nbucket;
 
                    if (bucket[hidx] == 0)
@@ -1647,7 +1647,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 
                    const char *name = elf_strptr (elf, strshndx,
                                                   sym->st_name);
-                   elf_assert (name != NULL);
+                   elf_assert (name != NULL && nbucket != 0);
                    size_t hidx = elf_hash (name) % nbucket;
 
                    if (bucket[hidx] == 0)

Integrated into the existing patch and updated the mjw/pending branch.

Cheers,

Mark


More information about the elfutils-devel mailing list