From 1232c7884d4a9bc69d4dd71cd293f92bb1ae6197 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Wed, 7 Jun 2023 18:06:07 -0700 Subject: [PATCH] od(1): Fix skip value handling POSIX defines -j as the number of bytes that od(1) should skip over the concatenated input files. The existing code tries to implement this behavior by checking if the current address was smaller than the skip value. However, this is not correct, because we adjust both the skip value and the address at the same time when we do fseeko (when file is seekable) or getchar (when file is not seekable). This commit fixes the problem by expecting the skip value to be zero upon return of next(). If the condition is not satisfied, a diagnostic message will be issued. Reported-by: Mohamed Akram Reviewed-by: emaste PR: 271832 MFC-after: 2 weeks Differential Revision: https://reviews.freebsd.org/D40446 --- usr.bin/hexdump/display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c index cad548e1ec41..36306ededfc6 100644 --- a/usr.bin/hexdump/display.c +++ b/usr.bin/hexdump/display.c @@ -263,7 +263,7 @@ get(void) * block and set the end flag. */ if (!length || (ateof && !next((char **)NULL))) { - if (odmode && address < skip) + if (odmode && skip > 0) errx(1, "cannot skip past end of input"); if (need == blocksize) return((u_char *)NULL);