diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-06-03 14:19:12 (GMT) |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2008-06-03 14:19:12 (GMT) |
commit | d373d86ab3d512e7c040425aeb9fbdad2cc61520 (patch) | |
tree | 6a281749a12a37e20e4fbd1ca765c8f006fcb1e4 /src | |
parent | 55a701beb7bc50c5438d64ab869321f808ad7bd3 (diff) | |
download | patchelf-d373d86ab3d512e7c040425aeb9fbdad2cc61520.zip patchelf-d373d86ab3d512e7c040425aeb9fbdad2cc61520.tar.gz patchelf-d373d86ab3d512e7c040425aeb9fbdad2cc61520.tar.bz2 |
* Don't clobber previously written sections.
Diffstat (limited to 'src')
-rw-r--r-- | src/patchelf.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 76b43b4..146c064 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -482,15 +482,25 @@ template<ElfFileParams> void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff, Elf_Addr startAddr, Elf_Off startOffset) { + /* Overwrite the old section contents with 'X's. Do this + *before* writing the new section contents (below) to prevent + clobbering previously written new section contents. */ for (ReplacedSections::iterator i = replacedSections.begin(); i != replacedSections.end(); ++i) { string sectionName = i->first; Elf_Shdr & shdr = findSection(sectionName); - debug("rewriting section `%s' from offset %d to offset %d\n", - sectionName.c_str(), rdi(shdr.sh_offset), curOff); - memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size)); + } + + for (ReplacedSections::iterator i = replacedSections.begin(); + i != replacedSections.end(); ++i) + { + string sectionName = i->first; + Elf_Shdr & shdr = findSection(sectionName); + debug("rewriting section `%s' from offset %d (size %d) to offset %d (size %d)\n", + sectionName.c_str(), rdi(shdr.sh_offset), rdi(shdr.sh_size), curOff, i->second.size()); + memcpy(contents + curOff, (unsigned char *) i->second.c_str(), i->second.size()); |