Skip to content

Commit 22a8062

Browse files
rmetrichjohannbg
authored andcommitted
fix(dracut): be more robust when using 'set -u'
From bash manpage, FUNCNAME exists only inside functions. When in debug mode, make sure to use an empty default value as FUNCNAME[0] when outside of functions. With bash4 this wasn't an issue, but is with bash5 with hardening option 'set -u' used, as shown in the example below: Incorrect: $ bash -u -c 'echo -n ${FUNCNAME[0]}' bash: line 1: FUNCNAME[0]: unbound variable $ Correct: $ bash -u -c 'echo -n ${FUNCNAME[0]-}' $ This hardening enables sourcing dracut-lib.sh from external utilities executing in the initramfs such as clevis-luks-askpass, which uses hardening option 'set -u' internally. (see Clevis PR latchset/clevis#340) Signed-off-by: Renaud Métrich <[email protected]>
1 parent c5907f8 commit 22a8062

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

dracut.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ unset GREP_OPTIONS
882882
export DRACUT_LOG_LEVEL=warning
883883
[[ $debug ]] && {
884884
export DRACUT_LOG_LEVEL=debug
885-
export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
885+
export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
886886
set -x
887887
}
888888

modules.d/99base/dracut-lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ setdebug() {
392392
if getargbool 0 rd.debug -d -y rdinitdebug -d -y rdnetdebug; then
393393
RD_DEBUG=yes
394394
[ -n "$BASH" ] \
395-
&& export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
395+
&& export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]-}): '
396396
fi
397397
fi
398398
export RD_DEBUG

0 commit comments

Comments
 (0)