For the cases like passing ssh opts, we need to word-split ssh_opts
(renamed from rename _ssh_opt to improve readability). So they are false
positives. For other cases, quote them to avoid prevent globbing and
word splitting.
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
dracut-kdump.sh | 27 +++++++++++++++++----------
kdump-dep-generator.sh | 4 ++--
kdump-lib-initramfs.sh | 5 +++--
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/dracut-kdump.sh b/dracut-kdump.sh
index f4456a1..148cad7 100755
--- a/dracut-kdump.sh
+++ b/dracut-kdump.sh
@@ -301,12 +301,12 @@ do_failure_action()
do_final_action()
{
dinfo "Executing final action $FINAL_ACTION"
- eval $FINAL_ACTION
+ eval "$FINAL_ACTION"
}
do_dump()
{
- eval $DUMP_INSTRUCTION
+ eval "$DUMP_INSTRUCTION"
_ret=$?
if [ $_ret -ne 0 ]; then
@@ -387,7 +387,7 @@ dump_raw()
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#*@}]"
@@ -398,29 +398,33 @@ 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 # need to word-split $_ssh_opts
+ 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 # need to word-split $_ssh_opts
+ scp -q $_ssh_opts /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete"
_ret=$?
_vmcore="vmcore"
else
- $CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 &&
dd bs=512 of='$_ssh_dir/vmcore-incomplete'"
+ # shellcheck disable=SC2086 # need to word-split $_ssh_opts
+ $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
- ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete'
'$_ssh_dir/$_vmcore'"
+ # shellcheck disable=SC2086 # need to word-split $_ssh_opts
+ ssh $_ssh_opts "$2" "mv '$_ssh_dir/vmcore-incomplete'
'$_ssh_dir/$_vmcore'"
_ret=$?
if [ $_ret -ne 0 ]; then
derror "moving vmcore failed, exitcode:$_ret"
@@ -451,11 +455,13 @@ save_opalcore_ssh()
dinfo "saving opalcore:$OPALCORE to $3:$1"
+ # shellcheck disable=SC2086 # need to word-split $2
if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then
derror "saving opalcore failed"
return 1
fi
+ # shellcheck disable=SC2086 # need to word-split $2
ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore"
dinfo "saving opalcore complete"
return 0
@@ -468,6 +474,7 @@ save_opalcore_ssh()
save_vmcore_dmesg_ssh()
{
dinfo "saving vmcore-dmesg.txt to $4:$2"
+ # shellcheck disable=SC2086 # need to word-split $3
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"
diff --git a/kdump-dep-generator.sh b/kdump-dep-generator.sh
index 0eb8482..655e7bf 100644
--- a/kdump-dep-generator.sh
+++ b/kdump-dep-generator.sh
@@ -18,6 +18,6 @@ systemd_dir=/usr/lib/systemd/system
kdump_wants=$dest_dir/kdump.service.wants
if is_ssh_dump_target; then
- mkdir -p $kdump_wants
- ln -sf $systemd_dir/network-online.target $kdump_wants/
+ mkdir -p "$kdump_wants"
+ ln -sf $systemd_dir/network-online.target "$kdump_wants"/
fi
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh
index 84e6bf7..5c052a2 100755
--- a/kdump-lib-initramfs.sh
+++ b/kdump-lib-initramfs.sh
@@ -36,6 +36,7 @@ is_mounted()
# $2: mount source type
# $3: mount source
# $4: extra args
+# shellcheck disable=SC2086 # $4 means extra args which nees to word-splitted
get_mount_info()
{
__kdump_mnt=$(findmnt -k -n -r -o "$1" "--$2" "$3" $4)
@@ -58,13 +59,13 @@ is_fs_type_nfs()
# If $1 contains dracut_args "--mount", return <filesystem type>
get_dracut_args_fstype()
{
- echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut
-d' ' -f3
+ echo "$1" | grep "\-\-mount" | sed "s/.*--mount
.\(.*\)/\1/" | cut -d' ' -f3
}
# If $1 contains dracut_args "--mount", return <device>
get_dracut_args_target()
{
- echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut
-d' ' -f1
+ echo "$1" | grep "\-\-mount" | sed "s/.*--mount
.\(.*\)/\1/" | cut -d' ' -f1
}
get_save_path()
--
2.37.1