From ad9d9bc4ce516356f781ec9ef3f5419eb624558a Mon Sep 17 00:00:00 2001 From: Josh Fisher Date: Thu, 9 Jun 2022 17:09:16 -0400 Subject: [PATCH] opal: Segfault avoidence in class and mca/btl/ofi Fixed a loop causing segfaults in opal_object.h and fixed goto fail block to check for NULL before potential dereference as we go there for NULL in what we dereference Signed-off-by: Josh Fisher --- opal/class/opal_object.h | 2 +- opal/mca/btl/ofi/btl_ofi_component.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/opal/class/opal_object.h b/opal/class/opal_object.h index 45cb4ac0608..5d2e81fcbb1 100644 --- a/opal/class/opal_object.h +++ b/opal/class/opal_object.h @@ -479,7 +479,7 @@ static inline void opal_obj_run_destructors(opal_object_t * object) assert(NULL != object->obj_class); cls_destruct = object->obj_class->cls_destruct_array; - while( NULL != *cls_destruct ) { + while (NULL != cls_destruct && NULL != *cls_destruct) { (*cls_destruct)(object); cls_destruct++; } diff --git a/opal/mca/btl/ofi/btl_ofi_component.c b/opal/mca/btl/ofi/btl_ofi_component.c index bc4342c6423..6627b69ff28 100644 --- a/opal/mca/btl/ofi/btl_ofi_component.c +++ b/opal/mca/btl/ofi/btl_ofi_component.c @@ -675,8 +675,10 @@ static int mca_btl_ofi_init_device(struct fi_info *info) /* if the contexts have not been initiated, num_contexts should * be zero and we skip this. */ - for (int i=0; i < module->num_contexts; i++) { - mca_btl_ofi_context_finalize(&module->contexts[i], module->is_scalable_ep); + if (NULL != module->contexts) { + for (int i = 0; i < module->num_contexts; i++) { + mca_btl_ofi_context_finalize(&module->contexts[i], module->is_scalable_ep); + } } free(module->contexts);