Blob Blame History Raw
From a6984b52a7194d2b4a0007af74659f3a5fd2c9ed Mon Sep 17 00:00:00 2001
From: Pavel Valena <pvalena@redhat.com>
Date: Fri, 25 Mar 2022 17:26:19 +0100
Subject: [PATCH] fix(10i18n): stop leaking shell options

Avoid using shell options in findkeymap, instead of using a wrapper[*]
to restore the previous options. Using mapfile and find to generate the list
of files also has the benefit of being more readable in this case.

[*] Reverted commit 35064768ebf14d3ec6bf3f7df52580fb4920ea3d
Original issue description from Michal Hecko <mhecko@redhat.com>:

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.

Resolves: #2047654
---
 modules.d/10i18n/module-setup.sh | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/modules.d/10i18n/module-setup.sh b/modules.d/10i18n/module-setup.sh
index f25026fb..35bda36f 100755
--- a/modules.d/10i18n/module-setup.sh
+++ b/modules.d/10i18n/module-setup.sh
@@ -31,10 +31,6 @@ install() {
     VCONFIG_CONF="/etc/vconsole.conf"
 
     findkeymap() {
-        # shellcheck disable=SC2064
-        trap "$(shopt -p nullglob globstar)" RETURN
-        shopt -q -s nullglob globstar
-
         local -a MAPS
         local MAPNAME
         local INCLUDES
@@ -46,7 +42,10 @@ install() {
             MAPS=("$1")
         else
             MAPNAME=${1%.map*}
-            MAPS=("$dracutsysrootdir""${kbddir}"/keymaps/**/"${MAPNAME}"{,.map{,.*}})
+
+            mapfile -t -d '' MAPS < <(
+                find "${dracutsysrootdir}${kbddir}"/keymaps/ -type f \( -name "${MAPNAME}" -o -name "${MAPNAME}.map*" \) -print0
+            )
         fi
 
         for MAP in "${MAPS[@]}"; do