From 4c87e11aeb1a1efe7059df00888dc6f9282894e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Mon, 17 Jul 2006 16:58:24 +0200 Subject: [PATCH] 8 bit relocation overflow detection added to ElfLinker --- src/linker.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/linker.cpp b/src/linker.cpp index ff81809b..efd94682 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -787,7 +787,16 @@ void ElfLinkerX86::relocate1(Relocation *rel, upx_byte *location, } if (strcmp(type, "8") == 0) + { + int displ = (char) *location + (int) value; + if (displ < -127 || displ > 128) + { + printf("target out of range (%d) in reloc %s:%x\n", + displ, rel->section->name, rel->offset); + abort(); + } *location += value; + } else if (strcmp(type, "16") == 0) set_le16(location, get_le16(location) + value); else if (strcmp(type, "32") == 0) @@ -810,7 +819,16 @@ void ElfLinkerAMD64::relocate1(Relocation *rel, upx_byte *location, } if (strcmp(type, "8") == 0) + { + int displ = (char) *location + (int) value; + if (displ < -127 || displ > 128) + { + printf("target out of range (%d) in reloc %s:%x\n", + displ, rel->section->name, rel->offset); + abort(); + } *location += value; + } else if (strcmp(type, "16") == 0) set_le16(location, get_le16(location) + value); else if (strcmp(type, "32") == 0)