pldmd: Account for pldm_pdr_init() returning NULL
Historically, libpldm's pldm_pdr_init() has internall used assert() to
enforce that the returned value is not NULL. Efforts are underway to
remove this reliance on assert() in libpldm to ensure consumers aren't
ungracefully terminated.
This change chooses to return an appropriate error to the
caller of pldmd's internal APIs where possible. However, in a number of
circumstances there was either not a sensible value that could be
returned, or it was not possible to return a value without further
refactoring. In these circumstances we choose to throw
`std::runtime_error`, which will at least do what it can to unwind.
While it may feel like it falls short of proper error handling, the
reality is the calling code is already structured such that it pretends
allocation failures never occur. The switch to throwing a runtime error
makes a strict improvement over the immediate termination implemented by
assert().
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ibb6bc3abf62e32f05ac079453853873298db6c4f
diff --git a/libpldmresponder/platform_numeric_effecter.hpp b/libpldmresponder/platform_numeric_effecter.hpp
index 3acfb3f..46330e6 100644
--- a/libpldmresponder/platform_numeric_effecter.hpp
+++ b/libpldmresponder/platform_numeric_effecter.hpp
@@ -256,6 +256,11 @@
std::unique_ptr<pldm_pdr, decltype(&pldm_pdr_destroy)>
numericEffecterPdrRepo(pldm_pdr_init(), pldm_pdr_destroy);
+ if (!numericEffecterPdrRepo)
+ {
+ error("Failed to instantiate numeric effecter PDR repository");
+ return PLDM_ERROR;
+ }
pldm::responder::pdr_utils::Repo numericEffecterPDRs(
numericEffecterPdrRepo.get());
pldm::responder::pdr::getRepoByType(handler.getRepo(), numericEffecterPDRs,