git: 6d46e2e0a7f3 - main - kldxref: Tidy error handling for invalid addresses

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 22 Dec 2023 15:50:10 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=6d46e2e0a7f345459fb42e666c7cb2e987c70857

commit 6d46e2e0a7f345459fb42e666c7cb2e987c70857
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-12-22 15:48:47 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-12-22 15:48:47 +0000

    kldxref: Tidy error handling for invalid addresses
    
    - 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
---
 usr.sbin/kldxref/ef.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/kldxref/ef.c b/usr.sbin/kldxref/ef.c
index aa9123d7f540..46d3dc1f4578 100644
--- a/usr.sbin/kldxref/ef.c
+++ b/usr.sbin/kldxref/ef.c
@@ -512,8 +512,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);
@@ -542,7 +542,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);