PEL: Sanitize D-Bus fields that come from PELs

The Resolution D-Bus property is filled with values from the PEL callout
fields like the serial and part numbers.  These fields usually come from
EEPROMs, and may not necessarily be valid printable values if the code
that creates the PEL doesn't sanitize the values first.  If any of the
characters were invalid, the daemon would crash when D-Bus broker
disconnects it from D-Bus since it doesn't allow invalid values on
D-Bus.

Prevent this crash by converting any non printable characters in the
Resolution property to spaces.  This also sanitizes the EventId property
which contains the SRC ASCII string and hex words just to be safe.

This is really just a concern for non-BMC created PELs, since the BMC
code that reads EEPROMs already sanitizes the values when it reads them,
but PELs have come in from other subsystems that don't.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: If0e80fd9db27446f5367ed046e4bca2eb62e3fb2
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index 0643229..41d6138 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -1110,3 +1110,16 @@
     auto& hexwords = pel.primarySRC().value()->hexwordData();
     EXPECT_EQ(hexwords[3] & 0x20000000, 0x20000000);
 }
+
+TEST_F(ManagerTest, TestSanitizeFieldforDBus)
+{
+    std::string base{"(test0!}\n\t ~"};
+    auto string = base;
+    string += char{' ' - 1};
+    string += char{'~' + 1};
+    string += char{0};
+    string += char{static_cast<char>(0xFF)};
+
+    // convert the last four chars to spaces
+    EXPECT_EQ(Manager::sanitizeFieldForDBus(string), base + "    ");
+}