From 0bcaaa7551e363a3b9154a8585d02dab8e653e9b Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Tue, 28 Nov 2023 10:32:28 +0100 Subject: [PATCH] smex: elf: fixed error handling from file operation Fixes commit #e5f337ba70a5 Signed-off-by: Adrian Bonislawski (cherry picked from commit 63f958e90c1d152136930c3f047b8d5ef90b8bf8) Signed-off-by: Kai Vehmanen --- smex/elf.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/smex/elf.c b/smex/elf.c index 53125c1d756b..eb0994530c6b 100644 --- a/smex/elf.c +++ b/smex/elf.c @@ -41,7 +41,7 @@ static int elf_read_sections(struct elf_module *module, bool verbose) if (count != hdr->shnum) { fprintf(stderr, "error: failed to read %s section header %d\n", module->elf_file, -errno); - return count < 0 ? -errno : -ENODATA; + return count > 0 ? -ENODATA : -errno; } /* read in strings */ @@ -64,7 +64,7 @@ static int elf_read_sections(struct elf_module *module, bool verbose) if (count != section[hdr->shstrndx].size) { fprintf(stderr, "error: failed to read %s strings %d\n", module->elf_file, -errno); - return count < 0 ? -errno : -ENODATA; + return count > 0 ? -ENODATA : -errno; } module->bss_index = elf_find_section(module, ".bss"); @@ -151,7 +151,7 @@ static int elf_read_programs(struct elf_module *module, bool verbose) if (count != hdr->phnum) { fprintf(stderr, "error: failed to read %s program header %d\n", module->elf_file, -errno); - return count < 0 ? -errno : -ENODATA; + return count > 0 ? -ENODATA : -errno; } /* check each program */ @@ -191,7 +191,7 @@ static int elf_read_hdr(struct elf_module *module, bool verbose) if (count != 1) { fprintf(stderr, "error: failed to read %s elf header %d\n", module->elf_file, -errno); - return count < 0 ? -errno : -ENODATA; + return count > 0 ? -ENODATA : -errno; } if (!verbose) @@ -411,7 +411,7 @@ int elf_find_section(const struct elf_module *module, const char *name) if (count != section->size) { fprintf(stderr, "error: can't read string section %d\n", -errno); - ret = count < 0 ? -errno : -ENODATA; + ret = count > 0 ? -ENODATA : -errno; goto out; } buffer[section->size - 1] = '\0';