From 985b390ba22f4229aeca9f02e273a54eb4a76a9a Mon Sep 17 00:00:00 2001 From: sys64738 Date: Thu, 19 May 2022 01:16:32 +0200 Subject: [PATCH] elf32: don't load sections with size zero --- formats/elf32.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/formats/elf32.c b/formats/elf32.c index 49a073c..07035a1 100644 --- a/formats/elf32.c +++ b/formats/elf32.c @@ -247,8 +247,10 @@ static int feed_section(struct elf32_info *info, ch.data = buf; ch.len = len; - if (cb(user_data, &ch) < 0) + if (cb(user_data, &ch) < 0) { + pr_error("elf32: misc error"); return -1; + } size -= len; offset += len; @@ -331,7 +333,7 @@ int elf32_extract(FILE *in, binfile_imgcb_t cb, void *user_data) Elf32_Shdr *s = &info.file_shdrs[i]; if ((s->sh_type == SHT_PROGBITS || s->sh_type == SHT_INIT_ARRAY) && - s->sh_flags & SHF_ALLOC && + (s->sh_flags & SHF_ALLOC) && s->sh_size > 0 && feed_section(&info, in, s, cb, user_data) < 0) { ret = -1; break;