pdr: pldm_entity_association_pdr_extract(): Early exit on bad arguments
Also identify the conditions in the doxygen commentary in the public
header.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I37945ab559ffdee5648b2d9ea2befc9fc9a24a9c
diff --git a/src/pdr.c b/src/pdr.c
index 8948ea0..7266ecd 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -1252,14 +1252,23 @@
pldm_entity **entities)
{
assert(pdr != NULL);
- assert(pdr_len >= sizeof(struct pldm_pdr_hdr) +
- sizeof(struct pldm_pdr_entity_association));
+ if (!pdr || !num_entities || !entities) {
+ return;
+ }
+#define PDR_MIN_SIZE \
+ (sizeof(struct pldm_pdr_hdr) + \
+ sizeof(struct pldm_pdr_entity_association))
+ assert(pdr_len >= PDR_MIN_SIZE);
+ if (pdr_len < PDR_MIN_SIZE) {
+ return;
+ }
+#undef PDR_MIN_SIZE
struct pldm_pdr_hdr *hdr = (struct pldm_pdr_hdr *)pdr;
assert(hdr->type == PLDM_PDR_ENTITY_ASSOCIATION);
const uint8_t *start = (uint8_t *)pdr;
- const uint8_t *end =
+ const uint8_t *end __attribute__((unused)) =
start + sizeof(struct pldm_pdr_hdr) + le16toh(hdr->length);
start += sizeof(struct pldm_pdr_hdr);
struct pldm_pdr_entity_association *entity_association_pdr =