Skip to content

Commit

Permalink
Prevent H5Pset_vol from changing default VOL
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Dec 9, 2024
1 parent 945fb3c commit 8bd42de
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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
58 changes: 58 additions & 0 deletions test/vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,63 @@ 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 +2661,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

0 comments on commit 8bd42de

Please sign in to comment.