From fc21d139a463c373fb61e5061f73ee737f5e53d0 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Mon, 10 Oct 2022 15:13:11 +0100 Subject: [PATCH] Fix out of bounds access when increasing program header table --- src/patchelf.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patchelf.cc b/src/patchelf.cc index 505c980..f7d6e00 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -689,7 +689,7 @@ void ElfFile::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( rdi(shdrs.at(i).sh_offset) <= pht_size && i < rdi(hdr()->e_shnum) ) { + while( i < rdi(hdr()->e_shnum) && rdi(shdrs.at(i).sh_offset) <= pht_size ) { if (not haveReplacedSection(getSectionName(shdrs.at(i)))) replaceSection(getSectionName(shdrs.at(i)), rdi(shdrs.at(i).sh_size)); i++;