summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2007-03-28 18:47:15 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2007-03-28 18:47:15 (GMT)
commit0975f08d7ee0366fd0c648a04f32380aa8cd1938 (patch)
tree02098155d848c6e733df33ff7d0bcdac8abafdaa
parentb9173f64d7b8ecc84dfc4728649adcfee24eb633 (diff)
downloadhdf5-0975f08d7ee0366fd0c648a04f32380aa8cd1938.zip
hdf5-0975f08d7ee0366fd0c648a04f32380aa8cd1938.tar.gz
hdf5-0975f08d7ee0366fd0c648a04f32380aa8cd1938.tar.bz2
[svn-r13560]
bug fix a malloc call with an incorrect length caused several memory problems that ultimately corrupted a name passed in a list of arguments in the h52gif tool allocated memory was not freed tested linux
-rw-r--r--hl/tools/gif2h5/h52gifgentst.c4
-rw-r--r--hl/tools/gif2h5/h52giftest.sh7
-rw-r--r--hl/tools/gif2h5/hdf2gif.c29
3 files changed, 22 insertions, 18 deletions
diff --git a/hl/tools/gif2h5/h52gifgentst.c b/hl/tools/gif2h5/h52gifgentst.c
index 717f9aa..e8c49ba 100644
--- a/hl/tools/gif2h5/h52gifgentst.c
+++ b/hl/tools/gif2h5/h52gifgentst.c
@@ -16,7 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "hdf5.h"
-#include "H5IM.h"
+#include "H5IMpublic.h"
@@ -36,7 +36,7 @@
#define WIDTH (hsize_t)400
#define HEIGHT (hsize_t)200
#define PAL_ENTRIES 256
-#define IMAGE1_NAME "1234567"
+#define IMAGE1_NAME "12345678"
#define PAL_NAME "palette"
/*-------------------------------------------------------------------------
diff --git a/hl/tools/gif2h5/h52giftest.sh b/hl/tools/gif2h5/h52giftest.sh
index b07ec90..fa439aa 100644
--- a/hl/tools/gif2h5/h52giftest.sh
+++ b/hl/tools/gif2h5/h52giftest.sh
@@ -15,6 +15,8 @@
#
# HDF Utilities Test script
+TESTFILE="$srcdir/../testfiles/h52giftst.h5"
+
# initialize errors variable
errors=0
@@ -28,7 +30,6 @@ TOOLTEST()
err=0
$RUNSERIAL ./h52gif $*
-
if [ $err -eq 1 ]; then
errors="` expr $errors + 1 `";
echo "*FAILED*"
@@ -39,8 +40,8 @@ fi
-TESTING "h52giftst.h5 image1.gif -i 1234567 -p palette" ;
-TOOLTEST h52giftst.h5 image1.gif -i 1234567 -p palette
+TESTING "h52giftst.h5 image1.gif -i 12345678 -p palette" ;
+TOOLTEST $TESTFILE image1.gif -i 12345678 -p palette
exit $errors
diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c
index 9a15c91..8f06bd2 100644
--- a/hl/tools/gif2h5/hdf2gif.c
+++ b/hl/tools/gif2h5/hdf2gif.c
@@ -114,8 +114,8 @@ int main(int argc , char **argv)
return 0;
}
- memset(image_name_arr , 0 , (size_t)MAX_NUMBER_IMAGES);
- memset(pal_name_arr , 0 , (size_t)MAX_NUMBER_IMAGES);
+ memset(image_name_arr , 0 , MAX_NUMBER_IMAGES);
+ memset(pal_name_arr , 0 , MAX_NUMBER_IMAGES);
HDFName = (CHAR *)malloc (strlen(argv[1]) + 1);
GIFName = (CHAR *)malloc (strlen(argv[2]) + 1);
@@ -149,7 +149,8 @@ int main(int argc , char **argv)
if (bool_is_image) {
/* this is an image */
/* allocate space to store the image name */
- image_name_arr[number_of_images] = (CHAR*) malloc(strlen(argv[arg_index] + 1));
+ size_t len = strlen(argv[arg_index]);
+ image_name_arr[number_of_images] = (CHAR*) malloc( len + 1);
strcpy(image_name_arr[number_of_images] , argv[arg_index]);
/* make the palette array for this NULL */
@@ -163,7 +164,8 @@ int main(int argc , char **argv)
/* this is a palette */
/* allocate space to store the pal name */
/* the palette was probably allocated for a previous image */
- pal_name_arr[number_of_images-1] = (CHAR*) malloc(strlen(argv[arg_index] + 1));
+ size_t len = strlen(argv[arg_index]);
+ pal_name_arr[number_of_images-1] = (CHAR*) malloc( len + 1);
strcpy(pal_name_arr[number_of_images - 1], argv[arg_index]);
bool_is_palette = 0;
continue;
@@ -172,12 +174,10 @@ int main(int argc , char **argv)
/* oops. This was not meant to happen */
usage();
-#if 0
while (number_of_images--) {
cleanup(image_name_arr[number_of_images]);
cleanup(pal_name_arr[number_of_images]);
}
-#endif /* 0 */
return -1;
}
@@ -216,8 +216,8 @@ int main(int argc , char **argv)
return -1;
}
- assert(dim_sizes[0]==(hsize_t)((int)dim_sizes[0]));
- assert(dim_sizes[1]==(hsize_t)((int)dim_sizes[1]));
+ assert(dim_sizes[0]==(hsize_t)((int)dim_sizes[0]));
+ assert(dim_sizes[1]==(hsize_t)((int)dim_sizes[1]));
RWidth = (int)dim_sizes[1];
RHeight = (int)dim_sizes[0];
#ifdef UNUSED
@@ -311,9 +311,9 @@ int main(int argc , char **argv)
if (idx == 0) {
/* Write out the GIF header and logical screen descriptor */
if (n_images > 1) {
- fwrite("GIF89a", sizeof( char ), (size_t)6, fpGif); /* the GIF magic number */
+ fwrite("GIF89a", sizeof( char ), 6, fpGif); /* the GIF magic number */
} else {
- fwrite("GIF87a", sizeof( char ), (size_t)6, fpGif); /* the GIF magic number */
+ fwrite("GIF87a", sizeof( char ), 6, fpGif); /* the GIF magic number */
}
putword(RWidth, fpGif); /* screen descriptor */
@@ -335,7 +335,7 @@ int main(int argc , char **argv)
fputc(0x21 , fpGif);
fputc(0xFF , fpGif);
fputc(11 , fpGif);
- fwrite("NETSCAPE2.0" , (size_t)1 , (size_t)11 , fpGif);
+ fwrite("NETSCAPE2.0" , 1 , 11 , fpGif);
fputc(3 , fpGif);
fputc(1 , fpGif);
fputc(0 , fpGif);
@@ -392,14 +392,17 @@ int main(int argc , char **argv)
fclose(fpGif);
-#if 0
+ if (HDFName != NULL)
+ free(HDFName);
+ if (GIFName != NULL)
+ free(GIFName);
+
while(number_of_images--) {
if (image_name_arr[number_of_images])
free(image_name_arr[number_of_images]);
if (pal_name_arr[number_of_images])
free(pal_name_arr[number_of_images]);
}
-#endif /* 0 */
return 0;
}