File elflint-dont-check-section-group-without-flags-word.patch of Package elfutils.13244

From: Joao Moreira <jmoreira@suse.de>
Date: Wed May 29 17:58:01 -03 2019
Subject: [PATCH] elflint: Don't check section group without flags word.
Reference: bnc#1033087

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

elfutils packaging edits:
 - changelog hunk removed from original patch to avoid conflict
 - patch was backported to 0.158
 - added fixes to errors captured by asan while testing the reproducer

Signed-off-by: Mark Wielaard <mark@klomp.org>


--- a/src/elflint.c
+++ b/src/elflint.c
@@ -1916,6 +1916,10 @@
     ERROR (gettext ("\
 section [%2d] '%s': extended section index section not for symbol table\n"),
 	   idx, section_name (ebl, idx));
+  else if (symshdr == NULL)
+    ERROR (gettext ("\
+section [%2d] '%s': sh_link extended section index [%2d] is invalid\n"),
+           idx, section_name (ebl, idx), shdr->sh_link);
   Elf_Data *symdata = elf_getdata (symscn, NULL);
   if (symdata == NULL)
     ERROR (gettext ("cannot get data for symbol section\n"));
@@ -1954,7 +1958,8 @@
     }
 
   Elf_Data *data = elf_getdata (elf_getscn (ebl->elf, idx), NULL);
-  if (data == NULL)
+
+  if (data == NULL || data->d_buf == NULL)
     {
       ERROR (gettext ("section [%2d] '%s': cannot get section data\n"),
  	     idx, section_name (ebl, idx));
@@ -1972,6 +1977,7 @@
 	{
 	  GElf_Sym sym_data;
 	  GElf_Sym *sym = gelf_getsym (symdata, cnt, &sym_data);
+
 	  if (sym == NULL)
 	    {
 	      ERROR (gettext ("cannot get data for symbol %zu\n"), cnt);
@@ -2530,9 +2536,12 @@
 	       idx, section_name (ebl, idx));
 
       if (data->d_size < elsize)
-	ERROR (gettext ("\
+	{
+	  ERROR (gettext ("\
 section [%2d] '%s': section group without flags word\n"),
 	       idx, section_name (ebl, idx));
+	  return;
+	}
       else if (be_strict)
 	{
 	  if (data->d_size < 2 * elsize)
@@ -3856,10 +3865,11 @@
 		break;
 	      }
 
-	  if (pcnt == phnum)
+	  if (pcnt == phnum) {
 	    ERROR (gettext ("\
 section [%2zu] '%s': alloc flag set but section not in any loaded segment\n"),
 		   cnt, section_name (ebl, cnt));
+            }
 	}
 
       if (cnt == shstrndx && shdr->sh_type != SHT_STRTAB)
openSUSE Build Service is sponsored by