From c090439fe56a66f07495e2fc38d26ce6f97b9cda Mon Sep 17 00:00:00 2001 From: Nicolas Sauzede Date: Mon, 10 Sep 2018 10:11:00 +0200 Subject: [PATCH] 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. --- 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..4578ab4 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