Skip to content

Commit

Permalink
Detect invalid ID to H5Gmove2
Browse files Browse the repository at this point in the history
User's application segfaulted because the returned value H5I_BADID wasn't
detected when H5I_get_type() was called.  This PR adds checks for invalid
file/group identifiers passed into H5Gmove2.

Is that still necessary to check the returned value from H5I_get_type() or
should the fix be checking the returned value from H5I_get_type() instead?

This defect occurs in many other places, hence, issue HDFGroupGH-4764.

Fixes HDFGroupGH-4737
  • Loading branch information
bmribler committed Aug 26, 2024
1 parent d0fe576 commit 215ce16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/H5Gdeprec.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,19 @@ H5Gmove2(hid_t src_loc_id, const char *src_name, hid_t dst_loc_id, const char *d
H5VL_loc_params_t loc_params1;
H5VL_object_t *vol_obj2 = NULL; /* Object of dst_id */
H5VL_loc_params_t loc_params2;
H5I_type_t id_type = H5I_BADID;
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_API(FAIL)

id_type = H5I_get_type(src_loc_id);
if (!(H5I_GROUP == id_type || H5I_FILE == id_type))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid group (or file) ID, src_loc_id");

id_type = H5I_get_type(dst_loc_id);
if (!(H5I_GROUP == id_type || H5I_FILE == id_type))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid group (or file) ID, dst_loc_id");

/* Set up collective metadata if appropriate */
if (H5CX_set_loc(dst_loc_id) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set collective metadata read info");
Expand Down
16 changes: 16 additions & 0 deletions test/links.c
Original file line number Diff line number Diff line change
Expand Up @@ -2117,6 +2117,22 @@ test_deprec(hid_t fapl, bool new_format)
if (H5Gmove2(file_id, "group2", group1_id, "moved_group2") < 0)
FAIL_STACK_ERROR;

/* Test passing in invalid ID */
H5E_BEGIN_TRY
{
if (H5Gmove2(0, "group2", group1_id, "moved_group2") >= 0)
TEST_ERROR;
}
H5E_END_TRY

/* Test passing in invalid ID */
H5E_BEGIN_TRY
{
if (H5Gmove2(file_id, "group2", 0, "moved_group2") >= 0)
TEST_ERROR;
}
H5E_END_TRY

/* Ensure that both groups can be opened */
if (H5Gclose(group2_id) < 0)
FAIL_STACK_ERROR;
Expand Down

0 comments on commit 215ce16

Please sign in to comment.