summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2023-02-21 19:40:59 +0100
committerChristian Göttsche <cgzones@googlemail.com>2023-02-21 19:40:59 +0100
commite8832294372f0e7c69948d701f3613183a4f78a2 (patch)
tree2140d8b206cf4259967aaf3d1eaf6d46ac6c95bc
parent98d1813f2516aa4c771dd8824e7cada98393049f (diff)
downloadpatchelf-e8832294372f0e7c69948d701f3613183a4f78a2.tar.gz
Avoid potential overflows in checkPointer()
Prevent overflows in the addtion of q and size, and avoid truncations in callers by using size_t as type for size.
-rw-r--r--src/patchelf.cc5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc
index 4c94175..6ea238e 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -236,10 +236,9 @@ struct ElfType
}
-static void checkPointer(const FileContents & contents, void * p, unsigned int size)
+static void checkPointer(const FileContents & contents, const void * p, size_t size)
{
- auto q = static_cast<unsigned char *>(p);
- if (!(q >= contents->data() && q + size <= contents->data() + contents->size()))
+ if (p < contents->data() || size > contents->size() || p > contents->data() + contents->size() - size)
error("data region extends past file end");
}