Skip to content

Commit 671f0cf

Browse files
committed
fix use-after-free in normalizeNoteSegments
1 parent 0121f5e commit 671f0cf

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
@@ -1011,6 +1011,7 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
10111011
[this](std::pair<const std::string, std::string> & i) { return rdi(findSection(i.first).sh_type) == SHT_NOTE; });
10121012
if (!replaced_note) return;
10131013

1014+
std::vector<Elf_Phdr> newPhdrs;
10141015
for (auto & phdr : phdrs) {
10151016
if (rdi(phdr.p_type) != PT_NOTE) continue;
10161017

@@ -1047,11 +1048,13 @@ void ElfFile<ElfFileParamNames>::normalizeNoteSegments()
10471048
if (curr_off == start_off)
10481049
phdr = new_phdr;
10491050
else
1050-
phdrs.push_back(new_phdr);
1051+
newPhdrs.push_back(new_phdr);
10511052

10521053
curr_off += size;
10531054
}
10541055
}
1056+
phdrs.insert(phdrs.end(), newPhdrs.begin(), newPhdrs.end());
1057+
10551058
wri(hdr->e_phnum, phdrs.size());
10561059
}
10571060

0 commit comments

Comments
 (0)