Skip to content
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

Fix memory corruption in 'MPI I/O FAPL preserve' test #3806

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
44 changes: 22 additions & 22 deletions testpar/t_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,28 +1128,27 @@ test_evict_on_close_parallel_unsupp(void)
void
test_fapl_preserve_hints(void)
{
hid_t fid = H5I_INVALID_HID; /* HDF5 file ID */
hid_t fapl_id = H5I_INVALID_HID; /* File access plist */
const char *filename;

int nkeys_used;
bool same = false;

MPI_Info info = MPI_INFO_NULL;
const char *key = "hdf_info_fapl";
const char *value = "xyz";

MPI_Info info_used = MPI_INFO_NULL;
int flag = -1;
char value_used[20];
char key_used[20];

int i;
herr_t ret; /* Generic return value */
int mpi_ret; /* MPI return value */
const char *key = "hdf_info_fapl";
const char *value = "xyz";
MPI_Info info_used = MPI_INFO_NULL;
MPI_Info info = MPI_INFO_NULL;
hid_t fid = H5I_INVALID_HID; /* HDF5 file ID */
hid_t fapl_id = H5I_INVALID_HID; /* File access plist */
char key_used[MPI_MAX_INFO_KEY + 1];
char *value_used = NULL;
bool same = false;
int flag = -1;
int nkeys_used;
int i;
int mpi_ret; /* MPI return value */
herr_t ret; /* Generic return value */

filename = (const char *)GetTestParameters();

value_used = malloc(MPI_MAX_INFO_VAL + 1);
VRFY(value_used, "malloc succeeded");

/* set up MPI parameters */
mpi_ret = MPI_Info_create(&info);
VRFY((mpi_ret >= 0), "MPI_Info_create succeeded");
Expand Down Expand Up @@ -1184,16 +1183,15 @@ test_fapl_preserve_hints(void)
for (i = 0; i < nkeys_used; i++) {

/* Memset the buffers to zero */
memset(key_used, 0, 20);
memset(value_used, 0, 20);
memset(key_used, 0, MPI_MAX_INFO_KEY + 1);
memset(value_used, 0, MPI_MAX_INFO_VAL + 1);

/* Get the nth key */
mpi_ret = MPI_Info_get_nthkey(info_used, i, key_used);
VRFY((mpi_ret == MPI_SUCCESS), "MPI_Info_get_nthkey succeeded");

if (!strcmp(key_used, key)) {

mpi_ret = MPI_Info_get(info_used, key_used, 20, value_used, &flag);
mpi_ret = MPI_Info_get(info_used, key_used, MPI_MAX_INFO_VAL, value_used, &flag);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard says the value length specified here should be 1 less than the number of bytes allocated to make room for the NUL terminator

VRFY((mpi_ret == MPI_SUCCESS), "MPI_Info_get succeeded");

if (!strcmp(value_used, value)) {
Expand All @@ -1220,4 +1218,6 @@ test_fapl_preserve_hints(void)
mpi_ret = MPI_Info_free(&info_used);
VRFY((mpi_ret >= 0), "MPI_Info_free succeeded");

free(value_used);

} /* end test_fapl_preserve_hints() */