Fix ipmid crash issue caused by null pointer in ipmiStorageGetSDR
When BIOS get fru information from BMC via IPMI command,
requested sdr may be not exist at some special case.
IPMD should handle such case and avoid null pointer is used.
Impact issues are like below:
1. Product name cannot be shown correctly in BIOS setup page.
2. frusdr.efi tool cannot get fru information in efi shell.
3. ipmid service is crashed when AC cycle or run frusdr.efi tool.
Tested:
ipmid service is working well when AC cycle and run frusdr.efi tool.
Product name could be shown correctly in BIOS setup page.
frusdr.efi tool could get correct fru information in efi shell.
Change-Id: Ie02156d80398a365311f3ba0b45ac2a086c84c66
Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
diff --git a/src/sensorcommands.cpp b/src/sensorcommands.cpp
index 98051e5..1d72cf0 100644
--- a/src/sensorcommands.cpp
+++ b/src/sensorcommands.cpp
@@ -1629,6 +1629,15 @@
get_sdr::SensorDataRecordHeader* hdr =
reinterpret_cast<get_sdr::SensorDataRecordHeader*>(
sensorDataRecords[recordID].data());
+ if (!hdr)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error: record header is null");
+ std::vector<uint8_t> emptyData;
+ uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF;
+ return ipmi::responseSuccess(nextRecordId, emptyData);
+ }
+
size_t sdrLength =
sizeof(get_sdr::SensorDataRecordHeader) + hdr->record_length;
if (sdrLength < (offset + bytesToRead))
@@ -1637,6 +1646,14 @@
}
uint8_t* respStart = reinterpret_cast<uint8_t*>(hdr) + offset;
+ if (!respStart)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error: record is null");
+ std::vector<uint8_t> emptyData;
+ uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF;
+ return ipmi::responseSuccess(nextRecordId, emptyData);
+ }
std::vector<uint8_t> recordData(respStart, respStart + bytesToRead);
uint16_t nextRecordId = lastRecord > recordID ? recordID + 1 : 0XFFFF;
return ipmi::responseSuccess(nextRecordId, recordData);