From c85ca3b7cc3fcb1becf349cbf3db400d452846db Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Mon, 3 Apr 2017 12:34:17 -0500 Subject: Update with checks for index bounds --- src/H5PL.c | 11 ++++++++++- test/plugin.c | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/H5PL.c b/src/H5PL.c index 683c53d..9570289 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -485,6 +485,8 @@ H5PLreplace(const char* plugin_path, unsigned int index) FUNC_ENTER_API(FAIL) if(NULL == plugin_path) 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))) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") @@ -520,6 +522,8 @@ H5PLinsert(const char* plugin_path, unsigned int index) HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table") if(NULL == plugin_path) 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))) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") @@ -553,12 +557,15 @@ H5PLremove(unsigned int index) FUNC_ENTER_API(FAIL) if(H5PL_num_paths_g == 0) 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]) 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_num_paths_g--; for(plindex = index; plindex < (unsigned int)H5PL_num_paths_g; plindex++) H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex + 1]; - H5PL_num_paths_g--; H5PL_path_table_g[H5PL_num_paths_g] = NULL; done: @@ -594,6 +601,8 @@ H5PLget(unsigned int index, char *pathname/*out*/, size_t size) FUNC_ENTER_API(FAIL) if(H5PL_num_paths_g == 0) 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])) HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index") len = HDstrlen(dl_path); diff --git a/test/plugin.c b/test/plugin.c index 2e5319d..a706476 100644 --- a/test/plugin.c +++ b/test/plugin.c @@ -750,6 +750,8 @@ test_filter_path_apis(void) HDputs("Testing access to the filter path table"); + if(H5Zfilter_avail(H5Z_FILTER_DYNLIB1) != TRUE) TEST_ERROR + ndx = H5PLsize(); TESTING(" remove"); @@ -764,7 +766,7 @@ test_filter_path_apis(void) if (H5PLsize() > 0) TEST_ERROR PASSED(); - TESTING(" remove (exceed)"); + TESTING(" remove (exceed min)"); /* Exceed the min path removal */ H5E_BEGIN_TRY { ret = H5PLremove(0); @@ -795,6 +797,7 @@ test_filter_path_apis(void) if (ret >= 0) TEST_ERROR + TESTING(" remove (exceed max)"); /* Exceed the max path removal */ H5E_BEGIN_TRY { ret = H5PLremove(H5PL_MAX_PATH_NUM); -- cgit v0.12