Skip to content

Commit bf62fda

Browse files
committed
fix use-after-free in normalizeNoteSegments
1 parent 8386499 commit bf62fda

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/patchelf.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
10251025
[this](std::pair<const std::string, std::string> & i) { return rdi(findSection(i.first).sh_type) == SHT_NOTE; });
10261026
if (!replaced_note) return;
10271027

1028+
std::vector<Elf_Phdr> newPhdrs;
10281029
for (auto & phdr : phdrs) {
10291030
if (rdi(phdr.p_type) != PT_NOTE) continue;
10301031

@@ -1061,11 +1062,13 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
10611062
if (curr_off == start_off)
10621063
phdr = new_phdr;
10631064
else
1064-
phdrs.push_back(new_phdr);
1065+
newPhdrs.push_back(new_phdr);
10651066

10661067
curr_off += size;
10671068
}
10681069
}
1070+
phdrs.insert(phdrs.end(), newPhdrs.begin(), newPhdrs.end());
1071+
10691072
wri(hdr->e_phnum, phdrs.size());
10701073
}
10711074

0 commit comments

Comments
 (0)