fix to check presence of smbios file before read
Issue: Response of read SMBIOS data ipmi command giving hardcoded values
when smbios file doesnt exists.
Fix: Added checks before reading SMBIOS file to ensure the
presence of the file. Absence of the file handles the case
of returning without displaying hardcoded data.
Test Results:
Verified using IPMI command
Command: ipmitool raw 0x3E 0x31 0x01 0x01 0x00 //read smbios data
Response: Unable to send RAW command
(channel=0x0 netfn=0x3e lun=0x0 cmd=0x31 rsp=0xce):Command response
could not be provided.
Signed-off-by: Prithvi A Pai <prithvi.a.pai@intel.com>
Change-Id: I612f71f2ce5bc81fe39b59c6fe742b1d5126dce8
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 75842fc..d678848 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -34,6 +34,15 @@
std::vector<uint8_t> MDR_V2::getDirectoryInformation(uint8_t dirIndex)
{
std::vector<uint8_t> responseDir;
+
+ std::ifstream smbiosFile(mdrType2File, std::ios_base::binary);
+ if (!smbiosFile.good())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Open MDRV2 table file failure");
+ throw sdbusplus::xyz::openbmc_project::Smbios::MDR_V2::Error::
+ InvalidParameter();
+ }
if (dirIndex > smbiosDir.dirEntries)
{
responseDir.push_back(0);
@@ -368,7 +377,17 @@
uint8_t MDR_V2::directoryEntries(uint8_t value)
{
- value = smbiosDir.dirEntries;
+ std::ifstream smbiosFile(mdrType2File, std::ios_base::binary);
+ if (!smbiosFile.good())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Read data from flash error - Open MDRV2 table file failure");
+ value = 0;
+ }
+ else
+ {
+ value = smbiosDir.dirEntries;
+ }
return sdbusplus::xyz::openbmc_project::Smbios::server::MDR_V2::
directoryEntries(value);
}