Skip to content

Commit a5d937c

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 a5d937c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,25 @@ 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+
int32_t type;
72+
rc = ompi_datatype_get_args( mtype, 0, &ci, NULL,
73+
&cl, NULL,
74+
&ca, NULL,
75+
&cd, NULL, &type );
76+
if( rc != MPI_SUCCESS ) {
77+
OMPI_ERRHANDLER_NOHANDLE_RETURN( MPI_ERR_INTERN,
78+
MPI_ERR_INTERN, FUNC_NAME );
79+
}
80+
// check that we have enough space
81+
if (cl > (size_t)max_large_counts ||
82+
ci > (size_t)max_integers ||
83+
ca > (size_t)max_addresses ||
84+
cd > (size_t)max_datatypes) {
85+
OMPI_ERRHANDLER_NOHANDLE_RETURN( MPI_ERR_TYPE,
86+
MPI_ERR_TYPE, FUNC_NAME );
87+
}
88+
7189
rc = ompi_datatype_get_args( mtype, 1, &ci, array_of_integers,
7290
&cl, array_of_large_counts,
7391
&ca, array_of_addresses,

0 commit comments

Comments
 (0)