summaryrefslogtreecommitdiffstats
path: root/hl/src/H5LT.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src/H5LT.c')
-rw-r--r--hl/src/H5LT.c107
1 files changed, 103 insertions, 4 deletions
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 6da097c..071b8a5 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -524,6 +524,10 @@ H5LT_make_dataset_numerical( hid_t loc_id,
{
hid_t did = -1, sid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Create the data space for the dataset. */
if((sid = H5Screate_simple(rank, dims, NULL)) < 0)
return -1;
@@ -799,6 +803,10 @@ herr_t H5LTmake_dataset_string(hid_t loc_id,
hid_t tid = -1;
size_t size;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* create a string data type */
if((tid = H5Tcopy(H5T_C_S1)) < 0 )
goto out;
@@ -977,6 +985,10 @@ H5LT_read_dataset_numerical(hid_t loc_id, const char *dset_name, hid_t tid, void
{
hid_t did;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1168,6 +1180,10 @@ herr_t H5LTread_dataset_string( hid_t loc_id,
hid_t did = -1;
hid_t tid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1217,6 +1233,10 @@ herr_t H5LTget_dataset_ndims( hid_t loc_id,
hid_t did = -1;
hid_t sid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1273,6 +1293,10 @@ herr_t H5LTget_dataset_info( hid_t loc_id,
hid_t tid = -1;
hid_t sid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1346,6 +1370,10 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d
*/
int ret = 0;
+ /* check the arguments */
+ if (name == NULL)
+ return ret;
+
/* Shut the compiler up */
loc_id = loc_id;
linfo = linfo;
@@ -1354,7 +1382,7 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d
* cause the iterator to immediately return that positive value,
* indicating short-circuit success
*/
- if(HDstrcmp(name, (char *)op_data) == 0)
+ if(HDstrncmp(name, (char *)op_data, HDstrlen((char *)op_data)) == 0)
ret = 1;
return ret;
@@ -1429,6 +1457,14 @@ herr_t H5LTset_attribute_string( hid_t loc_id,
int has_attr;
size_t attr_size;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+ if (attr_data == NULL)
+ return -1;
+
/* Open the object */
if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1518,6 +1554,12 @@ herr_t H5LT_set_attribute_numerical( hid_t loc_id,
hsize_t dim_size=size;
int has_attr;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1929,6 +1971,10 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
{
int ret = H5_ITER_CONT;
+ /* check the arguments */
+ if (name == NULL)
+ return H5_ITER_CONT;
+
/* Shut compiler up */
loc_id = loc_id; ainfo = ainfo;
@@ -1936,7 +1982,7 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
* cause the iterator to immediately return that positive value,
* indicating short-circuit success
*/
- if(HDstrcmp(name, (char *)op_data) == 0)
+ if(HDstrncmp(name, (char *)op_data, HDstrlen((char *)op_data)) == 0)
ret = H5_ITER_STOP;
return ret;
@@ -2021,6 +2067,12 @@ herr_t H5LTget_attribute_ndims( hid_t loc_id,
hid_t sid;
hid_t obj_id;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -2088,6 +2140,12 @@ herr_t H5LTget_attribute_info( hid_t loc_id,
hid_t sid;
hid_t obj_id;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -2163,6 +2221,10 @@ hid_t H5LTtext_to_dtype(const char *text, H5LT_lang_t lang_type)
{
hid_t type_id;
+ /* check the arguments */
+ if (text == NULL)
+ return -1;
+
if(lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG)
goto out;
@@ -2206,6 +2268,8 @@ out:
static char*
realloc_and_append(hbool_t _no_user_buf, size_t *len, char *buf, char *str_to_add)
{
+ size_t size_str_to_add, size_str;
+
if(_no_user_buf) {
/* If the buffer isn't big enough, reallocate it. Otherwise, go to do strcat. */
if(str_to_add && ((ssize_t)(*len - (HDstrlen(buf) + HDstrlen(str_to_add) + 1)) < LIMIT)) {
@@ -2220,8 +2284,25 @@ realloc_and_append(hbool_t _no_user_buf, size_t *len, char *buf, char *str_to_ad
if(!buf)
goto out;
- if(str_to_add)
- HDstrcat(buf, str_to_add);
+ if(str_to_add) {
+ /* find the size of the buffer to add */
+ size_str_to_add = HDstrlen(str_to_add);
+ /* find the size of the current buffer */
+ size_str = HDstrlen(buf);
+
+ /* Check to make sure the appended string does not
+ * extend past the allocated buffer; if it does then truncate the string
+ */
+ if(size_str < *len - 1) {
+ if( size_str + size_str_to_add < *len - 1) {
+ HDstrncat(buf, str_to_add, size_str_to_add);
+ } else {
+ HDstrncat(buf, str_to_add, (*len - 1) - size_str);
+ }
+ } else {
+ buf[*len-1] = '\0'; /* buffer is full, null terminate */
+ }
+ }
return buf;
@@ -3020,6 +3101,12 @@ herr_t H5LTget_attribute_string( hid_t loc_id,
/* identifiers */
hid_t obj_id;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if ((obj_id = H5Oopen( loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -3440,6 +3527,12 @@ static herr_t H5LT_get_attribute_mem(hid_t loc_id,
hid_t obj_id = -1;
hid_t attr_id = -1;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
goto out;
@@ -3619,6 +3712,12 @@ H5LTpath_valid(hid_t loc_id, const char *path, hbool_t check_object_valid)
/* Initialize */
ret_value = FALSE;
+ /* check the arguments */
+ if (path == NULL) {
+ ret_value = FAIL;
+ goto done;
+ }
+
/* Find the type of loc_id */
if((obj_type = H5Iget_type(loc_id)) == H5I_BADID) {
ret_value = FAIL;