Fix crash issue due to non-print char
When smbios table file is broken, the parsed string
type propery like version may contain non-print char,
which causes smbios service crash as below:
Nov 18 17:11:53 intel-obmc dbus-broker[180]: Peer :1.175 is being disconnected as it sent a message with an invalid body.
Nov 18 17:11:53 intel-obmc phosphor-mapper[298]: Introspect call failed with error: generic:113, No route to host on process: xyz.openbmc_project.Smbios.MDR_V2 path: /
Nov 18 17:11:53 intel-obmc smbiosmdrv2app[644]: terminate called after throwing an instance of 'sdbusplus::exception::SdBusError'
Nov 18 17:11:53 intel-obmc smbiosmdrv2app[644]: what(): sd_bus_process discard: org.freedesktop.DBus.Error.Disconnected: Connection reset by peer
Nov 18 17:11:53 intel-obmc systemd[1]: Created slice system-systemd\x2dcoredump.slice.
Nov 18 17:11:54 intel-obmc systemd[1]: Started Process Core Dump (PID 645/UID 0).
Nov 18 17:11:57 intel-obmc systemd[1]: smbios-mdrv2.service: Main process exited, code=dumped, status=6/ABRT
Nov 18 17:11:57 intel-obmc systemd[1]: smbios-mdrv2.service: Failed with result 'core-dump'.
Tested:
When version string contain non-print char that means
smbios table file is broken, smbios bios service will
print error and clear the broken.
The smbios table file will be re-generated again at the
next DC cycle.
Change-Id: I001c829b22fc3afba4e863d595f943d0954824e3
Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
diff --git a/src/system.cpp b/src/system.cpp
index 9e4e263..2f6e3e4 100644
--- a/src/system.cpp
+++ b/src/system.cpp
@@ -18,6 +18,7 @@
#include "mdrv2.hpp"
+#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
@@ -72,6 +73,23 @@
uint8_t biosVerByte = biosInfo->biosVersion;
std::string tempS =
positionToString(biosInfo->biosVersion, biosInfo->length, dataIn);
+ if (std::find_if(tempS.begin(), tempS.end(),
+ [](char ch) { return !isprint(ch); }) != tempS.end())
+ {
+ std::ofstream smbiosFile(mdrType2File, std::ios_base::trunc);
+ if (!smbiosFile.good())
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Open MDRV2 table file failure");
+ return result;
+ }
+ smbiosFile.clear();
+ smbiosFile.close();
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Find non-print char, delete the broken MDRV2 table file!");
+ return sdbusplus::xyz::openbmc_project::Inventory::Decorator::
+ server::Revision::version(result);
+ }
result = tempS;
}