From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 29 16:27:07 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id F1B791065675; Sun, 29 Aug 2010 16:27:07 +0000 (UTC) Date: Sun, 29 Aug 2010 16:27:07 +0000 From: Alexander Best To: freebsd-hackers@freebsd.org Message-ID: <20100829162707.GA98059@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="KsGdsel6WgEHnImy" Content-Disposition: inline Subject: hexdump(1)/od(1) skip function off-by-one when offset == file length X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 29 Aug 2010 16:27:08 -0000 --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline just discovered this issue while going through some linux mailinglists: otaku% dd if=/dev/urandom of=testfile bs=1 count=42 42+0 records in 42+0 records out 42 bytes transferred in 0.000393 secs (106894 bytes/sec) otaku% hexdump -s 42 testfile 000002a 134d b7b9 e085 da16 63b0 554a 1603 ead0 000003a 4bd1 fbfd c329 b606 e592 1377 6e10 4b9d 000004a c018 0fc9 ebf4 9ae2 9f1a 0000054 otaku% hexdump -s 43 testfile 000002a otaku% hexdump -s 41 testfile 0000029 009f 000002a the attached patch fixes this issue for HEAD. i also checked out any license issues which could pop up. this fix comes from the util-linux-ng repository [1] which seems entirely GPLv2'ed. :) cheers. alex [1] http://git.kernel.org/?p=utils/util-linux-ng/util-linux-ng.git;a=tree;hb=HEAD ps: no fix for od(1) necessary since it's simply a hardlink to hexdump(1). ;) -- a13x --KsGdsel6WgEHnImy Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="display.c.patch" diff --git a/usr.bin/hexdump/display.c b/usr.bin/hexdump/display.c index db04c49..3e3d903 100644 --- a/usr.bin/hexdump/display.c +++ b/usr.bin/hexdump/display.c @@ -378,7 +378,7 @@ doskip(const char *fname, int statok) if (statok) { if (fstat(fileno(stdin), &sb)) err(1, "%s", fname); - if (S_ISREG(sb.st_mode) && skip >= sb.st_size) { + if (S_ISREG(sb.st_mode) && skip > sb.st_size) { address += sb.st_size; skip -= sb.st_size; return; --KsGdsel6WgEHnImy--