From 74b2731f2cef0f1ec8c0c6e6e3dee9492b851e8c Mon Sep 17 00:00:00 2001 From: "Chang S. Bae" Date: Tue, 21 Apr 2020 09:23:39 +0000 Subject: [PATCH] outelf: Fix the section index for the debug output The section information delivered to the debug output has an index of the section table. The index should be different from the total number of sections at the moment, the returned value from add_sectname(). So, fix the value. Fixes: b2004511ddde ("ELF: handle more than 32,633 sections") Reported-by: C. Masloch Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392654 Reported-by: Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392661 Signed-off-by: Chang S. Bae --- output/outelf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/output/outelf.c b/output/outelf.c index 4976b680..18b52d88 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -1108,7 +1108,8 @@ static void elf32_out(int32_t segto, const void *data, /* again some stabs debugging stuff */ sinfo.offset = s->len; - sinfo.section = s->shndx; + /* Adjust to an index of the section table. */ + sinfo.section = s->shndx - 1; sinfo.segto = segto; sinfo.name = s->name; dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); @@ -1312,7 +1313,8 @@ static void elf64_out(int32_t segto, const void *data, /* again some stabs debugging stuff */ sinfo.offset = s->len; - sinfo.section = s->shndx; + /* Adjust to an index of the section table. */ + sinfo.section = s->shndx - 1; sinfo.segto = segto; sinfo.name = s->name; dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo); @@ -1592,7 +1594,8 @@ static void elfx32_out(int32_t segto, const void *data, /* again some stabs debugging stuff */ sinfo.offset = s->len; - sinfo.section = s->shndx; + /* Adjust to an index of the section table. */ + sinfo.section = s->shndx - 1; sinfo.segto = segto; sinfo.name = s->name; dfmt->debug_output(TY_DEBUGSYMLIN, &sinfo);