]> Git Repo - qemu.git/commitdiff
optionrom: fix bugs in signrom.sh
authorAvi Kivity <[email protected]>
Tue, 16 Nov 2010 14:33:17 +0000 (16:33 +0200)
committerAnthony Liguori <[email protected]>
Sun, 21 Nov 2010 15:16:57 +0000 (09:16 -0600)
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 <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
pc-bios/optionrom/signrom.sh

index 975b27dd602150f64cf4fe213225f5cf2f66f77a..9dc5c63ddec9aae0a639e2723d252bc58a9384af 100755 (executable)
@@ -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
This page took 0.026981 seconds and 4 git commands to generate.