pdr: Avoid ID overflow in pldm_entity_association_tree_add_entity()
Return early from pldm_entity_association_tree_add_entity() if the
container ID space has been exhausted.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ifc4ef529a8746c3b27b8925be1a038089f2f2729
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9903510..03f5387 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,10 @@
## [Unreleased]
+### Changed
+
+1. pdr: Avoid ID overflow in pldm_entity_association_tree_add_entity()
+
### Removed
1. pdr: Remove pldm_entity_association_pdr_add()
diff --git a/src/pdr.c b/src/pdr.c
index da2e98d..e78d8cd 100644
--- a/src/pdr.c
+++ b/src/pdr.c
@@ -563,6 +563,12 @@
node->entity.entity_container_id = 0;
node->remote_container_id = node->entity.entity_container_id;
} else if (parent != NULL && parent->first_child == NULL) {
+ /* Ensure next_container_id() will yield a valid ID */
+ if (tree->last_used_container_id == UINT16_MAX) {
+ free(node);
+ return NULL;
+ }
+
parent->first_child = node;
node->parent = parent->entity;