Skip to content

Commit

Permalink
kldxref: Tidy error handling for invalid addresses
Browse files Browse the repository at this point in the history
- Don't print an offset value that's always zero.

- ef_get_offset can't return -1.

Reviewed by:	imp
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D43124
  • Loading branch information
bsdjhb committed Mar 12, 2024
2 parents fa5982e + 6d46e2e commit 1659ee7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions usr.sbin/kldxref/ef.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ ef_seg_read_rel(elf_file_t ef, GElf_Addr address, size_t len, void *dest)
ofs = ef_get_offset(ef, address);
if (ofs == 0) {
if (ef->ef_verbose)
warnx("ef_seg_read_rel(%s): zero offset (%jx:%ju)",
ef->ef_name, (uintmax_t)address, (uintmax_t)ofs);
warnx("ef_seg_read_rel(%s): bad address (%jx)",
ef->ef_name, (uintmax_t)address);
return (EFAULT);
}
error = elf_read_raw_data(ef->ef_efile, ofs, dest, len);
Expand Down Expand Up @@ -591,7 +591,7 @@ ef_seg_read_string(elf_file_t ef, GElf_Addr address, size_t len, char *dest)
int error;

ofs = ef_get_offset(ef, address);
if (ofs == 0 || ofs == (GElf_Off)-1) {
if (ofs == 0) {
if (ef->ef_verbose)
warnx("ef_seg_read_string(%s): bad offset (%jx:%ju)",
ef->ef_name, (uintmax_t)address, (uintmax_t)ofs);
Expand Down

0 comments on commit 1659ee7

Please sign in to comment.