From 9cecd7eb47812183a8b0c1ae173525b06c5179e1 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Mon, 3 Nov 2025 15:11:38 +0800 Subject: [PATCH] Strip surrounding quotes from configuration values Resolves: RHEL-117011 Upstream: kdump-utils Conflict: None Signed-off-by: Lichen Liu --- ...ing-quotes-from-configuration-values.patch | 77 +++++++++++++++++++ ...case-for-quoted-configuration-values.patch | 45 +++++++++++ kdump-utils.spec | 2 + 3 files changed, 124 insertions(+) create mode 100644 0001-Strip-surrounding-quotes-from-configuration-values.patch create mode 100644 0002-unit-tests-Add-case-for-quoted-configuration-values.patch diff --git a/0001-Strip-surrounding-quotes-from-configuration-values.patch b/0001-Strip-surrounding-quotes-from-configuration-values.patch new file mode 100644 index 0000000..4582341 --- /dev/null +++ b/0001-Strip-surrounding-quotes-from-configuration-values.patch @@ -0,0 +1,77 @@ +From 1a733872aeab1d1dcc0b063cd05afe61bbeb1c33 Mon Sep 17 00:00:00 2001 +From: Lichen Liu +Date: Tue, 14 Oct 2025 11:30:29 +0800 +Subject: [PATCH 1/2] Strip surrounding quotes from configuration values + +The documentation for kdump.conf suggests values can be enclosed in +double quotes, as in 'core_collector "makedumpfile -l --message-level 7 -d 31"'. + +However, the parsing logic did not strip these quotes, causing the +system to treat them as part of the value. This led to errors, such +as attempting to execute the command '"makedumpfile', which would +fail with a "command not found" error. + +``` +kdump.sh[599]: /lib/kdump-lib-initramfs.sh: line 145: "makedumpfile: command not found +kdump[601]: saving vmcore failed, _exitcode:127 +kdump[603]: saving the /run/initramfs/kexec-dmesg.log to /sysroot//var/crash/127.0.0.1-2025-09-17-19:25:10/ +kdump[609]: saving vmcore failed +[FAILED] Failed to start Kdump Vmcore Save Service. +``` + +This patch fixes the issue by removing surrounding double quotes from +configuration values when they are read. This ensures that quoted +values are handled correctly and behave as documented. + +Signed-off-by: Lichen Liu +--- + dracut/99kdumpbase/module-setup.sh | 2 +- + kdump-lib-initramfs.sh | 5 +++-- + kdumpctl | 1 + + 3 files changed, 5 insertions(+), 3 deletions(-) + +diff --git a/dracut/99kdumpbase/module-setup.sh b/dracut/99kdumpbase/module-setup.sh +index 1c223ed..4dc11ac 100755 +--- a/dracut/99kdumpbase/module-setup.sh ++++ b/dracut/99kdumpbase/module-setup.sh +@@ -719,7 +719,7 @@ kdump_install_conf() { + kdump_read_conf > "${initdir}/tmp/$$-kdump.conf" + + while read -r _opt _val; do +- # remove inline comments after the end of a directive. ++ [[ $_val == \"*\" ]] && _val=${_val:1:-1} + case "$_opt" in + raw) + _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") +diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh +index 558295a..c4bc6d2 100755 +--- a/kdump-lib-initramfs.sh ++++ b/kdump-lib-initramfs.sh +@@ -29,9 +29,10 @@ kdump_read_conf() + kdump_get_conf_val() + { + # For lines matching "^\s*$1\s+", remove matched part (config name including space), +- # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. ++ # remove tailing comment, space and the surrounding quotes, then store in hold space. ++ # Print out the hold buffer on last line. + [ -f "$KDUMP_CONFIG_FILE" ] && +- sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE ++ sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;s/^\"\(.*\)\"$/\1/;h};\${x;p}" $KDUMP_CONFIG_FILE + } + + is_mounted() +diff --git a/kdumpctl b/kdumpctl +index dd69318..6375efa 100755 +--- a/kdumpctl ++++ b/kdumpctl +@@ -324,6 +324,7 @@ _set_config() + fi + return 1 + fi ++ [[ $_val == \"*\" ]] && _val=${_val:1:-1} + OPT[$opt]="$val" + } + +-- +2.51.1 + diff --git a/0002-unit-tests-Add-case-for-quoted-configuration-values.patch b/0002-unit-tests-Add-case-for-quoted-configuration-values.patch new file mode 100644 index 0000000..9a91d62 --- /dev/null +++ b/0002-unit-tests-Add-case-for-quoted-configuration-values.patch @@ -0,0 +1,45 @@ +From e44958cad8bd997322b213a88881fe874641050d Mon Sep 17 00:00:00 2001 +From: Lichen Liu +Date: Tue, 14 Oct 2025 11:43:04 +0800 +Subject: [PATCH 2/2] unit tests: Add case for quoted configuration values + +This adds a unit test to ensure `kdump_get_conf_val` correctly strips +surrounding quotes from configuration options. This test case covers the +bug fixed in the previous commit. + +Signed-off-by: Lichen Liu +--- + spec/kdump-lib-initramfs_spec.sh | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/spec/kdump-lib-initramfs_spec.sh b/spec/kdump-lib-initramfs_spec.sh +index 2cb85bb..acabc2f 100644 +--- a/spec/kdump-lib-initramfs_spec.sh ++++ b/spec/kdump-lib-initramfs_spec.sh +@@ -12,6 +12,7 @@ Describe 'kdump-lib-initramfs' + #|dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3" + #|sshkey /root/.ssh/kdump_id_rsa + #|ssh user@my.server.com ++ #|core_collector "makedumpfile -l --message-level 7 -d 31" + } + kdump_config >$KDUMP_CONFIG_FILE + Context 'Given different cases' +@@ -21,6 +22,7 @@ Describe 'kdump-lib-initramfs' + # - complicate value for dracut_args + # - Given two parameters, retrive one parameter that has value specified + # - Given two parameters (in reverse order), retrive one parameter that has value specified ++ # - values are enclosed in quotes + Parameters + "#1" nfs my.server.com:/export/tmp + "#2" ssh user@my.server.com +@@ -28,6 +30,7 @@ Describe 'kdump-lib-initramfs' + "#4" dracut_args '--omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3"' + "#5" 'ssh\|aaa' user@my.server.com + "#6" 'aaa\|ssh' user@my.server.com ++ "#7" core_collector "makedumpfile -l --message-level 7 -d 31" + End + + It 'should handle all cases correctly' +-- +2.51.1 + diff --git a/kdump-utils.spec b/kdump-utils.spec index f6138b8..63352b2 100644 --- a/kdump-utils.spec +++ b/kdump-utils.spec @@ -8,6 +8,8 @@ Summary: Kernel crash dump collection utilities License: GPL-2.0-only URL: https://github.com/rhkdump/kdump-utils Source0: https://github.com/rhkdump/kdump-utils/archive/v%{version}/%{name}-%{version}.tar.gz +Patch01: 0001-Strip-surrounding-quotes-from-configuration-values.patch +Patch02: 0002-unit-tests-Add-case-for-quoted-configuration-values.patch %ifarch ppc64 ppc64le Requires(post): servicelog