File arlib-check-that-sh_entsize-isnt-zero.patch of Package elfutils.8903

[PATCH] arlib: Check that sh_entsize isn't zero.
From: Mark Wielaard <mark at klomp dot org>
To: elfutils-devel at sourceware dot org
Cc: Mark Wielaard <mark at klomp dot org>
Date: Thu, 18 Oct 2018 19:02:49 +0200
Subject: [PATCH] arlib: Check that sh_entsize isn't zero.
Reference: bnc#1112723

A bogus ELF file could have sh_entsize as zero. Don't divide by zero,
but just assume there are no symbols in the section.

https://sourceware.org/bugzilla/show_bug.cgi?id=23786

elfutils packaging edits:
 - changelog hunk removed from original patch to avoid conflict

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 4 ++++
 src/arlib.c   | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/src/arlib.c b/src/arlib.c
index 778e0878b..a6521e307 100644
--- a/src/arlib.c
+++ b/src/arlib.c
@@ -252,6 +252,9 @@ arlib_add_symbols (Elf *elf, const char *arfname, const char *membername,
       if (data == NULL)
 	continue;
 
+      if (shdr->sh_entsize == 0)
+	continue;
+
       int nsyms = shdr->sh_size / shdr->sh_entsize;
       for (int ndx = shdr->sh_info; ndx < nsyms; ++ndx)
 	{
-- 
2.19.1
openSUSE Build Service is sponsored by