File libdw-check-end-of-attributes-list-consistently.patch of Package elfutils.13244

From 6983e59b727458a6c64d9659c85f08218bc4fcda Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Sat, 18 Aug 2018 19:51:27 +0200
Subject: [PATCH] libdw: Check end of attributes list consistently.
Reference: bnc#1107067

dwarf_child (__libdw_find_attr), dwarf_getabbrevattr[_data] and
dwarf_getattrs all assume the end of the attribute list is when
both the name (code) and form of the attribute are zero.

dwarf_getabbrev (__libdw_getabbrev) and dwarf_hasattr assume the
end of the attribute list is when either the name (code) or the
form of the attribute is zero.

The DWARF spec says: "The series of attribute specifications ends
with an entry containing 0 for the name and 0 for the form." So
the first check is correct.

Make sure dwarf_getabbrev and dwarf_hasattr use the same check.
This is important since all other functions expect dwarf_getabbrev
(__libdw_getabbrev) to have done a data sanity check of the attribute.
So if the ending condition is different it could cause a crash.

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

elfutils packaging edits:
 - hunk#1 in dwarf_getabbrev.c backported from original patch
 - hunk#3 in dwarf_hasattr.c does not make sense (already fixed in this version)
 - changelog hunk removed from original patch to avoid conflict

Signed-off-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Joao Moreira <jmoreira@suse.de>
---
 libdw/ChangeLog         | 7 +++++++
 libdw/dwarf_getabbrev.c | 2 +-
 libdw/dwarf_hasattr.c   | 4 ++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/libdw/dwarf_getabbrev.c b/libdw/dwarf_getabbrev.c
index 988d12c..6a7e981 100644
--- a/libdw/dwarf_getabbrev.c
+++ b/libdw/dwarf_getabbrev.c
@@ -122,7 +122,7 @@
       get_uleb128 (attrname, abbrevp);
       get_uleb128 (attrform, abbrevp);
     }
-  while (attrname != 0 && attrform != 0 && ++abb->attrcnt);
+  while ((attrname != 0 || attrform != 0) && ++abb->attrcnt);
 
   /* Return the length to the caller if she asked for it.  */
   if (lengthp != NULL)
-- 
2.9.3
openSUSE Build Service is sponsored by