Package: sg3-utils
Version: 1.42-2
Severity: normal
Tags: patch

thanks

Using rescan-scsi-bus.sh is scary enough at the best of times,
but when it prints things like this it's even scarier

  /usr/bin/rescan-scsi-bus.sh: line 257: test: !=: unary operator expected

That line reads
    257   if test $ctr != 0; then white_out; fi

and comes right after a loop with this loop condition
    245   while test $RC = 2 -o $RC = 6 && test $ctr -le 30; do

In the enclosing function (testonline), nothing initialises $ctr ;
it is only updated within the loop
    248     let ctr+=1

Given this situation, the loop condition at line 245 always fails
(on the second test) and the code jumps to line 257, where $ctr
is still not defined.

This patch initialises $ctr and appears to make the code run as
intended. The only question is whether 0 is the right starting value.

diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh
index e45caf3..fa8c1ae 100755
--- a/scripts/rescan-scsi-bus.sh
+++ b/scripts/rescan-scsi-bus.sh
@@ -242,6 +242,7 @@ testonline ()
   RC=$?
 
   # Handle in progress of becoming ready and unit attention
+  local ctr=0
   while test $RC = 2 -o $RC = 6 && test $ctr -le 30; do
     if test $RC = 2 -a "$RMB" != "1"; then echo -n "."; let LN+=1; sleep 1
     else sleep 0.02; fi

Kind regards
Vince

Reply via email to