]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
tests: elfcopy --reverse-offs should only swap sections next to each other.
authorMark Wielaard <mark@klomp.org>
Mon, 3 Jun 2019 16:00:20 +0000 (18:00 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 3 Jun 2019 16:00:20 +0000 (18:00 +0200)
The run-reverse-sections-self.sh (which really should have been called
"swap-sections") could fail if the ELF file had sections that were not
directly next to each other swapped. Add a check to make sure the swapped
sections are actually directly next to each other.

Signed-off-by: Mark Wielaard <mark@klomp.org>
tests/ChangeLog
tests/elfcopy.c

index b4877db50ef141af577d7c7f39f688b34c967f2e..e038793983287411ca42b9e540a1a06cba21212d 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-03  Mark Wielaard  <mark@klomp.org>
+
+       * elfcopy.c (copy_elf): When swapping the sh_offsets of two sections,
+       make sure they are actually next to each other.
+
 2019-05-12  Mark Wielaard  <mark@klomp.org>
 
        * Makefile.am (check_PROGRAMS): Add elfrdwrnop.
index d457badbc66293119a183a33a2c7f2dd1a84d76f..4542222e769594a3e55578d4775e3c032ecb83f8 100644 (file)
@@ -225,6 +225,7 @@ copy_elf (const char *in, const char *out, bool use_mmap, bool reverse_offs)
              && shdr.sh_addralign == 1
              && last_shdr.sh_type != SHT_NOBITS
              && shdr.sh_type != SHT_NOBITS
+             && last_shdr.sh_offset + last_shdr.sh_size == shdr.sh_offset
              && (phnum == 0
                  || ((shdr.sh_flags & SHF_ALLOC) == 0
                      && (last_shdr.sh_flags & SHF_ALLOC) == 0)))