Skip to content

Commit 52ab908

Browse files
committed
Fix issue NixOS#66 by ignoring the first section header when sorting, and not overwriting NOBITS entries.
1 parent 27ffe8a commit 52ab908

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/patchelf.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void ElfFile<ElfFileParamNames>::sortShdrs()
475475
/* Sort the sections by offset. */
476476
CompShdr comp;
477477
comp.elfFile = this;
478-
sort(shdrs.begin(), shdrs.end(), comp);
478+
sort(shdrs.begin() + 1, shdrs.end(), comp);
479479

480480
/* Restore the sh_link mappings. */
481481
for (unsigned int i = 1; i < rdi(hdr->e_shnum); ++i)
@@ -642,7 +642,8 @@ void ElfFile<ElfFileParamNames>::writeReplacedSections(Elf_Off & curOff,
642642
for (auto & i : replacedSections) {
643643
std::string sectionName = i.first;
644644
Elf_Shdr & shdr = findSection(sectionName);
645-
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
645+
if (shdr.sh_type != SHT_NOBITS)
646+
memset(contents + rdi(shdr.sh_offset), 'X', rdi(shdr.sh_size));
646647
}
647648

648649
for (auto & i : replacedSections) {

0 commit comments

Comments
 (0)