Skip to content

Commit

Permalink
Use sh_offset instead of sh_addr when checking already replaced libs
Browse files Browse the repository at this point in the history
When checking for already replaced libs, the check against the size must
be done using the section header offset, not the section file address.
This was not crashing in many situations because normally sh_address and
sh_offset have the same value but these two may differ and using the
sh_address value instead can cause library corruption in these
situations.
  • Loading branch information
pablogsal committed Sep 22, 2020
1 parent 5cd4517 commit 83aa89a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/patchelf.cc
Expand Up @@ -778,7 +778,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
/* Some sections may already be replaced so account for that */
unsigned int i = 1;
Elf_Addr pht_size = sizeof(Elf_Ehdr) + (phdrs.size() + num_notes + 1)*sizeof(Elf_Phdr);
while( shdrs[i].sh_addr <= pht_size && i < rdi(hdr->e_shnum) ) {
while( shdrs[i].sh_offset <= pht_size && i < rdi(hdr->e_shnum) ) {
if (not haveReplacedSection(getSectionName(shdrs[i])))
replaceSection(getSectionName(shdrs[i]), shdrs[i].sh_size);
i++;
Expand Down

0 comments on commit 83aa89a

Please sign in to comment.