Skip to content

Commit 83aa89a

Browse files
committed
Use sh_offset instead of sh_addr when checking already replaced libs
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.
1 parent 5cd4517 commit 83aa89a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/patchelf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
778778
/* Some sections may already be replaced so account for that */
779779
unsigned int i = 1;
780780
Elf_Addr pht_size = sizeof(Elf_Ehdr) + (phdrs.size() + num_notes + 1)*sizeof(Elf_Phdr);
781-
while( shdrs[i].sh_addr <= pht_size && i < rdi(hdr->e_shnum) ) {
781+
while( shdrs[i].sh_offset <= pht_size && i < rdi(hdr->e_shnum) ) {
782782
if (not haveReplacedSection(getSectionName(shdrs[i])))
783783
replaceSection(getSectionName(shdrs[i]), shdrs[i].sh_size);
784784
i++;

0 commit comments

Comments
 (0)