Allow ssh opts to be processed correctly

Resolves: RHEL-62661
Upstream: https://github.com/rhkdump/kdump-utils.git
Conflict: None

commit 848f2b7102e7cf785d4d77e0f462ab3cbe571c40
Author: Coiby Xu <coxu@redhat.com>
Date:   Tue Oct 15 15:11:48 2024 +0800

    Allow ssh opts to be processed correctly

    Resolves: https://github.com/rhkdump/kdump-utils/issues/46

    ssh opts shouldn't be quoted otherwise it will be treated as one
    argument. For clarity, also rename ssh_opt to ssh_opts.

    Fixes: 7218f584 ("99kdumpbase: fix shellcheck warnings")
    Reported-by: Jean-Baptiste Trystram <jbtrystram@redhat.com>
    Signed-off-by: Coiby Xu <coxu@redhat.com>

Signed-off-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Philipp Rudo 2024-11-04 14:48:40 +01:00 committed by Lichen Liu
parent d56516e8e5
commit 0459178e7c
2 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,115 @@
From 4244c20ba021e8563a9f0bc297060338ed3a1158 Mon Sep 17 00:00:00 2001
From: Coiby Xu <coxu@redhat.com>
Date: Tue, 15 Oct 2024 15:11:48 +0800
Subject: [PATCH 2/2] Allow ssh opts to be processed correctly
Resolves: https://github.com/rhkdump/kdump-utils/issues/46
ssh opts shouldn't be quoted otherwise it will be treated as one
argument. For clarity, also rename ssh_opt to ssh_opts.
Fixes: 7218f584 ("99kdumpbase: fix shellcheck warnings")
Reported-by: Jean-Baptiste Trystram <jbtrystram@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
---
dracut/99kdumpbase/kdump.sh | 43 +++++++++++++++++++++++--------------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/dracut/99kdumpbase/kdump.sh b/dracut/99kdumpbase/kdump.sh
index e35a76d..00a61f9 100755
--- a/dracut/99kdumpbase/kdump.sh
+++ b/dracut/99kdumpbase/kdump.sh
@@ -396,7 +396,7 @@ dump_raw() {
# $2: ssh address in <user>@<host> format
dump_ssh() {
_ret=0
- _ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
+ _ssh_opts="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes"
_ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR"
if is_ipv6_address "$2"; then
_scp_address=${2%@*}@"[${2#*@}]"
@@ -407,31 +407,37 @@ dump_ssh() {
dinfo "saving to $2:$_ssh_dir"
cat /var/lib/random-seed > /dev/urandom
- ssh -q "$_ssh_opt" "$2" mkdir -p "$_ssh_dir" || return 1
+ # shellcheck disable=SC2086 # ssh_opts needs to be split
+ ssh -q $_ssh_opts "$2" mkdir -p "$_ssh_dir" || return 1
- save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2"
+ save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opts" "$2"
dinfo "saving vmcore"
KDUMP_LOG_DEST=$2:$_ssh_dir/
- KDUMP_LOG_OP="scp -q $_ssh_opt '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'"
+ KDUMP_LOG_OP="scp -q $_ssh_opts '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'"
- save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address"
+ save_opalcore_ssh "$_ssh_dir" "$_ssh_opts" "$2" "$_scp_address"
if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then
- scp -q "$_ssh_opt" /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
+ # shellcheck disable=SC2086 # ssh_opts needs to be split
+ scp -q $_ssh_opts /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
_ret=$?
_vmcore="vmcore"
else
- # shellcheck disable=SC2029
- $CORE_COLLECTOR /proc/vmcore | ssh "$_ssh_opt" "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
+ # shellcheck disable=SC2029,SC2086
+ # - _ssh_opts needs to be split
+ # - _ssh_dir needs to be expanded
+ $CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opts "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
_ret=$?
_vmcore="vmcore.flat"
fi
if [ $_ret -eq 0 ]; then
- # shellcheck disable=SC2029
- ssh "$_ssh_opt" "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
+ # shellcheck disable=SC2029,SC2086
+ # - _ssh_opts needs to be split
+ # - _ssh_dir needs to be expanded
+ ssh $_ssh_opts "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'"
_ret=$?
if [ $_ret -ne 0 ]; then
derror "moving vmcore failed, exitcode:$_ret"
@@ -461,13 +467,16 @@ save_opalcore_ssh() {
dinfo "saving opalcore:$OPALCORE to $3:$1"
- if ! scp "$2" "$OPALCORE" "$4:$1/opalcore-incomplete"; then
+ # shellcheck disable=SC2086 # $2 (_ssh_opts) needs to be split
+ if ! scp $2 "$OPALCORE" "$4:$1/opalcore-incomplete"; then
derror "saving opalcore failed"
return 1
fi
- # shellcheck disable=SC2029
- ssh "$2" "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
+ # shellcheck disable=SC2029,SC2086
+ # - $1 (dump path) needs to be expanded
+ # - $2 (_ssh_opts) needs to be split
+ ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
dinfo "saving opalcore complete"
return 0
}
@@ -478,9 +487,11 @@ save_opalcore_ssh() {
# $4: ssh address in <user>@<host> format
save_vmcore_dmesg_ssh() {
dinfo "saving vmcore-dmesg.txt to $4:$2"
- # shellcheck disable=SC2029
- if "$1" /proc/vmcore | ssh "$3" "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then
- ssh -q "$3" "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
+ # shellcheck disable=SC2029,SC2086
+ # - $2 (_ssh_dir) needs to be expanded
+ # - $3 (_ssh_opts) needs to be split
+ if "$1" /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then
+ ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt"
dinfo "saving vmcore-dmesg.txt complete"
else
derror "saving vmcore-dmesg.txt failed"
--
2.47.0

View File

@ -12,6 +12,9 @@ Source0: https://github.com/rhkdump/kdump-utils/archive/v%{version}/%{name}-%{ve
# Return the correct exit code of rebuild initrd
# Author: Tao Liu <ltao@redhat.com>
Patch1: 0001-Return-the-correct-exit-code-of-rebuild-initrd.patch
# Allow ssh opts to be processed correctly
# Author: Coiby Xu <coxu@redhat.com>
Patch2: 0002-Allow-ssh-opts-to-be-processed-correctly.patch
%ifarch ppc64 ppc64le
Requires(post): servicelog