summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordan Henderson <jhenderson@hdfgroup.org>2019-01-08 21:52:30 (GMT)
committerJordan Henderson <jhenderson@hdfgroup.org>2019-01-08 21:52:30 (GMT)
commit2d7eb9a4c3a841f7612b88f6b559792cb6143930 (patch)
tree97c612317c334a25d22d550412a864c307a8be38
parent3f727a272c5511efd25d1417d435cb71fc3062b4 (diff)
downloadhdf5-2d7eb9a4c3a841f7612b88f6b559792cb6143930.zip
hdf5-2d7eb9a4c3a841f7612b88f6b559792cb6143930.tar.gz
hdf5-2d7eb9a4c3a841f7612b88f6b559792cb6143930.tar.bz2
Align behavior of H5Aget_name_by_idx with H5Aget_name when a NULL buffer is supplied
-rw-r--r--src/H5A.c2
-rw-r--r--test/tattr.c57
2 files changed, 59 insertions, 0 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 1b804d9..9c3ad7e 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -951,6 +951,8 @@ H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
if(!obj_name || !*obj_name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
+ if(!name && size)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "name cannot be NULL if size is non-zero")
if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
diff --git a/test/tattr.c b/test/tattr.c
index c1167c6..454ea71 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -150,6 +150,8 @@ float attr_data5=-5.123F; /* Test data for 5th attribute */
#define INVALID_RENAME_TEST_ATTR_NAME "InvalidRenameTestAttr"
#define INVALID_RENAME_TEST_NEW_ATTR_NAME "InvalidRenameTestNewAttr"
+/* Used by test_attr_get_name_invalid_buf() */
+#define GET_NAME_INVALID_BUF_TEST_ATTR_NAME "InvalidNameBufferTestAttr"
/* Attribute iteration struct */
typedef struct {
@@ -6138,6 +6140,60 @@ test_attr_rename_invalid_name(hid_t fcpl, hid_t fapl)
}
+/***************************************************************
+**
+** test_attr_get_name_invalid_buf(): A test to ensure that
+** passing a NULL buffer to H5Aget_name(_by_idx) when
+** the 'size' parameter is non-zero doesn't cause bad
+** behavior.
+**
+****************************************************************/
+static void
+test_attr_get_name_invalid_buf(hid_t fcpl, hid_t fapl)
+{
+ ssize_t err_ret = -1;
+ hid_t fid;
+ hid_t attr;
+ hid_t sid;
+
+ /* Create dataspace for attribute */
+ sid = H5Screate(H5S_SCALAR);
+ CHECK(sid, FAIL, "H5Screate");
+
+ /* Create file */
+ fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl, fapl);
+ CHECK(fid, FAIL, "H5Fcreate");
+
+ /* Create attribute */
+ attr = H5Acreate2(fid, GET_NAME_INVALID_BUF_TEST_ATTR_NAME, H5T_NATIVE_UINT, sid, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(attr, FAIL, "H5Acreate2");
+
+ H5E_BEGIN_TRY {
+ err_ret = H5Aget_name(attr, 1, NULL);
+ } H5E_END_TRY;
+
+ VERIFY(err_ret, FAIL, "H5Aget_name");
+
+ H5E_BEGIN_TRY {
+ err_ret = H5Aget_name_by_idx(fid, ".", H5_INDEX_NAME, H5_ITER_INC, 0, NULL, 1, H5P_DEFAULT);
+ } H5E_END_TRY;
+
+ VERIFY(err_ret, FAIL, "H5Aget_name_by_idx");
+
+ /* Close dataspace */
+ err_ret = H5Sclose(sid);
+ CHECK(err_ret, FAIL, "H5Sclose");
+
+ /* Close attribute */
+ err_ret = H5Aclose(attr);
+ CHECK(err_ret, FAIL, "H5Aclose");
+
+ /* Close file */
+ err_ret = H5Fclose(fid);
+ CHECK(err_ret, FAIL, "H5Fclose");
+}
+
+
/****************************************************************
**
** test_attr_delete_by_idx(): Test basic H5A (attribute) code.
@@ -11176,6 +11232,7 @@ test_attr(void)
test_attr_many(new_format, my_fcpl, my_fapl); /* Test storing lots of attributes */
test_attr_info_null_info_pointer(my_fcpl, my_fapl); /* Test passing a NULL attribute info pointer to H5Aget_info(_by_name/_by_idx) */
test_attr_rename_invalid_name(my_fcpl, my_fapl); /* Test passing a NULL or empty attribute name to H5Arename(_by_name) */
+ test_attr_get_name_invalid_buf(my_fcpl, my_fapl); /* Test passing NULL buffer to H5Aget_name(_by_idx) */
/* New attribute API routine tests
*/