Handle errors finding openbmc_path #75
1.Check return value properly.
Signed-off-by: Nan Li <bjlinan@cn.ibm.com>
diff --git a/ipmid.C b/ipmid.C
index 728ba0b..5d7fbe7 100644
--- a/ipmid.C
+++ b/ipmid.C
@@ -565,6 +565,11 @@
r = find_openbmc_path("SENSOR", number, &a);
+ if (r < 0) {
+ fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
+ return 0;
+ }
+
r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
if (r < 0) {
fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
@@ -602,6 +607,11 @@
r = find_openbmc_path("SENSOR", number, &a);
+ if (r < 0) {
+ fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
+ return 0;
+ }
+
r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
if (r < 0) {
fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
diff --git a/sensorhandler.C b/sensorhandler.C
index bb14e7a..39de660 100644
--- a/sensorhandler.C
+++ b/sensorhandler.C
@@ -180,6 +180,11 @@
r = find_openbmc_path("SENSOR", reqptr->sennum, &a);
+ if (r < 0) {
+ fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
+ return IPMI_CC_SENSOR_INVALID;
+ }
+
type = find_sensor(reqptr->sennum);
fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface);