summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2018-06-06 14:33:59 +0530
committerVernon Mauery <vernon.mauery@linux.intel.com>2018-07-24 20:10:39 +0000
commitebc886fc52d3f109e4c3b4ee74a510c65557eebe (patch)
tree53bb3aa41b434a10f8d54ba32557daa13aa7f4f1
parent1469f8adc101962c1235f9477e9d53b5ba44e72b (diff)
downloadphosphor-host-ipmid-ebc886fc52d3f109e4c3b4ee74a510c65557eebe.tar.gz
phosphor-host-ipmid-ebc886fc52d3f109e4c3b4ee74a510c65557eebe.zip
Fix to return sane error code
Any unhandled exception in the IPMI command handler crashes the ipmi stack. IPMI command handler also becomes bulky to catch all exceptions which must return unspecified errors. This fix adds a catch in the ipmi router command handler functions, and returns IPMI_CC_UNSPECIFIED_ERROR for all the unhandled exceptions. With this fix, exceptions which has to throw IPMI_CC_UNSPECIFIED_ERROR, doesn't needs to be handled in the command handlers. Change-Id: I6cf9fa1f0e5c1d71c57eebb9a2d451fa986168d3 Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
-rw-r--r--ipmid.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/ipmid.cpp b/ipmid.cpp
index c48df3b..3d7c663 100644
--- a/ipmid.cpp
+++ b/ipmid.cpp
@@ -239,10 +239,23 @@ ipmi_ret_t ipmi_netfn_router(ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_request_t
// make sense.
char *respo = &((char *)response)[IPMI_CC_LEN];
- // Response message from the plugin goes into a byte post the base response
- rc = (handler_and_context.first) (netfn, cmd, request, respo,
- data_len, handler_and_context.second);
-
+ try
+ {
+ // Response message from the plugin goes into a byte post the base
+ // response
+ rc = (handler_and_context.first) (netfn, cmd, request, respo,
+ data_len, handler_and_context.second);
+ }
+ // IPMI command handlers can throw unhandled exceptions, catch those
+ // and return sane error code.
+ catch (const std::exception &e)
+ {
+ log<level::ERR>(e.what(), entry("NET_FUN=0x%X", netfn),
+ entry("CMD=0x%X", cmd));
+ rc = IPMI_CC_UNSPECIFIED_ERROR;
+ *data_len = 0;
+ // fall through
+ }
// Now copy the return code that we got from handler and pack it in first
// byte.
memcpy(response, &rc, IPMI_CC_LEN);
OpenPOWER on IntegriCloud