From 6ea0c4eab9b571dae298bc85d37a398c4cd77bb5 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Thu, 28 Mar 2019 12:03:29 -0400 Subject: [PATCH] Prevent a segfault when accessing a rank outside a communicator. This is not fixing any issue, it is simply preventing a sefault if the communicator creation has not happened as expected. Thus, this code path should never really be hit in a correct MPI application with a valid communicator creation support. Signed-off-by: George Bosilca --- ompi/mca/pml/ob1/pml_ob1_comm.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ompi/mca/pml/ob1/pml_ob1_comm.h b/ompi/mca/pml/ob1/pml_ob1_comm.h index 780c9a44fc7..706ca07157f 100644 --- a/ompi/mca/pml/ob1/pml_ob1_comm.h +++ b/ompi/mca/pml/ob1/pml_ob1_comm.h @@ -82,6 +82,16 @@ static inline mca_pml_ob1_comm_proc_t *mca_pml_ob1_peer_lookup (struct ompi_comm { mca_pml_ob1_comm_t *pml_comm = (mca_pml_ob1_comm_t *)comm->c_pml_comm; + /** + * We have very few ways to validate the correct, and collective, creation of + * the communicator, and ensure all processes have the same cid. The least we + * can do is to check that we are not using a rank that is outside the scope + * of the communicator. + */ + if( OPAL_UNLIKELY(rank >= (int)pml_comm->num_procs) ) { + ompi_rte_abort(-1, "PML OB1 received a message from a rank outside the" + " valid range of the communicator. Please submit a bug request!"); + } if (OPAL_UNLIKELY(NULL == pml_comm->procs[rank])) { OPAL_THREAD_LOCK(&pml_comm->proc_lock); if (NULL == pml_comm->procs[rank]) {