Skip to content

Commit 4c73989

Browse files
committed
use more memory-safe at() function
1 parent a1352e5 commit 4c73989

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/patchelf.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, Elf_Addr sta
600600
PT_INTERP segment into memory. Otherwise glibc will choke. */
601601
phdrs.resize(rdi(hdr()->e_phnum) + 1);
602602
wri(hdr()->e_phnum, rdi(hdr()->e_phnum) + 1);
603-
Elf_Phdr & phdr = phdrs[rdi(hdr()->e_phnum) - 1];
603+
Elf_Phdr & phdr = phdrs.at(rdi(hdr()->e_phnum) - 1);
604604
wri(phdr.p_type, PT_LOAD);
605605
wri(phdr.p_offset, 0);
606606
wri(phdr.p_vaddr, wri(phdr.p_paddr, startPage));
@@ -641,7 +641,7 @@ std::optional<std::reference_wrapper<Elf_Shdr>> ElfFile<ElfFileParamNames>::find
641641
{
642642
auto i = findSection3(sectionName);
643643
if (i)
644-
return shdrs[i];
644+
return shdrs.at(i);
645645
return {};
646646
}
647647

@@ -863,7 +863,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsLibrary()
863863
wri(hdr()->e_phoff, sizeof(Elf_Ehdr));
864864
phdrs.resize(rdi(hdr()->e_phnum) + 1);
865865
wri(hdr()->e_phnum, rdi(hdr()->e_phnum) + 1);
866-
Elf_Phdr & phdr = phdrs[rdi(hdr()->e_phnum) - 1];
866+
Elf_Phdr & phdr = phdrs.at(rdi(hdr()->e_phnum) - 1);
867867
wri(phdr.p_type, PT_LOAD);
868868
wri(phdr.p_offset, startOffset);
869869
wri(phdr.p_vaddr, wri(phdr.p_paddr, startPage));
@@ -916,7 +916,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
916916
Elf_Addr startAddr = rdi(shdrs.at(lastReplaced + 1).sh_addr);
917917
std::string prevSection;
918918
for (unsigned int i = 1; i <= lastReplaced; ++i) {
919-
Elf_Shdr & shdr(shdrs[i]);
919+
Elf_Shdr & shdr(shdrs.at(i));
920920
std::string sectionName = getSectionName(shdr);
921921
debug("looking at section '%s'\n", sectionName.c_str());
922922
/* !!! Why do we stop after a .dynstr section? I can't
@@ -957,7 +957,7 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
957957
assert(rdi(hdr()->e_shnum) == shdrs.size());
958958
sortShdrs();
959959
for (unsigned int i = 1; i < rdi(hdr()->e_shnum); ++i)
960-
* ((Elf_Shdr *) (fileContents->data() + rdi(hdr()->e_shoff)) + i) = shdrs[i];
960+
* ((Elf_Shdr *) (fileContents->data() + rdi(hdr()->e_shoff)) + i) = shdrs.at(i);
961961
}
962962

963963

@@ -1349,12 +1349,12 @@ std::string ElfFile<ElfFileParamNames>::shrinkRPath(char* rpath, std::vector<std
13491349
exists in this directory. */
13501350
bool libFound = false;
13511351
for (unsigned int j = 0; j < neededLibs.size(); ++j)
1352-
if (!neededLibFound[j]) {
1353-
std::string libName = dirName + "/" + neededLibs[j];
1352+
if (!neededLibFound.at(j)) {
1353+
std::string libName = dirName + "/" + neededLibs.at(j);
13541354
try {
13551355
Elf32_Half library_e_machine = getElfType(readFile(libName, sizeof(Elf32_Ehdr))).machine;
13561356
if (rdi(library_e_machine) == rdi(hdr()->e_machine)) {
1357-
neededLibFound[j] = true;
1357+
neededLibFound.at(j) = true;
13581358
libFound = true;
13591359
} else
13601360
debug("ignoring library '%s' because its machine type differs\n", libName.c_str());

0 commit comments

Comments
 (0)