From 13864e43c05d921cdbcb3ae80e237ddbb71242b6 Mon Sep 17 00:00:00 2001 From: Turbo Fredriksson Date: Sun, 4 Oct 2015 14:31:57 +0200 Subject: [PATCH] Some minor fixes to the initramfs script (2/3). * Set and reset IFS in read_{mtab,fstab}() and recursive_mount_filesystems(). * Setup local ALL variables in read_fstab(). * Protect the variable set in read_{fstab,mtab}() in quotes. Signed-off-by: Turbo Fredriksson --- contrib/shell-common/zfs-functions.in | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/contrib/shell-common/zfs-functions.in b/contrib/shell-common/zfs-functions.in index ee2b51c8e6d2..8f204d348a9c 100644 --- a/contrib/shell-common/zfs-functions.in +++ b/contrib/shell-common/zfs-functions.in @@ -405,7 +405,9 @@ recursive_mount_filesystems() # Go through the complete list (recursivly) of all filesystems # below the first (root) dataset. + zfs_set_ifs " " filesystems="$("${ZFS}" list -oname -tfilesystem -H -r "${fs}")" + zfs_set_ifs "${OLD_IFS}" for f in ${filesystems} ${ZFS_INITRD_ADDITIONAL_DATASETS} do # Ignore the first (root) fs. Should already be @@ -428,6 +430,8 @@ read_mtab() local match="$1" local fs mntpnt fstype opts rest TMPFILE + zfs_set_ifs "${OLD_IFS}" + # Unset all MTAB_* variables unset $(env | grep ^MTAB_ | sed 's,=.*,,') @@ -449,9 +453,11 @@ read_mtab() fs=$(printf '%b\n' "$fs") # Set the variable. - eval export MTAB_$mntpnt=\"$fs\" + eval export MTAB_$mntpnt="\"$fs\"" fi done < /proc/mounts + + zfs_set_ifs "${TMP_IFS}" } # Check if specified filesystem is mounted. @@ -472,7 +478,9 @@ in_mtab() read_fstab() { local match="$1" - local i var TMPFILE + local i var TMPFILE fs mntpnt fstype opts + + zfs_set_ifs "${OLD_IFS}" # Unset all FSTAB_* variables unset $(env | grep ^FSTAB_ | sed 's,=.*,,') @@ -482,13 +490,15 @@ read_fstab() echo "$fs" | egrep -qE '^#|^$' && continue if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then - eval export FSTAB_dev_$i="$fs" + eval export FSTAB_dev_$i="\"$fs\"" fs=$(printf '%b\n' "$fs" | sed 's,/,_,g') - eval export FSTAB_$i="$mntpnt" + eval export FSTAB_$i="\"$mntpnt\"" i=$((i + 1)) fi done < /etc/fstab + + zfs_set_ifs "${TMP_IFS}" } # Check to see if specified filesystem is in fstab