]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(lsinitrd.sh): handle filenames with special characters
authorAntonio Alvarez Feijoo <antonio.feijoo@suse.com>
Wed, 4 Jan 2023 15:51:12 +0000 (16:51 +0100)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Tue, 31 Jan 2023 07:44:57 +0000 (08:44 +0100)
Printing and unpacking of specific files passed as arguments does not work if
their filenames contain special characters with a hexadecimal character escape
(\x), which is often the case for systemd device units.

lsinitrd.sh

index eaadc7623fefb2428e1f200b4305a025bea4130b..b6f436cb468a3c9442348deb5d4b4c35a2ea70f1 100755 (executable)
@@ -176,6 +176,8 @@ extract_files() {
     for f in "${!filenames[@]}"; do
         [[ $nofileinfo ]] || echo "initramfs:/$f"
         [[ $nofileinfo ]] || echo "========================================================================"
+        # shellcheck disable=SC2001
+        [[ $f == *"\\x"* ]] && f=$(echo "$f" | sed 's/\\x.\{2\}/????/g')
         $CAT "$image" 2> /dev/null | cpio --extract --verbose --quiet --to-stdout "$f" 2> /dev/null
         ((ret += $?))
         [[ $nofileinfo ]] || echo "========================================================================"
@@ -219,7 +221,9 @@ list_squash_content() {
 unpack_files() {
     if ((${#filenames[@]} > 0)); then
         for f in "${!filenames[@]}"; do
-            $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose $f
+            # shellcheck disable=SC2001
+            [[ $f == *"\\x"* ]] && f=$(echo "$f" | sed 's/\\x.\{2\}/????/g')
+            $CAT "$image" 2> /dev/null | cpio -id --quiet $verbose "$f"
             ((ret += $?))
         done
     else