File fix-bsc-1110929.diff of Package elfutils.14006

commit d7193bd7c9dc2a979352eee7fc446dacd3e97779
Author: Mark Wielaard <mark@klomp.org>
Date:   Sun May 12 00:37:45 2019 +0200

    libelf: Mark shdr_flags dirty if offset or size changes during update.
    
    We forgot to mark the shdr_flags dirty when only the sh_size or
    sh_offset changed during elf_update (). This meant that if there were
    no other shdr changes we only wrote out the section data, but didn't
    write out the shdr table to the file.
    
    Add a testcase that puts some sections in the reverse order and then
    writes out the resulting file again without doing any other
    updates. This would show the issue after write out of the
    (re-reversed) ELF file (the .shstrtab section offset would be wrong
    causing all section names to be garbage). Also run a self test.
    
    Signed-off-by: Mark Wielaard <mark@klomp.org>


ChangeLog
2019-05-12  Mark Wielaard  <mark@klomp.org>

	* elf32_updatenull.c (updatenull_wrlock): Mark shdr_flags dirty if
	either offset or size changed.

tests/ChangeLog
2019-05-12  Mark Wielaard  <mark@klomp.org>

	* Makefile.am (check_PROGRAMS): Add elfrdwrnop.
	(TESTS): Add run-reverse-sections.sh and
	run-reverse-sections-self.sh.
	(EXTRA_DIST): Likewise.
	(elfrdwrnop): New variable.
	* elfcopy.c (copy_elf): Add reverse_off argument. Record offsets
	of sections and swap them when possible.
	(main): Check for --reverse-off argument. Pass reverse_offs to
	copy_elf.
	* run-reverse-sections.sh: New test.
	* run-reverse-sections-self.sh: Likewise.
	* elfrdwrnop.c: New file.

Index: elfutils-0.168/libelf/elf32_updatenull.c
===================================================================
--- elfutils-0.168.orig/libelf/elf32_updatenull.c	2019-09-16 12:03:07.441236958 +0200
+++ elfutils-0.168/libelf/elf32_updatenull.c	2019-09-16 12:03:10.445275245 +0200
@@ -367,12 +367,15 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (E
 		    }
 
 		  /* See whether the section size is correct.  */
+		  int size_changed = 0;
 		  update_if_changed (shdr->sh_size, (GElf_Word) offset,
-				     changed);
+				     size_changed);
+		  changed |= size_changed;
 
 		  if (shdr->sh_type != SHT_NOBITS)
 		    size += offset;
 
+		  scn->shdr_flags |= (offset_changed | size_changed);
 		  scn->flags |= changed;
 		}
 

openSUSE Build Service is sponsored by