Handle sensors that can not be found in SystemManager
When a sensor id is not managed in yaml the code tries to get it from
legacy SystemManager;
And when the sensor id can not be found in SystemManager, it returns
empty path, and cause segment fault.
This commit makes it return -EINVAL when path is empty, and thus the
code will handle this case properly without crash.
Resolves openbmc/openbmc#3062
Tested: Boot host without ipmid crash on Romulus.
Change-Id: I4240b9be54824543b5e795e898330aeb02c5eb90
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 4fabac5..3a47e20 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -105,6 +105,13 @@
goto final;
}
+ if (strlen(str2) == 0)
+ {
+ // Path being empty occurs when the sensor id is not in SystemManager
+ r = -EINVAL;
+ goto final;
+ }
+
r = get_bus_for_path(str2, &str1);
if (r < 0) {
fprintf(stderr, "Failed to get %s busname: %s\n",
@@ -311,7 +318,7 @@
r = find_openbmc_path(num, &dbus_if);
if (r < 0) {
fprintf(stderr, "Could not find sensor %d\n", num);
- return r;
+ return 0;
}
return get_type_from_interface(dbus_if);
}