Hi Tao,
On Wed, 9 Feb 2022 16:43:37 +0800
Tao Liu <ltao(a)redhat.com> wrote:
Previously the output of blkid is not checked. If the output
is empty, the eval will report the following error message:
/lib/kdump/kdump-lib.sh: eval: line 925: syntax error near unexpected token `;'
/lib/kdump/kdump-lib.sh: eval: line 925: `; echo $TYPE'
For example, we can observe such a failing when blkid is invoked
against a lvm thinpool block device:
$ blkid -u filesystem,crypto -o export -- "/dev/block/253\:2"
$ echo $?
2
$ udevadm info /dev/block/253\:2|grep S\:
S: mapper/vg00-thinpoll_tmeta
In this patch, we will first check whether the output of blkid is
empty, then decide if eval will be invoked later.
Signed-off-by: Tao Liu <ltao(a)redhat.com>
---
kdump-lib.sh | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 3e912cc..63e0b1f 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -881,12 +881,16 @@ kdump_get_arch_recommend_size()
# $1: the block device to be checked in maj:min format
get_luks_crypt_dev()
{
- local _type
+ local _type _blk_info
[[ -b /dev/block/$1 ]] || return 1
- _type=$(eval "$(blkid -u filesystem,crypto -o export --
"/dev/block/$1"); echo \$TYPE")
- [[ $_type == "crypto_LUKS" ]] && echo "$1"
isn't it easier to simply pipe the output of blkid to sed? I.e.
_type="$(blkid -u filesystem,crypto -o export -- "/dev/block/$1" | sed -n
-e "s/^TYPE=(.*)$/\1/p")"
With that $_type will be empty when blkid returns an empty string and
the following check will fail. Furthermore you also get rid of the eval
wich in my opinion should only be used when there is no other way.
Thanks
Philipp
+ _blk_info=$(blkid -u filesystem,crypto -o export --
"/dev/block/$1")
+
+ if [[ -n $_blk_info ]]; then
+ _type=$(eval "$_blk_info; echo \$TYPE")
+ [[ $_type == "crypto_LUKS" ]] && echo "$1"
+ fi
for _x in "/sys/dev/block/$1/slaves/"*; do
[[ -f $_x/dev ]] || continue