diff options
author | Jason <otherjason@nodomain.com> | 2022-12-02 09:58:49 -0500 |
---|---|---|
committer | Jason <otherjason@nodomain.com> | 2022-12-02 09:58:49 -0500 |
commit | f4f1848e42b68adca04019bcf0d47132d1530bf2 (patch) | |
tree | b698eb8d36f9a120a3683068d66bb3cfbd3d5492 | |
parent | 3f90e4925cde85185576bef8980bc68992c341b6 (diff) | |
download | patchelf-f4f1848e42b68adca04019bcf0d47132d1530bf2.tar.gz |
shiftFile: when splitting a segment into two pieces, preserve the original flags in both
-rw-r--r-- | src/patchelf.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index 398404c..4b4fea4 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -463,6 +463,9 @@ void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, size_t start int splitIndex = -1; size_t splitShift = 0; + /* Save off the flags from the segment that we are splitting so we can apply the same value + to both of the resulting segments. */ + decltype(phdrs.at(0).p_flags) splitFlags = 0; /* Update the offsets in the program headers. */ for (int i = 0; i < rdi(hdr()->e_phnum); ++i) { @@ -473,6 +476,7 @@ void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, size_t start splitIndex = i; splitShift = startOffset - p_start; + splitFlags = rdi(phdrs.at(i).p_flags); /* This is the load segment we're currently extending within, so we split it. */ wri(phdrs.at(i).p_offset, startOffset); @@ -513,7 +517,7 @@ void ElfFile<ElfFileParamNames>::shiftFile(unsigned int extraPages, size_t start wri(phdr.p_paddr, phdrs.at(splitIndex).p_paddr - splitShift - shift); wri(phdr.p_vaddr, phdrs.at(splitIndex).p_vaddr - splitShift - shift); wri(phdr.p_filesz, wri(phdr.p_memsz, splitShift + shift)); - wri(phdr.p_flags, PF_R | PF_W); + wri(phdr.p_flags, splitFlags); wri(phdr.p_align, getPageSize()); } |