Skip to content

Commit

Permalink
smex: elf: fixed error handling from file operation
Browse files Browse the repository at this point in the history
Fixes commit #e5f337ba70a5

Signed-off-by: Adrian Bonislawski <[email protected]>
  • Loading branch information
abonislawski committed Nov 28, 2023
1 parent 7ac7fa2 commit 84ed076
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions smex/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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");
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 84ed076

Please sign in to comment.