summaryrefslogtreecommitdiffstats
path: root/tools/h5dump
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2016-01-12 20:31:59 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2016-01-12 20:31:59 (GMT)
commit24443da31663e4f0835e8b966470aff6dfb4f0c9 (patch)
tree175bba5c4d2bc6343984d0c79c930b3607a84c0a /tools/h5dump
parent2396a172adc0fca7ad56fe6bd89276903dc8af44 (diff)
downloadhdf5-24443da31663e4f0835e8b966470aff6dfb4f0c9.zip
hdf5-24443da31663e4f0835e8b966470aff6dfb4f0c9.tar.gz
hdf5-24443da31663e4f0835e8b966470aff6dfb4f0c9.tar.bz2
[svn-r28865] HDFFV-9639: Fix double-free error by setting freed var to NULL.
Verified issue with "h5dump tgroup.h5 non_existing.h5" Applied patch and retested.
Diffstat (limited to 'tools/h5dump')
-rw-r--r--tools/h5dump/CMakeTests.cmake39
-rw-r--r--tools/h5dump/errfiles/non_existing.err1
-rw-r--r--tools/h5dump/h5dump.c64
3 files changed, 60 insertions, 44 deletions
diff --git a/tools/h5dump/CMakeTests.cmake b/tools/h5dump/CMakeTests.cmake
index 00ec760..c256e11 100644
--- a/tools/h5dump/CMakeTests.cmake
+++ b/tools/h5dump/CMakeTests.cmake
@@ -4,7 +4,7 @@
### T E S T I N G ###
##############################################################################
##############################################################################
-
+
# --------------------------------------------------------------------
# Copy all the HDF5 files from the test directory into the source directory
# --------------------------------------------------------------------
@@ -12,6 +12,7 @@
${HDF5_TOOLS_SRC_DIR}/testfiles/charsets.ddl
${HDF5_TOOLS_SRC_DIR}/testfiles/file_space.ddl
${HDF5_TOOLS_SRC_DIR}/testfiles/filter_fail.ddl
+ ${HDF5_TOOLS_SRC_DIR}/testfiles/non_existing.ddl
${HDF5_TOOLS_SRC_DIR}/testfiles/packedbits.ddl
${HDF5_TOOLS_SRC_DIR}/testfiles/tall-1.ddl
${HDF5_TOOLS_SRC_DIR}/testfiles/tall-2.ddl
@@ -284,6 +285,7 @@
)
set (HDF5_ERROR_REFERENCE_TEST_FILES
${PROJECT_SOURCE_DIR}/errfiles/filter_fail.err
+ ${PROJECT_SOURCE_DIR}/errfiles/non_existing.err
${PROJECT_SOURCE_DIR}/errfiles/tall-1.err
${PROJECT_SOURCE_DIR}/errfiles/tall-2A.err
${PROJECT_SOURCE_DIR}/errfiles/tall-2A0.err
@@ -325,7 +327,7 @@
ARGS -E copy_if_different ${tst_h5_file} ${dest}
)
endforeach (tst_h5_file ${HDF5_REFERENCE_TEST_FILES})
-
+
foreach (tst_exp_file ${HDF5_REFERENCE_EXP_FILES})
if (WIN32)
file (READ ${HDF5_TOOLS_SRC_DIR}/testfiles/${tst_exp_file} TEST_STREAM)
@@ -373,7 +375,7 @@
COMMAND ${CMAKE_COMMAND}
ARGS -E copy_if_different ${HDF5_TOOLS_SOURCE_DIR}/testfiles/tbin1.ddl ${PROJECT_BINARY_DIR}/testfiles/std/tbin1LE.ddl
)
-
+
if (WIN32)
file (READ ${HDF5_TOOLS_SRC_DIR}/testfiles/tbinregR.exp TEST_STREAM)
file (WRITE ${PROJECT_BINARY_DIR}/testfiles/std/tbinregR.exp "${TEST_STREAM}")
@@ -385,7 +387,7 @@
ARGS -E copy_if_different ${HDF5_TOOLS_SRC_DIR}/testfiles/tbinregR.exp ${PROJECT_BINARY_DIR}/testfiles/std/tbinregR.exp
)
endif (WIN32)
-
+
##############################################################################
##############################################################################
### T H E T E S T S M A C R O S ###
@@ -730,7 +732,7 @@
add_test (
NAME H5DUMP-clearall-objects
COMMAND ${CMAKE_COMMAND}
- -E remove
+ -E remove
h5dump-help.out
charsets.out
charsets.out.err
@@ -738,6 +740,8 @@
file_space.out.err
filter_fail.out
filter_fail.out.err
+ non_existing.out
+ non_existing.out.err
packedbits.out
packedbits.out.err
tall-1.out
@@ -1075,9 +1079,9 @@
ADD_H5_TEST_EXPORT (trawdatafile packedbits.h5 0 --enable-error-stack -y -o)
ADD_H5_TEST_EXPORT (tnoddlfile packedbits.h5 0 --enable-error-stack -O -y -o)
ADD_H5_TEST_EXPORT (trawssetfile tdset.h5 0 --enable-error-stack -d "/dset1[1,1;;;]" -y -o)
-
+
ADD_H5_TEST_EXPORT_DDL (twithddlfile packedbits.h5 0 twithddl --enable-error-stack --ddl=twithddl.txt -y -o)
-
+
# test for maximum display datasets
ADD_H5_TEST (twidedisplay 0 --enable-error-stack -w0 packedbits.h5)
@@ -1147,7 +1151,7 @@
# test for named data types
ADD_H5_TEST (tcomp-2 0 --enable-error-stack -t /type1 --datatype /type2 --datatype=/group1/type3 tcompound.h5)
ADD_H5_TEST_N (tcomp-2 0 --enable-error-stack -N /type1 --any_path /type2 --any_path=/group1/type3 tcompound.h5)
- # test for unamed type
+ # test for unamed type
ADD_H5ERR_MASK_TEST (tcomp-3 0 "--enable-error-stack;-t;/#6632;-g;/group2;tcompound.h5")
# test complicated compound datatype
ADD_H5_TEST (tcomp-4 0 --enable-error-stack tcompound_complex.h5)
@@ -1169,7 +1173,7 @@
# test for loop detection
ADD_H5_TEST (tloop-1 0 --enable-error-stack tloop.h5)
- # test for string
+ # test for string
ADD_H5_TEST (tstr-1 0 --enable-error-stack tstr.h5)
ADD_H5_TEST (tstr-2 0 --enable-error-stack tstr2.h5)
@@ -1202,7 +1206,7 @@
#ADD_H5_MASK_TEST (tstarfile 0 --enable-error-stack -H -d Dataset1 tarr*.h5)
#ADD_H5_MASK_TEST (tqmarkfile 0 --enable-error-stack -H -d Dataset1 tarray?.h5)
ADD_H5_TEST (tmultifile 0 --enable-error-stack -H -d Dataset1 tarray2.h5 tarray3.h5 tarray4.h5 tarray5.h5 tarray6.h5 tarray7.h5)
-
+
# test for files with empty data
ADD_H5_TEST (tempty 0 --enable-error-stack tempty.h5)
@@ -1263,7 +1267,7 @@
ADD_H5_TEST (tcontiguos 0 --enable-error-stack -H -p -d contiguous tfilters.h5)
# chunked
ADD_H5_TEST (tchunked 0 --enable-error-stack -H -p -d chunked tfilters.h5)
- # external
+ # external
ADD_H5_TEST (texternal 0 --enable-error-stack -H -p -d external tfilters.h5)
# fill values
@@ -1331,7 +1335,7 @@
# don't have). Do this by searching H5pubconf.h to see which
# filters are defined.
-# detect whether the encoder is present.
+# detect whether the encoder is present.
if (H5_HAVE_FILTER_DEFLATE)
set (USE_FILTER_DEFLATE "true")
endif (H5_HAVE_FILTER_DEFLATE)
@@ -1352,12 +1356,12 @@
# test for displaying objects with very long names
ADD_H5_TEST (tlonglinks 0 --enable-error-stack tlonglinks.h5)
- # dimensions over 4GB, print boundary
+ # dimensions over 4GB, print boundary
ADD_H5_TEST (tbigdims 0 --enable-error-stack -d dset4gb -s 4294967284 -c 22 tbigdims.h5)
# hyperslab read
ADD_H5_TEST (thyperslab 0 --enable-error-stack thyperslab.h5)
-
+
# test for displaying dataset and attribute of null space
ADD_H5_TEST (tnullspace 0 --enable-error-stack tnullspace.h5)
@@ -1391,7 +1395,7 @@
ADD_H5_TEST (tbin4 0 --enable-error-stack -d double -b FILE -o tbin4.bin tbinary.h5)
endif (NOT HDF5_ENABLE_USING_MEMCHECKER)
- # test for dataset region references
+ # test for dataset region references
ADD_H5_TEST (tdatareg 0 --enable-error-stack tdatareg.h5)
ADD_H5ERR_MASK_TEST (tdataregR 0 --enable-error-stack -R tdatareg.h5)
ADD_H5ERR_MASK_TEST (tattrregR 0 -R --enable-error-stack tattrreg.h5)
@@ -1414,7 +1418,7 @@
# tests for link references and order
ADD_H5ERR_MASK_TEST (torderlinks1 0 --enable-error-stack --sort_by=name --sort_order=ascending tfcontents1.h5)
ADD_H5ERR_MASK_TEST (torderlinks2 0 --enable-error-stack --sort_by=name --sort_order=descending tfcontents1.h5)
-
+
# tests for floating point user defined printf format
ADD_H5_TEST (tfpformat 0 --enable-error-stack -m %.7f tfpformat.h5)
@@ -1430,3 +1434,6 @@
# test for -o -y for dataset with attributes
ADD_H5_TEST_EXPORT (tall-6 tall.h5 0 --enable-error-stack -d /g1/g1.1/dset1.1.1 -y -o)
+
+ # test for non-existing file
+ ADD_H5_TEST (non_existing 1 --enable-error-stack tgroup.h5 non_existing.h5)
diff --git a/tools/h5dump/errfiles/non_existing.err b/tools/h5dump/errfiles/non_existing.err
new file mode 100644
index 0000000..f7e3afa
--- /dev/null
+++ b/tools/h5dump/errfiles/non_existing.err
@@ -0,0 +1 @@
+h5dump error: unable to open file "non_existing.h5"
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 68889c9..ffba581 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -620,7 +620,7 @@ parse_hsize_list(const char *h_list, subset_d *d)
size_count++;
last_digit = 1;
- }
+ }
else {
last_digit = 0;
}
@@ -643,7 +643,7 @@ parse_hsize_list(const char *h_list, subset_d *d)
}
d->data = p_list;
d->len = size_count;
-
+
return;
}
@@ -705,7 +705,7 @@ parse_subset_params(char *dset)
*
* Purpose: Parse a list of comma or space separated integers and fill
* the packed_bits list and counter. The string being passed into this function
- * should be at the start of the list you want to parse.
+ * should be at the start of the list you want to parse.
*
* Return: Success: SUCCEED
*
@@ -831,7 +831,7 @@ static void
free_handler(struct handler_t *hand, int len)
{
int i;
-
+
if(hand) {
for (i = 0; i < len; i++) {
if(hand[i].obj) {
@@ -1161,7 +1161,7 @@ parse_start:
}
if (HDstrcmp(opt_arg,":") == 0) {
xmlnsprefix = "";
- }
+ }
else {
xmlnsprefix = opt_arg;
}
@@ -1187,7 +1187,7 @@ parse_start:
* the two.
*/
s = last_dset->subset_info;
- }
+ }
else {
last_dset->subset_info = s = (struct subset_t *)HDcalloc(1, sizeof(struct subset_t));
}
@@ -1358,7 +1358,7 @@ main(int argc, const char *argv[])
/* Disable tools error reporting */
H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
-
+
if((hand = parse_command_line(argc, argv))==NULL) {
goto done;
}
@@ -1444,12 +1444,12 @@ main(int argc, const char *argv[])
if (xml_dtd_uri == NULL) {
if (useschema) {
xml_dtd_uri = DEFAULT_XSD;
- }
+ }
else {
xml_dtd_uri = DEFAULT_DTD;
xmlnsprefix = "";
}
- }
+ }
else {
if (useschema && HDstrcmp(xmlnsprefix,"")) {
error_msg("Cannot set Schema URL for a qualified namespace--use -X or -U option with -D \n");
@@ -1486,7 +1486,7 @@ main(int argc, const char *argv[])
/* start to dump - display file header information */
if (!doxml) {
begin_obj(h5tools_dump_header_format->filebegin, fname, h5tools_dump_header_format->fileblockbegin);
- }
+ }
else {
PRINTVALSTREAM(rawoutstream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
@@ -1495,7 +1495,7 @@ main(int argc, const char *argv[])
if (HDstrcmp(xmlnsprefix,"") == 0) {
PRINTSTREAM(rawoutstream, "<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n",
xml_dtd_uri);
- }
+ }
else {
/* TO DO: make -url option work in this case (may need new option) */
char *ns;
@@ -1511,7 +1511,7 @@ main(int argc, const char *argv[])
"http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.xsd\">\n",xmlnsprefix,ns);
HDfree(ns);
}
- }
+ }
else {
PRINTSTREAM(rawoutstream, "<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n", xml_dtd_uri);
PRINTVALSTREAM(rawoutstream, "<HDF5-File>\n");
@@ -1570,7 +1570,7 @@ main(int argc, const char *argv[])
if (!doxml) {
end_obj(h5tools_dump_header_format->fileend, h5tools_dump_header_format->fileblockend);
PRINTVALSTREAM(rawoutstream, "\n");
- }
+ }
else {
PRINTSTREAM(rawoutstream, "</%sHDF5-File>\n", xmlnsprefix);
}
@@ -1581,13 +1581,17 @@ main(int argc, const char *argv[])
if (H5Fclose(fid) < 0)
h5tools_setstatus(EXIT_FAILURE);
- if(prefix)
+ if(prefix) {
HDfree(prefix);
- if(fname)
+ prefix = NULL;
+ }
+ if(fname) {
HDfree(fname);
+ fname = NULL;
+ }
} /* end while */
- if(hand)
+ if(hand)
free_handler(hand, argc);
/* To Do: clean up XML table */
@@ -1601,13 +1605,17 @@ done:
if(fid >=0)
if (H5Fclose(fid) < 0)
h5tools_setstatus(EXIT_FAILURE);
-
- if(prefix)
+
+ if(prefix) {
HDfree(prefix);
- if(fname)
+ prefix = NULL;
+ }
+ if(fname) {
HDfree(fname);
+ fname = NULL;
+ }
- if(hand)
+ if(hand)
free_handler(hand, argc);
/* To Do: clean up XML table */
@@ -1660,20 +1668,20 @@ h5_fileaccess(void)
if (!HDstrcmp(name, "sec2")) {
/* Unix read() and write() system calls */
if (H5Pset_fapl_sec2(fapl)<0) return -1;
- }
+ }
else if (!HDstrcmp(name, "stdio")) {
/* Standard C fread() and fwrite() system calls */
if (H5Pset_fapl_stdio(fapl)<0) return -1;
- }
+ }
else if (!HDstrcmp(name, "core")) {
/* In-core temporary file with 1MB increment */
if (H5Pset_fapl_core(fapl, 1024*1024, FALSE)<0) return -1;
- }
+ }
else if (!HDstrcmp(name, "split")) {
/* Split meta data and raw data each using default driver */
if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0)
return -1;
- }
+ }
else if (!HDstrcmp(name, "multi")) {
/* Multi-file driver, general case of the split driver */
H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
@@ -1699,7 +1707,7 @@ h5_fileaccess(void)
if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE) < 0)
return -1;
- }
+ }
else if (!HDstrcmp(name, "family")) {
hsize_t fam_size = 100*1024*1024; /*100 MB*/
@@ -1708,7 +1716,7 @@ h5_fileaccess(void)
fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024);
if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0)
return -1;
- }
+ }
else if (!HDstrcmp(name, "log")) {
long log_flags = H5FD_LOG_LOC_IO;
@@ -1718,12 +1726,12 @@ h5_fileaccess(void)
if (H5Pset_fapl_log(fapl, NULL, (unsigned)log_flags, 0) < 0)
return -1;
- }
+ }
else if (!HDstrcmp(name, "direct")) {
/* Substitute Direct I/O driver with sec2 driver temporarily because
* some output has sec2 driver as the standard. */
if (H5Pset_fapl_sec2(fapl)<0) return -1;
- }
+ }
else {
/* Unknown driver */
return -1;