summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBreno Rodrigues Guimaraes <brenorg@gmail.com>2023-02-20 18:22:17 -0300
committerBreno Rodrigues Guimaraes <brenorg@gmail.com>2023-02-24 20:39:11 -0300
commitde3e1f5e11f533d8678474eb9234ba35efa960d6 (patch)
tree276fecc1cba3f3543d241ea34115f6ef4030733c /src
parent69a7ae54d27513d7553b4d8bd77ade017e674e22 (diff)
downloadpatchelf-de3e1f5e11f533d8678474eb9234ba35efa960d6.tar.gz
Add one extra page to avoid overlapping with next page if its rounded down
Diffstat (limited to 'src')
-rw-r--r--src/patchelf.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index ca247c1..b78210c 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -985,7 +985,9 @@ void ElfFile<ElfFileParamNames>::rewriteSectionsExecutable()
/* Calculate how many bytes are needed out of the additional pages. */
size_t extraSpace = neededSpace - startOffset;
- unsigned int neededPages = roundUp(extraSpace, getPageSize()) / getPageSize();
+ // Always give one extra page to avoid colliding with segments that start at
+ // unaligned addresses and will be rounded down when loaded
+ unsigned int neededPages = 1 + roundUp(extraSpace, getPageSize()) / getPageSize();
debug("needed pages is %d\n", neededPages);
if (neededPages * getPageSize() > firstPage)
error("virtual address space underrun!");