Skip to content

Commit 115ac0f

Browse files
committed
Add check for size and large counts to MPI_Type_get_contents[_c]
We should raise MPI_ERR_TYPE if a type has large counts but the user called the legacy MPI_Type_get_contents. We might as well check that the buffer sizes are correct. Signed-off-by: Joseph Schuchart <[email protected]>
1 parent 950ebc1 commit 115ac0f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

ompi/mpi/c/type_get_contents.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ int MPI_Type_get_contents(MPI_Datatype mtype,
6666
}
6767

6868
size_t ci, cl, ca, cd;
69+
int32_t type;
70+
rc = ompi_datatype_get_args( mtype, 0, &ci, NULL,
71+
&cl, NULL,
72+
&ca, NULL,
73+
&cd, NULL, &type );
74+
if( rc != MPI_SUCCESS ) {
75+
OMPI_ERRHANDLER_NOHANDLE_RETURN( MPI_ERR_INTERN,
76+
MPI_ERR_INTERN, FUNC_NAME );
77+
}
78+
// check that we have enough space and no large counts
79+
if (cl > 0 ||
80+
ci > (size_t)max_integers ||
81+
ca > (size_t)max_addresses ||
82+
cd > (size_t)max_datatypes) {
83+
OMPI_ERRHANDLER_NOHANDLE_RETURN( MPI_ERR_TYPE,
84+
MPI_ERR_TYPE, FUNC_NAME );
85+
}
86+
// now get the contents
87+
ci = max_integers, cl = 0, ca = max_addresses, cd = max_datatypes;
6988
rc = ompi_datatype_get_args( mtype, 1, &ci, array_of_integers,
7089
&cl, NULL,
7190
&ca, array_of_addresses,

ompi/mpi/c/type_get_contents_c.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,24 @@ int MPI_Type_get_contents_c(MPI_Datatype mtype,
6767
}
6868
}
6969

70-
size_t ci = max_integers, cl = max_large_counts, ca = max_addresses, cd = max_datatypes;
70+
size_t ci, cl, ca, cd;
71+
rc = ompi_datatype_get_args( mtype, 0, &ci, NULL,
72+
&cl, NULL,
73+
&ca, NULL,
74+
&cd, NULL, NULL );
75+
if( rc != MPI_SUCCESS ) {
76+
OMPI_ERRHANDLER_NOHANDLE_RETURN( MPI_ERR_INTERN,
77+
MPI_ERR_INTERN, FUNC_NAME );
78+
}
79+
// check that we have enough space
80+
if (cl > (size_t)max_large_counts ||
81+
ci > (size_t)max_integers ||
82+
ca > (size_t)max_addresses ||
83+
cd > (size_t)max_datatypes) {
84+
OMPI_ERRHANDLER_NOHANDLE_RETURN( MPI_ERR_TYPE,
85+
MPI_ERR_TYPE, FUNC_NAME );
86+
}
87+
7188
rc = ompi_datatype_get_args( mtype, 1, &ci, array_of_integers,
7289
&cl, array_of_large_counts,
7390
&ca, array_of_addresses,

0 commit comments

Comments
 (0)