From: Américo Wang Date: Thu, 26 Nov 2009 14:19:37 +0000 (+0800) Subject: hexdump: bug in hexdump when offset == file length X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c9f0e8e7f4c8049ecc259712c618ee75d94409d;p=util-linux hexdump: bug in hexdump when offset == file length On Thu, Nov 26, 2009 at 03:42:21AM -0500, Mike Smith wrote: >[mike@laptop ~]$ dd if=/dev/urandom of=testfile bs=1 count=42 >42+0 records in >42+0 records out >42 bytes (42 B) copied, 0.000216179 s, 194 kB/s >[mike@laptop ~]$ hexdump -Cv testfile -s 42 >0000002a bb b0 ba 50 fe 70 f8 d9 f7 96 36 49 e9 74 c7 bd |...P.p....6I.t..| >0000003a 82 cb 19 64 a6 30 53 29 d2 fa 08 e3 f4 26 7f de |...d.0S).....&..| >0000004a bb 2c f2 df 7c a7 8c 6e 66 01 |.,..|..nf.| >00000054 >[mike@laptop ~]$ hexdump -Cv testfile -s 43 >0000002a I think I got where the bug is, it's an off-by-one problem... Signed-off-by: WANG Cong --- diff --git a/text-utils/display.c b/text-utils/display.c index 91857c2f..7a35e46f 100644 --- a/text-utils/display.c +++ b/text-utils/display.c @@ -336,7 +336,7 @@ doskip(const char *fname, int statok) fname, strerror(errno)); exit(1); } - if (S_ISREG(sbuf.st_mode) && skip >= sbuf.st_size) { + if (S_ISREG(sbuf.st_mode) && skip > sbuf.st_size) { /* If size valid and skip >= size */ skip -= sbuf.st_size; address += sbuf.st_size;