]> git.ipfire.org Git - thirdparty/dracut.git/commit
dracut-lib.sh: quote variables in parameter expansion patterns
authorJonas Witschel <diabonas@archlinux.org>
Sat, 18 Apr 2020 12:55:41 +0000 (14:55 +0200)
committerHarald Hoyer <harald@hoyer.xyz>
Mon, 20 Apr 2020 12:59:02 +0000 (14:59 +0200)
commit8e1a4dc5f8a777fc718db490414ffdc9dc755f66
treedf937a21b6f5ab3650f120d5e4324429223da2a8
parent25c7a13985473ff9714245eaa602225b1a0f9ecb
dracut-lib.sh: quote variables in parameter expansion patterns

According to POSIX.1-2017, 2.6.2 Parameter Expansion:

${parameter%[word]} [...] The word shall be expanded to produce a
pattern.

This means if word contains variables that itself contain special
characters like asterisks or backslashes, these are treated as pattern
characters unless the variable is quoted. Try e.g. the following example
in bash, dash or (busybox) ash:

i='a\c'; j='\'; echo "${i%$j*}"

This prints "a\c" because "$j*" is expanded to "\*", escaping the
asterisk. In contrast,

i='a\c'; j='\'; echo "${i%"$j"*}"

produces the expected result "a" because the backslash is not specially
treated any more after quoting.

The quotes that this commit adds have been previously removed in commit
f9c96cf56fed390841eac05c43826e62014c9188, citing issues with busybox
hush without further specifying the actual error. I tested a recent
busybox build (upstream commit 9aa751b08ab03d6396f86c3df77937a19687981b)
and couldn't find any problems. Note that the above example always
produces "a\c" in hush regardless of quoting $j, making hush unsuitable
for use with dracut, but using quotes in parameter expansions generally
works.

The unquoted variables break the "rd.luks.uuid/name" kernel command line
options in dracut 050 because

str_replace "$luksname" '\' '\\'

in modules.d/90crypt/parse-crypt.sh is not able to escape the
backslashes any more, see GH-723, GH-727: backslashes in the
systemd-cryptsetup@.service unit name stay unescaped for use in udev
(cf. commit 0f6d93eb9d63695a64002ec8b0421fbc9fc8a7a3), leading to
failures in starting the unit.

This partially reverts commit f9c96cf56fed390841eac05c43826e62014c9188.
modules.d/99base/dracut-lib.sh