From d2419cf947252c5514610de2c3b004972dfb65d6 Mon Sep 17 00:00:00 2001 From: Tim Strazzere Date: Tue, 3 Mar 2020 17:59:53 -0800 Subject: [PATCH] Fix issue #16 - prevent underflow in original_ep() --- src/internal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/internal.c b/src/internal.c index 1678512..27d6e92 100755 --- a/src/internal.c +++ b/src/internal.c @@ -1325,6 +1325,11 @@ original_ep(elfobj_t *obj) uint8_t *inst, *marker; size_t i; + // If we can't figure out the elf_text_offset + elf_text_filesz, then the following + // loop will cause errors, prevent this case + if (elf_text_offset(obj) + elf_text_filesz(obj) <= 0) + return 0; + for (i = 0, marker = inst = ptr; inst; inst++, i++) { if (i >= (elf_text_offset(obj) + elf_text_filesz(obj) - 6)) return 0;