From c0bd1191ae3eec784eb9d9aeb0aa5b21ed41c1fc Mon Sep 17 00:00:00 2001 From: Jan-Willem Blokland Date: Tue, 14 Nov 2023 20:14:21 +0100 Subject: [PATCH] rest_vol_object: (fix) H5Ovisit (#94) - Fixed the function RV_object_specific() for the case H5Ovisit. If the variable iter_object_type is either H5I_FILE or H5I_GROUP a call to CURL_PERFORM is made before setting the cURL headers correctly. This resulted in a segmentation fault. This has been fixed. - Added the missing brackets in 2 if statements to ensure that the variable url_len is set first before the comparison evaluation. - Corrected the link target path for the test_copy_link and test_move_link tests. - Implemented a test for H5Ovisit() using file_id as root. --- src/rest_vol_object.c | 33 +++++++++++++++++++++++++++------ test/test_rest_vol.c | 40 +++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/rest_vol_object.c b/src/rest_vol_object.c index e4ea4af6..756ed135 100644 --- a/src/rest_vol_object.c +++ b/src/rest_vol_object.c @@ -996,8 +996,8 @@ RV_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_s /* To build object table, information about parent object will be needed */ object_iter_data.iter_obj_parent = iter_object; - if (url_len = snprintf(request_url, URL_MAX_LENGTH, "%s/%s/%s", base_URL, object_type_header, - object_iter_data.iter_obj_parent->URI) < 0) + if ((url_len = snprintf(request_url, URL_MAX_LENGTH, "%s/%s/%s", base_URL, object_type_header, + object_iter_data.iter_obj_parent->URI)) < 0) FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error"); if (url_len >= URL_MAX_LENGTH) @@ -1085,6 +1085,11 @@ RV_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_s * object */ CURL_PERFORM(curl, H5E_LINK, H5E_CANTGET, FAIL); + if (curl_headers) { + curl_slist_free_all(curl_headers); + curl_headers = NULL; + } + if (RV_parse_response(response_buffer.buffer, NULL, &oinfo, RV_get_object_info_callback) < 0) FUNC_GOTO_ERROR(H5E_OBJECT, H5E_PARSEERROR, FAIL, "failed to get object info"); @@ -1104,21 +1109,37 @@ RV_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_s switch (iter_object_type) { case H5I_FILE: case H5I_GROUP: - if (url_len = snprintf(request_url, URL_MAX_LENGTH, "%s/%s/%s%s", base_URL, - object_type_header, object_iter_data.iter_obj_parent->URI, - (!strcmp(object_type_header, "groups") ? "/links" : "")) < 0) + if ((url_len = snprintf(request_url, URL_MAX_LENGTH, "%s/%s/%s%s", base_URL, + object_type_header, object_iter_data.iter_obj_parent->URI, + (!strcmp(object_type_header, "groups") ? "/links" : ""))) < 0) FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "snprintf error"); if (url_len >= URL_MAX_LENGTH) FUNC_GOTO_ERROR(H5E_LINK, H5E_SYSERRSTR, FAIL, "H5Oiterate/visit request URL size exceeded maximum URL size"); + curl_headers = curl_slist_append(curl_headers, host_header); + + /* Disable use of Expect: 100 Continue HTTP response */ + curl_headers = curl_slist_append(curl_headers, "Expect:"); + + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL HTTP headers: %s", + curl_err_buf); + if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_HTTPGET, 1)) + FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, + "can't set up cURL to make HTTP GET request: %s", curl_err_buf); if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_URL, request_url)) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set cURL request URL: %s", curl_err_buf); CURL_PERFORM(curl, H5E_LINK, H5E_CANTGET, FAIL); + if (curl_headers) { + curl_slist_free_all(curl_headers); + curl_headers = NULL; + } + if (RV_parse_response(response_buffer.buffer, &object_iter_data, NULL, RV_object_iter_callback) < 0) FUNC_GOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't iterate over links"); @@ -2162,4 +2183,4 @@ RV_traverse_object_table(object_table_entry *object_table, rv_hash_table_t *visi RV_free(object_rel_path); return ret_value; -} /* end RV_traverse_object_table */ \ No newline at end of file +} /* end RV_traverse_object_table */ diff --git a/test/test_rest_vol.c b/test/test_rest_vol.c index ad01c34e..8453f2dd 100644 --- a/test/test_rest_vol.c +++ b/test/test_rest_vol.c @@ -446,21 +446,23 @@ char filename[FILENAME_MAX_LENGTH]; #define LINK_DELETE_TEST_DSET_NAME1 "link_delete_test_dset1" #define LINK_DELETE_TEST_DSET_NAME2 "link_delete_test_dset2" -#define COPY_LINK_TEST_SOFT_LINK_TARGET_PATH "/" COPY_LINK_TEST_GROUP_NAME "/" COPY_LINK_TEST_DSET_NAME -#define COPY_LINK_TEST_HARD_LINK_COPY_NAME "hard_link_to_dset_copy" -#define COPY_LINK_TEST_SOFT_LINK_COPY_NAME "soft_link_to_dset_copy" -#define COPY_LINK_TEST_HARD_LINK_NAME "hard_link_to_dset" -#define COPY_LINK_TEST_SOFT_LINK_NAME "soft_link_to_dset" -#define COPY_LINK_TEST_GROUP_NAME "link_copy_test_group" -#define COPY_LINK_TEST_DSET_NAME "link_copy_test_dset" -#define COPY_LINK_TEST_DSET_SPACE_RANK 2 - -#define MOVE_LINK_TEST_SOFT_LINK_TARGET_PATH "/" MOVE_LINK_TEST_GROUP_NAME "/" MOVE_LINK_TEST_DSET_NAME -#define MOVE_LINK_TEST_HARD_LINK_NAME "hard_link_to_dset" -#define MOVE_LINK_TEST_SOFT_LINK_NAME "soft_link_to_dset" -#define MOVE_LINK_TEST_GROUP_NAME "link_move_test_group" -#define MOVE_LINK_TEST_DSET_NAME "link_move_test_dset" -#define MOVE_LINK_TEST_DSET_SPACE_RANK 2 +#define COPY_LINK_TEST_SOFT_LINK_TARGET_PATH \ + "/" LINK_TEST_GROUP_NAME "/" COPY_LINK_TEST_GROUP_NAME "/" COPY_LINK_TEST_DSET_NAME +#define COPY_LINK_TEST_HARD_LINK_COPY_NAME "hard_link_to_dset_copy" +#define COPY_LINK_TEST_SOFT_LINK_COPY_NAME "soft_link_to_dset_copy" +#define COPY_LINK_TEST_HARD_LINK_NAME "hard_link_to_dset" +#define COPY_LINK_TEST_SOFT_LINK_NAME "soft_link_to_dset" +#define COPY_LINK_TEST_GROUP_NAME "link_copy_test_group" +#define COPY_LINK_TEST_DSET_NAME "link_copy_test_dset" +#define COPY_LINK_TEST_DSET_SPACE_RANK 2 + +#define MOVE_LINK_TEST_SOFT_LINK_TARGET_PATH \ + "/" LINK_TEST_GROUP_NAME "/" MOVE_LINK_TEST_GROUP_NAME "/" MOVE_LINK_TEST_DSET_NAME +#define MOVE_LINK_TEST_HARD_LINK_NAME "hard_link_to_dset" +#define MOVE_LINK_TEST_SOFT_LINK_NAME "soft_link_to_dset" +#define MOVE_LINK_TEST_GROUP_NAME "link_move_test_group" +#define MOVE_LINK_TEST_DSET_NAME "link_move_test_dset" +#define MOVE_LINK_TEST_DSET_SPACE_RANK 2 #define GET_LINK_INFO_TEST_DSET_SPACE_RANK 2 #define GET_LINK_INFO_TEST_SUBGROUP_NAME "get_link_info_test" @@ -884,7 +886,6 @@ static int (**tests[])(void) = { setup_tests, file_tests, group_tests, attribute_tests, dataset_tests, link_tests, type_tests, object_tests, misc_tests, }; - /***************************************************** * * * Plugin initialization/termination tests * @@ -15393,7 +15394,12 @@ test_object_visit(void) if (H5Ovisit3(container_group, H5_INDEX_NAME, H5_ITER_INC, object_visit_callback, NULL, H5O_INFO_ALL) < 0) { H5_FAILED(); - printf(" H5Ovisit failed!\n"); + printf(" H5Ovisit using container_group failed!\n"); + goto error; + } + if (H5Ovisit(file_id, H5_INDEX_NAME, H5_ITER_DEC, object_visit_callback, NULL, H5O_INFO_ALL) < 0) { + H5_FAILED(); + printf(" H5Ovisit using file_id failed!\n"); goto error; }