From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 29 20:04:18 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2AC6410656A8 for ; Sun, 29 Aug 2010 20:04:18 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 83C468FC0C for ; Sun, 29 Aug 2010 20:04:17 +0000 (UTC) Received: by bwz20 with SMTP id 20so3866298bwz.13 for ; Sun, 29 Aug 2010 13:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type; bh=ALOROuIMF6zv0GmIvejXUZY7sqUfGrDieqbaR+fc/FQ=; b=bWHmlFpQhq6VLga6hPHc6bd3Gh/IG8+amaU3u5HQSZ0HS0j0j3+k5Mf5lkgjPJXVoQ /6hvqnwAq4+Rv7izb0ELxzvrbWlZ3IotzFNmXThLChaWfR77iq4p/CuwFWFvQ+gH3mOY y3uGVeDF6lZ1x6H9pMJEIFlDp7VTfgn9t+ZkM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=DOHMOyzFDkRL4dulHB4YnZLWeiy8qHq/+kVFhAiykMj5+aUiFiWg+ZOna0anq2neiv aIzWbR+EOAtoDVe0GgxycpgYLhmwgTxGsw7/e8K0E68j+aPlD01PoF2LFRMbGI0jhTDY bG3D2sOlQxDKLMmDVuHpyEoPKvWoHbyd3Byfw= MIME-Version: 1.0 Received: by 10.204.57.9 with SMTP id a9mr2531819bkh.104.1283112256396; Sun, 29 Aug 2010 13:04:16 -0700 (PDT) Sender: yanegomi@gmail.com Received: by 10.204.113.79 with HTTP; Sun, 29 Aug 2010 13:04:16 -0700 (PDT) In-Reply-To: <20100829162707.GA98059@freebsd.org> References: <20100829162707.GA98059@freebsd.org> Date: Sun, 29 Aug 2010 13:04:16 -0700 X-Google-Sender-Auth: UORUF1Pemj4m1E8qe91aiZJf9w0 Message-ID: From: Garrett Cooper To: Alexander Best Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-hackers@freebsd.org Subject: Re: 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 20:04:18 -0000 On Sun, Aug 29, 2010 at 9:27 AM, Alexander Best wrote: > 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. :) Lest they forget that they code was originally BSD licensed, not GPLv2 (except for new source I suppose)... According to the manpage... -s offset Skip offset bytes from the beginning of the input. By default, offset is interpreted as a decimal number. With a leading 0x or 0X, offset is interpreted as a hexadecimal number, otherwise, with a leading 0, offset is interpreted as an octal number. Appending the character b, k, or m to offset causes it to be interpreted as a multiple of 512, 1024, or 1048576, respectively. ... I would expect the following output: 1. -s 41 -> one byte displayed. 2. -s 42 -> no bytes displayed. 2. -s 43 -> no bytes displayed. This is the case with your patch alone, but with the another patch I posted (see bin/118723), it's completely broken, so there might be an issue with the proposed change on either end. The logic in hexdump is in serious need of fixing because there are tons of cornercases like this in the code. Thanks, -Garrett