mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-12-15 07:40:23 +08:00
Update with checks for index bounds
This commit is contained in:
parent
dd2749d1be
commit
399060c17a
11
src/H5PL.c
11
src/H5PL.c
@ -494,6 +494,8 @@ H5PLreplace(const char* plugin_path, unsigned int index)
|
|||||||
FUNC_ENTER_API(FAIL)
|
FUNC_ENTER_API(FAIL)
|
||||||
if(NULL == plugin_path)
|
if(NULL == plugin_path)
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided")
|
||||||
|
if(index >= H5PL_MAX_PATH_NUM)
|
||||||
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "index path out of bounds for table")
|
||||||
if(NULL == (dl_path = H5MM_strdup(plugin_path)))
|
if(NULL == (dl_path = H5MM_strdup(plugin_path)))
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
||||||
|
|
||||||
@ -529,6 +531,8 @@ H5PLinsert(const char* plugin_path, unsigned int index)
|
|||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table")
|
||||||
if(NULL == plugin_path)
|
if(NULL == plugin_path)
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided")
|
||||||
|
if(index >= H5PL_MAX_PATH_NUM)
|
||||||
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "index path out of bounds for table")
|
||||||
if(NULL == (dl_path = H5MM_strdup(plugin_path)))
|
if(NULL == (dl_path = H5MM_strdup(plugin_path)))
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path")
|
||||||
|
|
||||||
@ -562,12 +566,15 @@ H5PLremove(unsigned int index)
|
|||||||
FUNC_ENTER_API(FAIL)
|
FUNC_ENTER_API(FAIL)
|
||||||
if(H5PL_num_paths_g == 0)
|
if(H5PL_num_paths_g == 0)
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table")
|
||||||
|
if(index >= H5PL_MAX_PATH_NUM)
|
||||||
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "index path out of bounds for table")
|
||||||
if(NULL == H5PL_path_table_g[index])
|
if(NULL == H5PL_path_table_g[index])
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index")
|
||||||
H5PL_path_table_g[index] = (char *)H5MM_xfree(H5PL_path_table_g[index]);
|
H5PL_path_table_g[index] = (char *)H5MM_xfree(H5PL_path_table_g[index]);
|
||||||
|
|
||||||
|
H5PL_num_paths_g--;
|
||||||
for(plindex = index; plindex < (unsigned int)H5PL_num_paths_g; plindex++)
|
for(plindex = index; plindex < (unsigned int)H5PL_num_paths_g; plindex++)
|
||||||
H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex + 1];
|
H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex + 1];
|
||||||
H5PL_num_paths_g--;
|
|
||||||
H5PL_path_table_g[H5PL_num_paths_g] = NULL;
|
H5PL_path_table_g[H5PL_num_paths_g] = NULL;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -603,6 +610,8 @@ H5PLget(unsigned int index, char *pathname/*out*/, size_t size)
|
|||||||
FUNC_ENTER_API(FAIL)
|
FUNC_ENTER_API(FAIL)
|
||||||
if(H5PL_num_paths_g == 0)
|
if(H5PL_num_paths_g == 0)
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table")
|
||||||
|
if(index >= H5PL_MAX_PATH_NUM)
|
||||||
|
HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "index path out of bounds for table")
|
||||||
if(NULL == (dl_path = H5PL_path_table_g[index]))
|
if(NULL == (dl_path = H5PL_path_table_g[index]))
|
||||||
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index")
|
HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index")
|
||||||
len = HDstrlen(dl_path);
|
len = HDstrlen(dl_path);
|
||||||
|
@ -750,6 +750,8 @@ test_filter_path_apis(void)
|
|||||||
|
|
||||||
HDputs("Testing access to the filter path table");
|
HDputs("Testing access to the filter path table");
|
||||||
|
|
||||||
|
if(H5Zfilter_avail(H5Z_FILTER_DYNLIB1) != TRUE) TEST_ERROR
|
||||||
|
|
||||||
ndx = H5PLsize();
|
ndx = H5PLsize();
|
||||||
|
|
||||||
TESTING(" remove");
|
TESTING(" remove");
|
||||||
@ -764,7 +766,7 @@ test_filter_path_apis(void)
|
|||||||
if (H5PLsize() > 0) TEST_ERROR
|
if (H5PLsize() > 0) TEST_ERROR
|
||||||
PASSED();
|
PASSED();
|
||||||
|
|
||||||
TESTING(" remove (exceed)");
|
TESTING(" remove (exceed min)");
|
||||||
/* Exceed the min path removal */
|
/* Exceed the min path removal */
|
||||||
H5E_BEGIN_TRY {
|
H5E_BEGIN_TRY {
|
||||||
ret = H5PLremove(0);
|
ret = H5PLremove(0);
|
||||||
@ -795,6 +797,7 @@ test_filter_path_apis(void)
|
|||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
|
|
||||||
|
TESTING(" remove (exceed max)");
|
||||||
/* Exceed the max path removal */
|
/* Exceed the max path removal */
|
||||||
H5E_BEGIN_TRY {
|
H5E_BEGIN_TRY {
|
||||||
ret = H5PLremove(H5PL_MAX_PATH_NUM);
|
ret = H5PLremove(H5PL_MAX_PATH_NUM);
|
||||||
@ -815,7 +818,7 @@ test_filter_path_apis(void)
|
|||||||
HDfprintf(stderr," get 0 len: %d : %s\n", pathlen, pathname);
|
HDfprintf(stderr," get 0 len: %d : %s\n", pathlen, pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
if (strcmp(pathname, "a_path_0") != 0) {
|
if (HDstrcmp(pathname, "a_path_0") != 0) {
|
||||||
HDfprintf(stderr," get 0: %s\n", pathname);
|
HDfprintf(stderr," get 0: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
@ -824,14 +827,14 @@ test_filter_path_apis(void)
|
|||||||
TESTING(" get (bounds)");
|
TESTING(" get (bounds)");
|
||||||
if ((pathlen = H5PLget(1, pathname, 256)) <= 0)
|
if ((pathlen = H5PLget(1, pathname, 256)) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
if (strcmp(pathname, "a_path_1") != 0) {
|
if (HDstrcmp(pathname, "a_path_1") != 0) {
|
||||||
HDfprintf(stderr," get 1: %s\n", pathname);
|
HDfprintf(stderr," get 1: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
if ((pathlen = H5PLget(H5PL_MAX_PATH_NUM - 1, pathname, 256)) <= 0)
|
if ((pathlen = H5PLget(H5PL_MAX_PATH_NUM - 1, pathname, 256)) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
HDsprintf(tempname, "a_path_%d", H5PL_MAX_PATH_NUM - 1);
|
HDsprintf(tempname, "a_path_%d", H5PL_MAX_PATH_NUM - 1);
|
||||||
if (strcmp(pathname, tempname) != 0) {
|
if (HDstrcmp(pathname, tempname) != 0) {
|
||||||
HDfprintf(stderr," get %d: %s\n", H5PL_MAX_PATH_NUM - 1, pathname);
|
HDfprintf(stderr," get %d: %s\n", H5PL_MAX_PATH_NUM - 1, pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
@ -852,7 +855,7 @@ test_filter_path_apis(void)
|
|||||||
/* Verify that the entries were moved */
|
/* Verify that the entries were moved */
|
||||||
if ((pathlen = H5PLget(8, pathname, 256)) <= 0)
|
if ((pathlen = H5PLget(8, pathname, 256)) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
if (strcmp(pathname, "a_path_9") != 0) {
|
if (HDstrcmp(pathname, "a_path_9") != 0) {
|
||||||
HDfprintf(stderr," get 8: %s\n", pathname);
|
HDfprintf(stderr," get 8: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
@ -875,14 +878,14 @@ test_filter_path_apis(void)
|
|||||||
/* Verify that the entries were moved */
|
/* Verify that the entries were moved */
|
||||||
if (H5PLget(8, pathname, 256) <= 0)
|
if (H5PLget(8, pathname, 256) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
if (strcmp(pathname, "a_path_7") != 0) {
|
if (HDstrcmp(pathname, "a_path_7") != 0) {
|
||||||
HDfprintf(stderr," get 8: %s\n", pathname);
|
HDfprintf(stderr," get 8: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
if (H5PLget(0, pathname, 256) <= 0)
|
if (H5PLget(0, pathname, 256) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
HDsprintf(tempname, "a_path_%d", H5PL_MAX_PATH_NUM + 1);
|
HDsprintf(tempname, "a_path_%d", H5PL_MAX_PATH_NUM + 1);
|
||||||
if (strcmp(pathname, tempname) != 0) {
|
if (HDstrcmp(pathname, tempname) != 0) {
|
||||||
HDfprintf(stderr," get 0: %s\n", pathname);
|
HDfprintf(stderr," get 0: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
@ -913,13 +916,13 @@ test_filter_path_apis(void)
|
|||||||
if (H5PLget(0, pathname, 256) <= 0)
|
if (H5PLget(0, pathname, 256) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
HDsprintf(tempname, "a_path_%d", H5PL_MAX_PATH_NUM + 1);
|
HDsprintf(tempname, "a_path_%d", H5PL_MAX_PATH_NUM + 1);
|
||||||
if (strcmp(pathname, tempname) != 0) {
|
if (HDstrcmp(pathname, tempname) != 0) {
|
||||||
HDfprintf(stderr," get 0: %s\n", pathname);
|
HDfprintf(stderr," get 0: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
if (H5PLget(2, pathname, 256) <= 0)
|
if (H5PLget(2, pathname, 256) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
if (strcmp(pathname, "a_path_1") != 0) {
|
if (HDstrcmp(pathname, "a_path_1") != 0) {
|
||||||
HDfprintf(stderr," get 2: %s\n", pathname);
|
HDfprintf(stderr," get 2: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
@ -932,7 +935,7 @@ test_filter_path_apis(void)
|
|||||||
/* Verify that the entries were moved */
|
/* Verify that the entries were moved */
|
||||||
if (H5PLget(4, pathname, 256) <= 0)
|
if (H5PLget(4, pathname, 256) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
if (strcmp(pathname, "a_path_4") != 0) {
|
if (HDstrcmp(pathname, "a_path_4") != 0) {
|
||||||
HDfprintf(stderr," get 4: %s\n", pathname);
|
HDfprintf(stderr," get 4: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
@ -952,7 +955,7 @@ test_filter_path_apis(void)
|
|||||||
/* Verify that the entries were moved */
|
/* Verify that the entries were moved */
|
||||||
if (H5PLget(4, pathname, 256) <= 0)
|
if (H5PLget(4, pathname, 256) <= 0)
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
if (strcmp(pathname, "a_path_2") != 0){
|
if (HDstrcmp(pathname, "a_path_2") != 0){
|
||||||
HDfprintf(stderr," get 4: %s\n", pathname);
|
HDfprintf(stderr," get 4: %s\n", pathname);
|
||||||
TEST_ERROR
|
TEST_ERROR
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user