From 52ab908394958a2a5d0476e306e2cad4da4fdeae Mon Sep 17 00:00:00 2001 From: Ezra Cooper Date: Thu, 21 Jun 2018 11:07:35 -0700 Subject: Fix issue #66 by ignoring the first section header when sorting, and not overwriting NOBITS entries. --- src/patchelf.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index 3ca38d9..0b4965a 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -475,7 +475,7 @@ void ElfFile::sortShdrs() /* Sort the sections by offset. */ CompShdr comp; comp.elfFile = this; - sort(shdrs.begin(), shdrs.end(), comp); + sort(shdrs.begin() + 1, shdrs.end(), comp); /* Restore the sh_link mappings. */ for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i) @@ -642,7 +642,8 @@ void ElfFile::writeReplacedSections(Elf_Off & curOff, for (auto & i : replacedSections) { std::string sectionName = i.first; Elf_Shdr & shdr = findSection(sectionName); - memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size)); + if (shdr.sh_type != SHT_NOBITS) + memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size)); } for (auto & i : replacedSections) { -- cgit v0.12