Skip to content

Commit 878ec37

Browse files
authored
Escape ZFS args (#1222)
Args to ZFS (like mountpoints) might have spaces or other shell-unfriendly characters in them. This escapes those so they get passed to zfs correctly.
2 parents c4d34f2 + dff80bb commit 878ec37

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

lib/types/zfs_fs.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@
9191
updateOptions = builtins.removeAttrs createOptions onetimeProperties;
9292
in
9393
''
94-
if ! zfs get type ${config._name} >/dev/null 2>&1; then
94+
if ! zfs get type "${config._name}" >/dev/null 2>&1; then
9595
${
9696
if config._createFilesystem then
9797
''
98-
zfs create -up ${config._name} \
99-
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") (createOptions))}
98+
zfs create -up "${config._name}" \
99+
${lib.concatStringsSep " " (
100+
lib.mapAttrsToList (n: v: "-o ${n}=${lib.escapeShellArg v}") (createOptions)
101+
)}
100102
''
101103
else
102104
''
@@ -107,8 +109,8 @@
107109
${lib.optionalString (updateOptions != { }) ''
108110
else
109111
zfs set -u ${
110-
lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)
111-
} ${config._name}
112+
lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${lib.escapeShellArg v}") updateOptions)
113+
} "${config._name}"
112114
''}
113115
fi
114116
'';

lib/types/zfs_volume.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@
6363
default = ''
6464
if ! zfs get type "${config._parent.name}/${config.name}" >/dev/null 2>&1; then
6565
zfs create "${config._parent.name}/${config.name}" \
66-
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
66+
${
67+
lib.concatStringsSep " " (
68+
lib.mapAttrsToList (n: v: "-o ${n}=${lib.escapeShellArg v}") config.options
69+
)
70+
} \
6771
-V ${config.size} ${toString (builtins.map lib.escapeShellArg config.extraArgs)}
6872
zvol_wait
6973
partprobe "/dev/zvol/${config._parent.name}/${config.name}"

lib/types/zpool.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,16 @@ in
377377
else
378378
""
379379
} \
380-
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
381-
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
380+
${
381+
lib.concatStringsSep " " (
382+
lib.mapAttrsToList (n: v: "-o ${n}=${lib.escapeShellArg v}") config.options
383+
)
384+
} \
385+
${
386+
lib.concatStringsSep " " (
387+
lib.mapAttrsToList (n: v: "-O ${n}=${lib.escapeShellArg v}") config.rootFsOptions
388+
)
389+
} \
382390
''${topology:+ $topology}
383391
if [[ $(zfs get -H mounted "${config.name}" | cut -f3) == "yes" ]]; then
384392
zfs unmount "${config.name}"

0 commit comments

Comments
 (0)