libpldmresponder: fix a potential pldm crash

In the current state, pldm does create the sensor/effecter even in the
absence of the underlying dbus resource. There is a bug in the responder
code due to which we emplace an empty dbus value map into the handler
with a sensor ID. And if the remote PLDM endpoint queries for the state
of the sensor, pldm would crash since it tries to read content from the
empty dbus value map. This commit would fix the crash by adding
necessary bound checks.

Testing:
1. Unit tests passed.
2. Functionally verified the fix by giving a dummy dbus object path and
making sure that the sensor/effecter is not created & also ensured that
pldm does not crash.

Change-Id: I5fb06677f6ae1bd74f9ec741b311f59737caf79d
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
diff --git a/libpldmresponder/platform_state_effecter.hpp b/libpldmresponder/platform_state_effecter.hpp
index db70128..247dbfd 100644
--- a/libpldmresponder/platform_state_effecter.hpp
+++ b/libpldmresponder/platform_state_effecter.hpp
@@ -98,7 +98,17 @@
     {
         const auto& [dbusMappings,
                      dbusValMaps] = handler.getDbusObjMaps(effecterId);
-        for (uint8_t currState = 0; currState < compEffecterCnt; ++currState)
+        if (dbusMappings.empty() || dbusValMaps.empty())
+        {
+            error("dbusMappings for effecter id : {EFFECTER_ID} is missing",
+                  "EFFECTER_ID", effecterId);
+            return PLDM_ERROR;
+        }
+
+        for (uint8_t currState = 0;
+             currState < compEffecterCnt && currState < dbusMappings.size() &&
+             currState < dbusValMaps.size();
+             ++currState)
         {
             std::vector<StateSetNum> allowed{};
             // computation is based on table 79 from DSP0248 v1.1.1