From f2958c043c1fe73313046cbe70893f97b862a178 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 6 Jun 2010 16:06:13 -0400 Subject: rollback: sanitize input. insist that the argument passed is purely numeric --- squashfu | 10 ++++------ 1 file 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)} -- cgit v1.2.3