From: Roland McGrath Date: Tue, 15 Jun 2010 00:44:38 +0000 (-0700) Subject: Fix unstrip for modifying file in place. X-Git-Tag: elfutils-0.148~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec86e5fa64540a6bb027b0dd505322455968c8e2;p=thirdparty%2Felfutils.git Fix unstrip for modifying file in place. --- diff --git a/src/ChangeLog b/src/ChangeLog index ab33cbf20..3c8c33c72 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-06-14 Roland McGrath + + * unstrip.c (copy_elided_sections): Make sure all sections' data have + been read in before we write anything out. + 2010-06-04 Roland McGrath * unstrip.c (update_shdr): New function. diff --git a/src/unstrip.c b/src/unstrip.c index 59d3ead57..443cd620d 100644 --- a/src/unstrip.c +++ b/src/unstrip.c @@ -1781,6 +1781,15 @@ more sections in stripped file than debug file -- arguments reversed?")); GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); ELF_CHECK (shdr != NULL, _("cannot get section header: %s")); + /* We must make sure we have read in the data of all sections + beforehand and marked them to be written out. When we're + modifying the existing file in place, we might overwrite + this part of the file before we get to handling the section. */ + + ELF_CHECK (elf_flagdata (elf_getdata (scn, NULL), + ELF_C_SET, ELF_F_DIRTY), + _("cannot read section data: %s")); + if (skip_reloc && (shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA)) continue; @@ -1813,7 +1822,8 @@ more sections in stripped file than debug file -- arguments reversed?")); placed[i] = true; } - } while (skip_reloc); + } + while (skip_reloc); if (stripped_ehdr->e_phnum > 0) ELF_CHECK (gelf_newphdr (unstripped, stripped_ehdr->e_phnum), diff --git a/tests/ChangeLog b/tests/ChangeLog index 60b0847a9..0176fb495 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +2010-06-04 Roland McGrath + + * run-unstrip-test.sh: Also test modifying the file in place. + 2010-04-22 Roland McGrath * addrcfi.c (handle_cfi): Fix function name in error message. diff --git a/tests/run-unstrip-test.sh b/tests/run-unstrip-test.sh index 8f0fc6988..b9959a109 100755 --- a/tests/run-unstrip-test.sh +++ b/tests/run-unstrip-test.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2007 Red Hat, Inc. +# Copyright (C) 2007-2010 Red Hat, Inc. # This file is part of Red Hat elfutils. # # Red Hat elfutils is free software; you can redistribute it and/or modify @@ -30,7 +30,7 @@ stripped=${stripped:-testfile17} debugfile=${debugfile:-${stripped}.debug} testfiles $original $stripped $debugfile -tempfiles testfile.unstrip +tempfiles testfile.unstrip testfile.inplace # These are old reference output from run-test-strip6.sh, when # strip left the .debug file with unchanged sh_size in @@ -40,3 +40,12 @@ tempfiles testfile.unstrip testrun ../src/unstrip -o testfile.unstrip $stripped $debugfile testrun ../src/elfcmp --hash-inexact $original testfile.unstrip + +# Also test modifying the file in place. + +rm -f testfile.inplace +cp $debugfile testfile.inplace +chmod 644 testfile.inplace +testrun ../src/unstrip $stripped testfile.inplace + +testrun ../src/elfcmp --hash-inexact $original testfile.inplace