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

Prevent H5Pset* routines from modifying default plists #5172

Merged
merged 7 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/H5Pfapl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5833,6 +5833,8 @@ H5Pset_vol(hid_t plist_id, hid_t new_vol_id, const void *new_vol_info)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a property list");
if (NULL == (connector = H5I_object_verify(new_vol_id, H5I_VOL)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file VOL ID");
if (plist_id == H5P_FILE_ACCESS_DEFAULT || plist_id == H5P_DEFAULT)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "can't set VOL connector in default property list");

/* Set the VOL */
if (H5P_set_vol(plist, connector, new_vol_info) < 0)
Expand Down
59 changes: 59 additions & 0 deletions test/vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,64 @@ test_query_optional(void)
return FAIL;
} /* end test_query_optional() */

/*-------------------------------------------------------------------------
* Function: test_set_default_vol_invalid
*
* Purpose: Tests that H5Pset_vol() fails when attempting to change
* the VOL connector on the default FAPL
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
test_set_default_plist_vol_fail(void)
{
hid_t vol_id = H5I_INVALID_HID;
herr_t ret = FAIL;

TESTING("H5Pset_vol() on default FAPL");

if ((vol_id = H5VLregister_connector(&fake_vol_g, H5P_DEFAULT)) < 0)
TEST_ERROR;

/* Attempt to set the VOL connector on the default FAPL */
H5E_BEGIN_TRY
{
ret = H5Pset_vol(H5P_FILE_ACCESS_DEFAULT, vol_id, NULL);
}
H5E_END_TRY

if (ret >= 0)
FAIL_PUTS_ERROR("H5Pset_vol() succeeded on default FAPL");

/* Attempt to set the VOL connector on the default generic property list */
H5E_BEGIN_TRY
{
ret = H5Pset_vol(H5P_DEFAULT, vol_id, NULL);
}
H5E_END_TRY

if (ret >= 0)
FAIL_PUTS_ERROR("H5Pset_vol() succeeded on default property list");

/* Unregister the fake VOL ID */
if (H5VLunregister_connector(vol_id) < 0)
TEST_ERROR;

PASSED();

return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5VLunregister_connector(vol_id);
}
H5E_END_TRY

return FAIL;
}

/*-------------------------------------------------------------------------
* Function: main
*
Expand Down Expand Up @@ -2604,6 +2662,7 @@ main(void)
nerrors += test_wrap_register() < 0 ? 1 : 0;
nerrors += test_info_to_str() < 0 ? 1 : 0;
nerrors += test_query_optional() < 0 ? 1 : 0;
nerrors += test_set_default_plist_vol_fail() < 0 ? 1 : 0;

if (nerrors) {
printf("***** %d Virtual Object Layer TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : "");
Expand Down
Loading