diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2023-02-21 19:40:59 +0100 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2023-02-21 19:40:59 +0100 |
commit | e8832294372f0e7c69948d701f3613183a4f78a2 (patch) | |
tree | 2140d8b206cf4259967aaf3d1eaf6d46ac6c95bc | |
parent | 98d1813f2516aa4c771dd8824e7cada98393049f (diff) | |
download | patchelf-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.cc | 5 |
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"); } |