From 1197beaa13a7c0e0dcc12585bf66e511e87a67cc Mon Sep 17 00:00:00 2001 From: "jreiser@BitWagon.com" Date: Mon, 5 Sep 2016 20:36:07 -0700 Subject: [PATCH] ElfLinker::init() zero length implies 0x4000 blank bytes --- src/linker.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index 4da776f5..9160d7fb 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -184,23 +184,25 @@ void ElfLinker::init(const void *pdata_v, int plen) } input[inputlen] = 0; // NUL terminate - output = new upx_byte[inputlen]; + output = new upx_byte[inputlen ? inputlen : 0x4000]; outputlen = 0; - int pos = find(input, inputlen, "Sections:\n", 10); - assert(pos != -1); - char *psections = (char *) input + pos; + if ((int)strlen("Sections:\n" "SYMBOL TABLE:\n" "RELOCATION RECORDS FOR ") < inputlen) { + int pos = find(input, inputlen, "Sections:\n", 10); + assert(pos != -1); + char *psections = (char *) input + pos; - char *psymbols = strstr(psections, "SYMBOL TABLE:\n"); - assert(psymbols != NULL); + char *psymbols = strstr(psections, "SYMBOL TABLE:\n"); + assert(psymbols != NULL); - char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR "); - assert(prelocs != NULL); + char *prelocs = strstr(psymbols, "RELOCATION RECORDS FOR "); + assert(prelocs != NULL); - preprocessSections(psections, psymbols); - preprocessSymbols(psymbols, prelocs); - preprocessRelocations(prelocs, (char*) input + inputlen); - addLoader("*UND*"); + preprocessSections(psections, psymbols); + preprocessSymbols(psymbols, prelocs); + preprocessRelocations(prelocs, (char*) input + inputlen); + addLoader("*UND*"); + } } void ElfLinker::preprocessSections(char *start, char *end)