aboutsummaryrefslogtreecommitdiffstats
path: root/squashfu
diff options
context:
space:
mode:
authorDave Reisner <d@falconindy.com>2010-06-06 16:06:13 -0400
committerDave Reisner <d@falconindy.com>2010-06-06 16:06:13 -0400
commitf2958c043c1fe73313046cbe70893f97b862a178 (patch)
treebd3409c0d24ea0c4380217d91ba9475a6ef2b7ba /squashfu
parent83c7e76eab8edfa5c9710f61f477ef53f8d91483 (diff)
downloadsquashfu-f2958c043c1fe73313046cbe70893f97b862a178.tar.gz
rollback: sanitize input. insist that the argument passed is purely numeric
Diffstat (limited to 'squashfu')
-rwxr-xr-xsquashfu10
1 files changed, 4 insertions, 6 deletions
diff --git a/squashfu b/squashfu
index b724458..a993790 100755
--- a/squashfu
+++ b/squashfu
@@ -290,19 +290,17 @@ action_rollback () {
# Returns: none
[[ $UID -ne 0 ]] && die "Must be root to perform a rollback"
-
- # Validate input with test cases
- [[ -z $1 ]] && die "The rollback action requires 1 additional argument."
+ [[ ! $1 =~ ^[0-9]*$ ]] && die "Invalid argument. Parameter must be a number."
# Form a chronologically ordered list of bins, assuming the user didn't give bogus input
- local bin_list=($(grep -vE "^[ \t]*$" "$BINVENTORY" | sort -t: -r -n -k2 | cut -d: -f1))
+ local bin_list=($(sed -n 's/[\t\ ]*\([0-9]*\):.*/\1/p' "$BINVENTORY"))
[[ $1 -gt ${#bin_list[@]} ]] && die "Cannot rollback more than ${#bin_list[@]} backups"
local num_to_mount=$(( ${#bin_list[@]} - $1 ))
- mountpoint "$UNION_MOUNT" &>/dev/null && unmount_union
- mountpoint "$SQUASH_MOUNT" &>/dev/null || mount_squash
+ mountpoint -q "$UNION_MOUNT" && unmount_union
+ mountpoint -q "$SQUASH_MOUNT" || mount_squash
mount_union_with_bins ${bin_list[@]:(-$num_to_mount)}