[parted-devel]
t1100: protect against a device name containing e.g., a space
Jim Meyering
jim at meyering.net
Fri May 11 16:29:15 UTC 2007
* tests/t1100-busy-label.sh: Quote uses of $dev, in case
the user's device name contains a shell meta-character.
diff --git a/tests/t1100-busy-label.sh b/tests/t1100-busy-label.sh
index e7bbbfa..b1f1659 100755
--- a/tests/t1100-busy-label.sh
+++ b/tests/t1100-busy-label.sh
@@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
-test_description='partitioning (parted -s $dev mklabel) a busy disk must fail.'
+test_description='partitioning (parted -s DEV mklabel) a busy disk must fail.'
privileges_required_=1
erasable_device_required_=1
@@ -27,15 +27,15 @@ dev=$DEVICE_TO_ERASE
test_expect_success \
"setup: create a fat32 file system on $dev" \
- 'dd if=/dev/zero of=$dev bs=1k count=1 2> /dev/null &&
- parted -s $dev mklabel msdos > out 2>&1 &&
- parted -s $dev mkpartfs primary fat32 1 40 >> out 2>&1'
+ 'dd if=/dev/zero "of=$dev" bs=1k count=1 2> /dev/null &&
+ parted -s "$dev" mklabel msdos > out 2>&1 &&
+ parted -s "$dev" mkpartfs primary fat32 1 40 >> out 2>&1'
test_expect_success 'expect no output' '$compare out /dev/null'
mount_point="`pwd`/mnt"
# Be sure to unmount upon interrupt, failure, etc.
-cleanup_() { umount ${dev}1 > /dev/null 2>&1; }
+cleanup_() { umount "${dev}1" > /dev/null 2>&1; }
# There's a race condition here: on udev-based systems, the partition#1
# device, ${dev}1 (i.e., /dev/sdd1) is not created immediately, and
@@ -44,13 +44,13 @@ cleanup_() { umount ${dev}1 > /dev/null 2>&1; }
test_expect_success \
'create mount point dir. and mount the just-created partition on it' \
'mkdir $mount_point &&
- i=0; while :; do test -e ${dev}1 && break; test $i = 90 && break;
+ i=0; while :; do test -e "${dev}1" && break; test $i = 90 && break;
i=$(expr $i + 1); done;
- mount ${dev}1 $mount_point'
+ mount "${dev}1" $mount_point'
test_expect_failure \
'now that a partition is mounted, mklabel attempt must fail' \
- 'parted -s $dev mklabel msdos > out 2>&1'
+ 'parted -s "$dev" mklabel msdos > out 2>&1'
test_expect_success \
'create expected output file' \
'echo "Error: Partition(s) on $dev are being used." > exp'
@@ -63,7 +63,7 @@ test_expect_success \
test_expect_success 'create input file' 'echo c > in'
test_expect_failure \
'as above, this mklabel attempt must fail' \
- 'parted ---pretend-input-tty $dev mklabel msdos < in > out 2>&1'
+ 'parted ---pretend-input-tty "$dev" mklabel msdos < in > out 2>&1'
fail=0
cat <<EOF > exp || fail=1
More information about the parted-devel
mailing list