Skip to contentSkip to conversation

optionrom: fix bugs in signrom.sh

PATCH Applied Avi Kivity 2 participants 2 messages Nov 16, 2010 – Nov 21, 2010 KVM

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 optionrom: fix bugs in signrom.sh

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.

---
 pc-bios/optionrom/signrom.sh |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
pc-bios/optionrom/signrom.sh +3 -4
index 975b27d..9dc5c63 100755
@@ -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
Signature · 1 line
1.7.3.1
#1 lore raw
Quoted 9 lines · Avi Kivity

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

Quoted 4 lines

Instead of rewriting this in half a line of python, this patch fixes the bugs.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 27 lines
---
  pc-bios/optionrom/signrom.sh |    7 +++----
  1 files changed, 3 insertions(+), 4 deletions(-)
pc-bios/optionrom/signrom.sh +3 -4
index 975b27d..9dc5c63 100755
@@ -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