From fbbb19f24465882abf9a1d301017a2179098f770 Mon Sep 17 00:00:00 2001 From: Nicolas Sauzede Date: Wed, 19 Sep 2018 22:00:59 +0200 Subject: [PATCH] Fix cases where a CPU ucode version is not found in $procfs/cpuinfo. (#246) * Fix cases where a CPU ucode version is not found in $procfs/cpuinfo. When running whithin a virtual machine, it seems like $procfs/cpuinfo doesn't contain a 'microcode' line, which triggers a script runtime error. Fall back to '0x0' in this case, as other part of the script seems to already this as a default value anyway. * Double quote to prevent globbing and word splitting. --- spectre-meltdown-checker.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spectre-meltdown-checker.sh b/spectre-meltdown-checker.sh index aeaef1e..8cb91a3 100755 --- a/spectre-meltdown-checker.sh +++ b/spectre-meltdown-checker.sh @@ -1104,7 +1104,8 @@ parse_cpu_details() cpu_family=$( grep '^cpu family' "$procfs/cpuinfo" | awk '{print $4}' | grep -E '^[0-9]+$' | head -1) cpu_model=$( grep '^model' "$procfs/cpuinfo" | awk '{print $3}' | grep -E '^[0-9]+$' | head -1) cpu_stepping=$(grep '^stepping' "$procfs/cpuinfo" | awk '{print $3}' | grep -E '^[0-9]+$' | head -1) - cpu_ucode=$( grep '^microcode' "$procfs/cpuinfo" | awk '{print $3}' | head -1) + # read CPU ucode from $procfs/cpuinfo. fall-back to 0x0 if not found (eg: with a virtual machine) + cpu_ucode=$( raw_cpu_ucode=$(grep '^microcode' "$procfs/cpuinfo") && echo "$raw_cpu_ucode" | awk '{print $3}' | head -1 || echo "0x0") else cpu_friendly_name=$(sysctl -n hw.model) fi