From patchwork Tue Nov 16 14:33:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 71407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 79D17B713B for ; Wed, 17 Nov 2010 01:36:08 +1100 (EST) Received: from localhost ([127.0.0.1]:54454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PIMdR-0007Wp-H9 for incoming@patchwork.ozlabs.org; Tue, 16 Nov 2010 09:35:49 -0500 Received: from [140.186.70.92] (port=37781 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PIMbH-0006nc-PM for qemu-devel@nongnu.org; Tue, 16 Nov 2010 09:33:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PIMb2-0000lC-M1 for qemu-devel@nongnu.org; Tue, 16 Nov 2010 09:33:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37748) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PIMb2-0000l4-FA for qemu-devel@nongnu.org; Tue, 16 Nov 2010 09:33:20 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oAGEXJaX005062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 16 Nov 2010 09:33:19 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oAGEXIph004158; Tue, 16 Nov 2010 09:33:19 -0500 Received: from file.tlv.redhat.com (file.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id BAC8C25005B; Tue, 16 Nov 2010 16:33:17 +0200 (IST) From: Avi Kivity To: qemu-devel@nongnu.org Date: Tue, 16 Nov 2010 16:33:17 +0200 Message-Id: <1289917997-27429-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Marcelo Tosatti , kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH] optionrom: fix bugs in signrom.sh X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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