libpldm: fix the length bytes of get state sensor readings resp

Since the len of stateFields is variable(0x01-0x08), we only define
the min len for the get state sensor readings resp.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I105042a3c45e3b0a96b701c556e22579b56c1c03
diff --git a/libpldm/platform.c b/libpldm/platform.c
index 401e1ca..bc45ae0 100644
--- a/libpldm/platform.c
+++ b/libpldm/platform.c
@@ -649,7 +649,9 @@
 		return PLDM_SUCCESS;
 	}
 
-	if (payload_length > PLDM_GET_STATE_SENSOR_READINGS_RESP_BYTES) {
+	if (payload_length >
+	    PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
+		sizeof(get_sensor_state_field) * *comp_sensor_count) {
 		return PLDM_ERROR_INVALID_LENGTH;
 	}
 
diff --git a/libpldm/platform.h b/libpldm/platform.h
index 546712d..e1b5b23 100644
--- a/libpldm/platform.h
+++ b/libpldm/platform.h
@@ -18,7 +18,6 @@
 #define PLDM_GET_SENSOR_READING_REQ_BYTES 4
 /* Response lengths are inclusive of completion code */
 #define PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES 1
-#define PLDM_GET_STATE_SENSOR_READINGS_RESP_BYTES 34
 
 #define PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES 1
 #define PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES 4
@@ -28,6 +27,7 @@
 #define PLDM_GET_PDR_MIN_RESP_BYTES 12
 #define PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES 5
 #define PLDM_GET_SENSOR_READING_MIN_RESP_BYTES 8
+#define PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES 2
 
 /* Minimum length for PLDM PlatformEventMessage request */
 #define PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES 3
diff --git a/libpldm/tests/libpldm_platform_test.cpp b/libpldm/tests/libpldm_platform_test.cpp
index 992d74a..b30bc66 100644
--- a/libpldm/tests/libpldm_platform_test.cpp
+++ b/libpldm/tests/libpldm_platform_test.cpp
@@ -550,7 +550,9 @@
 
 TEST(GetStateSensorReadings, testGoodEncodeResponse)
 {
-    std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_RESP_BYTES>
+    std::array<uint8_t, hdrSize +
+                            PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
+                            sizeof(get_sensor_state_field) * 2>
         responseMsg{};
 
     auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());
@@ -593,7 +595,9 @@
 
 TEST(GetStateSensorReadings, testGoodDecodeResponse)
 {
-    std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_RESP_BYTES>
+    std::array<uint8_t, hdrSize +
+                            PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
+                            sizeof(get_sensor_state_field) * 2>
         responseMsg{};
 
     uint8_t completionCode = 0;
@@ -638,7 +642,9 @@
 
 TEST(GetStateSensorReadings, testBadDecodeResponse)
 {
-    std::array<uint8_t, hdrSize + PLDM_GET_STATE_SENSOR_READINGS_RESP_BYTES>
+    std::array<uint8_t, hdrSize +
+                            PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES +
+                            sizeof(get_sensor_state_field) * 2>
         responseMsg{};
 
     auto response = reinterpret_cast<pldm_msg*>(responseMsg.data());