From 3026e03ffe1a9fbd117a2d03fb7259a5a3e3ce8b Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Wed, 20 Jan 2010 16:26:17 -0500 Subject: [svn-r18127] Purpose: Fix for bug1749: Incorrect code in diff() function for links compare Also removed duplicated redundant code, which improves performance. Description: When comparing file1 to file2 and both files contain same soft-links and/or external-links, if file2's target object path name is longer than file1's target object path name, the current code allocates memory buffer incorrectly, so it could end up buffer overflow or wrong result. Tested on Jam. --- tools/lib/h5diff.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index 7d11f2f..18dd1ed 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -1024,7 +1024,7 @@ hsize_t diff(hid_t file1_id, if(H5Lget_info(file1_id, path1, &li1, H5P_DEFAULT) < 0) goto out; - if(H5Lget_info(file1_id, path1, &li2, H5P_DEFAULT) < 0) + if(H5Lget_info(file2_id, path2, &li2, H5P_DEFAULT) < 0) goto out; buf1 = HDmalloc(li1.u.val_size); @@ -1062,7 +1062,7 @@ hsize_t diff(hid_t file1_id, if(H5Lget_info(file1_id, path1, &li1, H5P_DEFAULT) < 0) goto out; - if(H5Lget_info(file1_id, path1, &li2, H5P_DEFAULT) < 0) + if(H5Lget_info(file2_id, path2, &li2, H5P_DEFAULT) < 0) goto out; /* Only external links will have a query function registered */ @@ -1085,16 +1085,6 @@ hsize_t diff(hid_t file1_id, /* If the buffers are the same size, compare them */ if(li1.u.val_size == li2.u.val_size) { - if(H5Lget_val(file1_id, path1, buf1, li1.u.val_size, H5P_DEFAULT) < 0) { - HDfree(buf1); - HDfree(buf2); - goto out; - } /* end if */ - if(H5Lget_val(file2_id, path2, buf2, li2.u.val_size, H5P_DEFAULT) < 0) { - HDfree(buf1); - HDfree(buf2); - goto out; - } /* end if */ ret = HDmemcmp(buf1, buf2, li1.u.val_size); } else -- cgit v0.12