From 213dbedac2cd6e488dfd494573d0394cf7e76874 Mon Sep 17 00:00:00 2001 From: Martin Bickel Date: Wed, 28 Dec 2016 19:20:37 +0100 Subject: [PATCH] Add sanity check when calculating alignment --- elfio/elfio.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/elfio/elfio.hpp b/elfio/elfio.hpp index 468140f..c983a9e 100644 --- a/elfio/elfio.hpp +++ b/elfio/elfio.hpp @@ -676,6 +676,11 @@ class elfio // when possible (this is what matters for execution) Elf64_Off req_offset = sec->get_address() - seg->get_virtual_address(); Elf64_Off cur_offset = current_file_pos - seg_start_pos; + if ( req_offset < cur_offset) { + // something has gone awfully wrong, abort! + // secAlign would turn out negative, seeking backwards and overwriting previous data + return false; + } secAlign = req_offset - cur_offset; } else if (!section_generated[index]) {