Check if the FRU Id is valid for FRU commands

Validate FRU Id before proceesing with the command handling.
Do not report error log for any FRU command failure, since IPMI is
an external interface.

Resolves openbmc/openbmc#3016

Change-Id: I9e2af3ce50285662f1b8f9600222e9ff3057a7e3
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/storagehandler.cpp b/storagehandler.cpp
index d1392e6..6f97bef 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -595,6 +595,14 @@
     ipmi_ret_t rc = IPMI_CC_OK;
     const FruInvenAreaInfoRequest* reqptr =
         reinterpret_cast<const FruInvenAreaInfoRequest*>(request);
+
+    auto iter = frus.find(reqptr->fruID);
+    if (iter == frus.end())
+    {
+        *data_len = 0;
+        return IPMI_CC_SENSOR_INVALID;
+    }
+
     try
     {
         const auto& fruArea = getFruAreaData(reqptr->fruID);
@@ -614,7 +622,6 @@
         rc = IPMI_CC_UNSPECIFIED_ERROR;
         *data_len = 0;
         log<level::ERR>(e.what());
-        report<InternalFailure>();
     }
     return rc;
 }
@@ -630,6 +637,14 @@
         reinterpret_cast<const ReadFruDataRequest*>(request);
     auto resptr =
         reinterpret_cast<ReadFruDataResponse*>(response);
+
+    auto iter = frus.find(reqptr->fruID);
+    if (iter == frus.end())
+    {
+        *data_len = 0;
+        return IPMI_CC_SENSOR_INVALID;
+    }
+
     auto offset =
         static_cast<uint16_t>(reqptr->offsetMS << 8 | reqptr->offsetLS);
     try
@@ -658,7 +673,6 @@
         rc = IPMI_CC_UNSPECIFIED_ERROR;
         *data_len = 0;
         log<level::ERR>(e.what());
-        report<InternalFailure>();
     }
     return rc;
 }