From ac4db9d4b9bd70f75f7fe731ed035d14361c807d Mon Sep 17 00:00:00 2001 From: Derek M Date: Sun, 30 Apr 2023 01:30:21 -0700 Subject: [PATCH] Adding checks around the value cache in the IPMI update (#1054) (#1061) * Adding checks around the value cache in the IPMI update to prevent null dereference. * Adding braces for code style. --------- Co-authored-by: doolbneerg --- .../Hardware/Motherboard/Lpc/Ipmi.cs | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Ipmi.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Ipmi.cs index 7597600..8087034 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Ipmi.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Ipmi.cs @@ -174,21 +174,21 @@ internal class Ipmi : ISuperIO { case 1: _temperatures.Add(RawToFloat(reading[1], sdr)); - if (Temperatures.Length == 0) + if (Temperatures == null || Temperatures.Length == 0) _temperatureNames.Add(sdr.id_string.Replace(" Temp", "")); break; case 2: _voltages.Add(RawToFloat(reading[1], sdr)); - if (Voltages.Length == 0) + if (Voltages == null || Voltages.Length == 0) _voltageNames.Add(sdr.id_string); break; case 4: _fans.Add(RawToFloat(reading[1], sdr)); - if (Fans.Length == 0) + if (Fans == null || Fans.Length == 0) _fanNames.Add(sdr.id_string); break; @@ -213,17 +213,29 @@ internal class Ipmi : ISuperIO } } - for (int i = 0; i < Math.Min(_temperatures.Count, Temperatures.Length); ++i) - Temperatures[i] = _temperatures[i]; + if (Temperatures != null) + { + for (int i = 0; i < Math.Min(_temperatures.Count, Temperatures.Length); ++i) + Temperatures[i] = _temperatures[i]; + } - for (int i = 0; i < Math.Min(_voltages.Count, Voltages.Length); ++i) - Voltages[i] = _voltages[i]; + if (Voltages != null) + { + for (int i = 0; i < Math.Min(_voltages.Count, Voltages.Length); ++i) + Voltages[i] = _voltages[i]; + } - for (int i = 0; i < Math.Min(_fans.Count, Fans.Length); ++i) - Fans[i] = _fans[i]; + if (Fans != null) + { + for (int i = 0; i < Math.Min(_fans.Count, Fans.Length); ++i) + Fans[i] = _fans[i]; + } - for (int i = 0; i < Math.Min(_controls.Count, Controls.Length); ++i) - Controls[i] = _controls[i]; + if (Controls != null) + { + for (int i = 0; i < Math.Min(_controls.Count, Controls.Length); ++i) + Controls[i] = _controls[i]; + } } public IEnumerable GetTemperatures()