Add check for response params in encode_XXX_resp
Updated to code so that the response params in encode_xxx_resp()
functions were encoded only if response was a success,
not otherwise.
Change-Id: Ie74ed11c77b481814ff08cea600a4c9a9aa3ae6a
Signed-off-by: Zahed Hossain <zahzahed@in.ibm.com>
diff --git a/libpldm/bios.c b/libpldm/bios.c
index 6470dc3..021c680 100644
--- a/libpldm/bios.c
+++ b/libpldm/bios.c
@@ -31,29 +31,31 @@
}
msg->payload[0] = completion_code;
-
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_BIOS;
header.command = PLDM_GET_DATE_TIME;
+
if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
return rc;
}
- uint8_t *dst = msg->payload + sizeof(msg->payload[0]);
+ if (msg->payload[0] == PLDM_SUCCESS) {
+ uint8_t *dst = msg->payload + sizeof(msg->payload[0]);
- memcpy(dst, &seconds, sizeof(seconds));
- dst += sizeof(seconds);
- memcpy(dst, &minutes, sizeof(minutes));
- dst += sizeof(minutes);
- memcpy(dst, &hours, sizeof(hours));
- dst += sizeof(hours);
- memcpy(dst, &day, sizeof(day));
- dst += sizeof(day);
- memcpy(dst, &month, sizeof(month));
- dst += sizeof(month);
- uint16_t local_year = htole16(year);
- memcpy(dst, &local_year, sizeof(local_year));
+ memcpy(dst, &seconds, sizeof(seconds));
+ dst += sizeof(seconds);
+ memcpy(dst, &minutes, sizeof(minutes));
+ dst += sizeof(minutes);
+ memcpy(dst, &hours, sizeof(hours));
+ dst += sizeof(hours);
+ memcpy(dst, &day, sizeof(day));
+ dst += sizeof(day);
+ memcpy(dst, &month, sizeof(month));
+ dst += sizeof(month);
+ uint16_t local_year = htole16(year);
+ memcpy(dst, &local_year, sizeof(local_year));
+ }
return PLDM_SUCCESS;
}