Fix for service crash - hwmontempsensor
D-Bus object path accepts only "[a-zA-Z0-9_/]+".
If any invalid characters present on path leads to
throw exception at sdbusplus and leads to service
crashes.
terminate called after throwing an instance of
'sdbusplus::exception::SdBusError'
what(): Invalid path or interface:
org.freedesktop.DBus.Error.InvalidArgs: Invalid argument
Example sensor name: "PCH M.2 Temp"
Replace any invalid characters with "_".
Tested:
No service crashes observed after fix.
Change-Id: Ie487c732db253d01e7c20fa1e79b86a3cca2b263
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
diff --git a/include/sensor.hpp b/include/sensor.hpp
index 4e98089..ff272b5 100644
--- a/include/sensor.hpp
+++ b/include/sensor.hpp
@@ -18,7 +18,7 @@
std::vector<thresholds::Threshold>&& thresholdData,
const std::string& configurationPath, const std::string& objectType,
const double max, const double min) :
- name(name),
+ name(std::regex_replace(name, std::regex("[^a-zA-Z0-9_/]+"), "_")),
configurationPath(configurationPath), objectType(objectType),
maxValue(max), minValue(min), thresholds(std::move(thresholdData)),
hysteresisTrigger((max - min) * 0.01),