Skip to content

comm: beef up args checking for some comm constructors #12964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions ompi/mpi/c/comm_create_from_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2021 Triad National Security, LLC. All rights
* Copyright (c) 2021-2024 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -54,23 +54,31 @@ int MPI_Comm_create_from_group (MPI_Group group, const char *tag, MPI_Info info,
if ( MPI_PARAM_CHECK ) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);

if (NULL == errhandler ||
MPI_ERRHANDLER_NULL == errhandler ||
( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
return ompi_errhandler_invoke (NULL, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG,FUNC_NAME);
}

if (NULL == tag) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_TAG, FUNC_NAME);
}

if (NULL == group) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_GROUP, FUNC_NAME);
}

if (NULL == info || ompi_info_is_freed(info)) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_INFO, FUNC_NAME);
}

if (NULL == newcomm) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG, FUNC_NAME);
}
}
Expand Down
39 changes: 28 additions & 11 deletions ompi/mpi/c/intercomm_create_from_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* and Technology (RIST). All rights reserved.
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2018-2021 Triad National Security, LLC. All rights
* Copyright (c) 2018-2024 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
Expand Down Expand Up @@ -50,7 +50,7 @@ int MPI_Intercomm_create_from_groups (MPI_Group local_group, int local_leader, M
int remote_leader, const char *tag, MPI_Info info, MPI_Errhandler errhandler,
MPI_Comm *newintercomm)
{
int rc;
int rc, my_grp_rank, remote_grp_size;

MEMCHECKER(
memchecker_comm(local_comm);
Expand All @@ -60,26 +60,43 @@ int MPI_Intercomm_create_from_groups (MPI_Group local_group, int local_leader, M
if (MPI_PARAM_CHECK) {
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);

if (NULL == errhandler) {
return MPI_ERR_ARG;
}
if (NULL == errhandler ||
MPI_ERRHANDLER_NULL == errhandler ||
( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
return ompi_errhandler_invoke (NULL, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG,FUNC_NAME);

if (NULL == local_group || NULL == remote_group) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
MPI_ERR_GROUP, FUNC_NAME);
}

if (NULL == info || ompi_info_is_freed(info)) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_INFO, FUNC_NAME);
}
if (NULL == tag) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_TAG, FUNC_NAME);
}
if (NULL == newintercomm) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, errhandler->eh_mpi_object_type,
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG, FUNC_NAME);
}

my_grp_rank = ompi_group_rank((ompi_group_t *)local_group);
if (local_leader == my_grp_rank) {

if (NULL == local_group || NULL == remote_group) {
return ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_GROUP, FUNC_NAME);
}

remote_grp_size = ompi_group_size((ompi_group_t *)remote_group);
if (remote_leader >= remote_grp_size) {
rc = ompi_errhandler_invoke (errhandler, MPI_COMM_NULL, OMPI_ERRHANDLER_TYPE_COMM,
MPI_ERR_ARG, FUNC_NAME);
return rc;
}
}
}

rc = ompi_intercomm_create_from_groups (local_group, local_leader, remote_group, remote_leader, tag,
Expand Down
Loading