From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=49025 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PKBhk-0005NE-F9 for qemu-devel@nongnu.org; Sun, 21 Nov 2010 10:19:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PKBhj-0004Ow-CS for qemu-devel@nongnu.org; Sun, 21 Nov 2010 10:19:48 -0500 Received: from mail-yx0-f173.google.com ([209.85.213.173]:63390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PKBhj-0004Oo-8i for qemu-devel@nongnu.org; Sun, 21 Nov 2010 10:19:47 -0500 Received: by yxs7 with SMTP id 7so769550yxs.4 for ; Sun, 21 Nov 2010 07:19:46 -0800 (PST) Message-ID: <4CE9388E.4050804@codemonkey.ws> Date: Sun, 21 Nov 2010 09:19:42 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] optionrom: fix bugs in signrom.sh References: <1289917997-27429-1-git-send-email-avi@redhat.com> In-Reply-To: <1289917997-27429-1-git-send-email-avi@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org On 11/16/2010 08:33 AM, Avi Kivity wrote: > signrom.sh has multiple bugs: > > - the last byte is considered when calculating the existing checksum, but not > when computing the correction > - apprently the 'expr' expression overflows and produces incorrect results with > larger roms > - if the checksum happened to be zero, we calculated the correction byte to be > 256 > > Instead of rewriting this in half a line of python, this patch fixes the bugs. > > Signed-off-by: Avi Kivity > Applied. Thanks. Regards, Anthony Liguori > --- > pc-bios/optionrom/signrom.sh | 7 +++---- > 1 files changed, 3 insertions(+), 4 deletions(-) > > diff --git a/pc-bios/optionrom/signrom.sh b/pc-bios/optionrom/signrom.sh > index 975b27d..9dc5c63 100755 > --- a/pc-bios/optionrom/signrom.sh > +++ b/pc-bios/optionrom/signrom.sh > @@ -31,14 +31,13 @@ x=`dd if="$1" bs=1 count=1 skip=2 2>/dev/null | od -t u1 -A n` > size=$(( $x * 512 - 1 )) > > # now get the checksum > -nums=`od -A n -t u1 -v "$1"` > +nums=`od -A n -t u1 -v -N $size "$1"` > for i in ${nums}; do > # add each byte's value to sum > - sum=`expr $sum + $i` > + sum=`expr \( $sum + $i \) % 256` > done > > -sum=$(( $sum % 256 )) > -sum=$(( 256 - $sum )) > +sum=$(( (256 - $sum) % 256 )) > sum_octal=$( printf "%o" $sum ) > > # and write the output file >