Skip to content

Commit

Permalink
Fix issue #66 by ignoring the first section header when sorting, and …
Browse files Browse the repository at this point in the history
…not overwriting NOBITS entries.
  • Loading branch information
ezquat committed Jun 21, 2018
1 parent 27ffe8a commit 52ab908
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/patchelf.cc
Expand Up @@ -475,7 +475,7 @@ void ElfFile<ElfFileParamNames>::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)
Expand Down Expand Up @@ -642,7 +642,8 @@ void ElfFile<ElfFileParamNames>::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) {
Expand Down

0 comments on commit 52ab908

Please sign in to comment.