Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dracut-lib.sh: quote variables in parameter expansion patterns #794

Merged
merged 1 commit into from Apr 20, 2020

Conversation

diabonas
Copy link
Contributor

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 f9c96cf, 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

luksname="$(str_replace "$luksname" '\' '\\')"

is not able to escape the backslashes any more, see #723, #727: backslashes in the systemd-cryptsetup@.service unit name stay unescaped for use in udev (cf. commit 0f6d93e), leading to failures in starting the unit.

This partially reverts commit f9c96cf.

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
f9c96cf, 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 dracutdevsGH-723, dracutdevsGH-727: backslashes in the
systemd-cryptsetup@.service unit name stay unescaped for use in udev
(cf. commit 0f6d93e), leading to
failures in starting the unit.

This partially reverts commit f9c96cf.
@centos-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@haraldh
Copy link
Collaborator

haraldh commented Apr 20, 2020

Thank you!

@haraldh haraldh merged commit 8e1a4dc into dracutdevs:master Apr 20, 2020
@diabonas diabonas deleted the quote-variables-in-patterns branch April 20, 2020 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants