Fix a FruDevice service crash issue
In some systems, the FruDevice service stopped while it is adding
Dbus properties with below logs:
Mar 19 17:17:38 wolfpass systemd[1]: Starting Fru Device...
Mar 19 17:17:38 wolfpass fru-device[1061]: failed to read bus 5 address 112
Mar 19 17:18:04 wolfpass fru-device[1061]: failed to read bus 5 address 112
Mar 19 17:18:18 wolfpass fru-device[1061]: process 1061: arguments to dbus_message_iter_append_basic() were incorrect, asserti
on "_dbus_check_is_valid_utf8 (*string_p)" failed in file ../../dbus-1.10.10/dbus/dbus-message.c line 2749.
Mar 19 17:18:18 wolfpass fru-device[1061]: This is normally a bug in some application using the D-Bus library.
Mar 19 17:18:18 wolfpass fru-device[1061]: D-Bus not built with -rdynamic so unable to print a backtrace
Mar 19 17:18:28 wolfpass systemd[1]: [[0;1;39mxyz.openbmc_project.FruDevice.service: Main process exited, code=killed, status=
6/ABRT[[0m
Mar 19 17:18:28 wolfpass systemd[1]: [[0;1;31mFailed to start Fru Device.[[0m
Mar 19 17:18:28 wolfpass systemd[1]: [[0;1;39mxyz.openbmc_project.FruDevice.service: Unit entered failed state.[[0m
Mar 19 17:18:28 wolfpass systemd[1]: [[0;1;39mxyz.openbmc_project.FruDevice.service: Failed with result 'signal'.[[0m
This is caused by an invalid string property from some components
so this patch adds a regex_replace() call to avoid _dbus_assert
crashes.
Change-Id: I551f12f028e08685ce5dbb3a3f770d199ff8fc3b
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index c9d0c15..eb7f90a 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -373,7 +373,7 @@
}
std::string commandStr = *(match.begin() + 1);
// convert single ticks and single slashes into legal json
- boost::replace_all(commandStr, "'", R"(")");
+ boost::replace_all(commandStr, "'", "\"");
boost::replace_all(commandStr, R"(\)", R"(\\)");
auto json = nlohmann::json::parse(commandStr, nullptr, false);
if (json.is_discarded())
diff --git a/src/FruDevice.cpp b/src/FruDevice.cpp
index 86806ba..f2b7b29 100644
--- a/src/FruDevice.cpp
+++ b/src/FruDevice.cpp
@@ -42,6 +42,7 @@
static constexpr std::array<const char *, 5> FRU_AREAS = {
"INTERNAL", "CHASSIS", "BOARD", "PRODUCT", "MULTIRECORD"};
const static constexpr char *POWER_OBJECT_NAME = "/org/openbmc/control/power0";
+const static std::regex NON_ASCII_REGEX("[^\x01-\x7f]");
using DeviceMap = boost::container::flat_map<int, std::vector<char>>;
using BusMap = boost::container::flat_map<int, std::shared_ptr<DeviceMap>>;
@@ -416,7 +417,13 @@
object->register_interface(iface);
for (auto &property : formattedFru)
{
+ std::regex_replace(property.second.begin(), property.second.begin(),
+ property.second.end(), NON_ASCII_REGEX, "_");
iface->set_property(property.first, property.second);
+ if (DEBUG)
+ {
+ std::cout << property.first << ": " << property.second << "\n";
+ }
}
// baseboard can set this to -1 to not set a bus / address
if (bus > 0)