]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(10i18n): stop leaking shell options
authorMichal Hecko <mhecko@redhat.com>
Mon, 21 Feb 2022 09:59:27 +0000 (10:59 +0100)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Wed, 9 Mar 2022 04:09:53 +0000 (04:09 +0000)
The findkeymap function manipulates the shell options and relies on
restoring them using the trap. However, as the function might be called
recursively, each recursive invocation changes the signal handler to its
own. As the recursion is entered with shell options already modified,
the changed trap handler is replaced with restoration to the modified
shell options, not the original ones. This patch wraps the findkeymap
function so that the shellopts are manipulated and restored outside the
recursion.

modules.d/10i18n/module-setup.sh

index f25026fb803eef9f3d4919a8c08db10e124c3842..91c189e82520ca7db94af96d85d62a586ad3fc5a 100755 (executable)
@@ -30,11 +30,7 @@ install() {
     I18N_CONF="/etc/locale.conf"
     VCONFIG_CONF="/etc/vconsole.conf"
 
-    findkeymap() {
-        # shellcheck disable=SC2064
-        trap "$(shopt -p nullglob globstar)" RETURN
-        shopt -q -s nullglob globstar
-
+    _findkeymap() {
         local -a MAPS
         local MAPNAME
         local INCLUDES
@@ -66,12 +62,21 @@ install() {
             for INCL in "${INCLUDES[@]}"; do
                 for FN in "$dracutsysrootdir""${kbddir}"/keymaps/**/"$INCL"*; do
                     [[ -f $FN ]] || continue
-                    [[ -v KEYMAPS["$FN"] ]] || findkeymap "$FN"
+                    [[ -v KEYMAPS["$FN"] ]] || _findkeymap "$FN"
                 done
             done
         done
     }
 
+    # Wrapper around the recursive _findkeymap making sure the shell
+    # options are restored correctly
+    findkeymap() {
+        # shellcheck disable=SC2064
+        trap "$(shopt -p nullglob globstar)" RETURN
+        shopt -q -s nullglob globstar
+        _findkeymap "$@"
+    }
+
     # Function gathers variables from distributed files among the tree, maps to
     # specified names and prints the result in format "new-name=value".
     #