diff options
author | Albert Cheng <acheng@hdfgroup.org> | 2008-12-09 04:10:58 (GMT) |
---|---|---|
committer | Albert Cheng <acheng@hdfgroup.org> | 2008-12-09 04:10:58 (GMT) |
commit | 4d476fd050395defbc0abe6d25c8faa3767c65c3 (patch) | |
tree | db4f0cda91df32643541e0f70e403c8e97180193 | |
parent | 0d8e7cafc7f155f64a76fd12ff6389c4f8f89f84 (diff) | |
download | hdf5-4d476fd050395defbc0abe6d25c8faa3767c65c3.zip hdf5-4d476fd050395defbc0abe6d25c8faa3767c65c3.tar.gz hdf5-4d476fd050395defbc0abe6d25c8faa3767c65c3.tar.bz2 |
[svn-r16171] Code clean up.
Function get_unique_name() had potential string overflow problem.
Fixed. Also removed some unused macros.
Tested by h5committest.
-rw-r--r-- | perform/zip_perf.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/perform/zip_perf.c b/perform/zip_perf.c index 9eab2ee..d1d36b4 100644 --- a/perform/zip_perf.c +++ b/perform/zip_perf.c @@ -29,7 +29,6 @@ #include <fcntl.h> #include <math.h> #include <sys/time.h> -#include <sys/uio.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> @@ -43,13 +42,13 @@ #include <zlib.h> -#if defined(MSDOS) || defined(OS2) || defined(WIN32) +#if defined(MSDOS) || defined(OS2) || defined(_WIN32) # include <fcntl.h> # include <io.h> # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) #else # define SET_BINARY_MODE(file) /* nothing */ -#endif /* MSDOS || OS2 || WIN32 */ +#endif /* MSDOS || OS2 || _WIN32 */ #ifdef VMS # define unlink delete @@ -70,8 +69,6 @@ # define GZ_SUFFIX ".gz" #endif /* GZ_SUFFIX */ -#define SUFFIX_LEN (sizeof(GZ_SUFFIX) - 1) - #define ONE_KB 1024 #define ONE_MB (ONE_KB * ONE_KB) #define ONE_GB (ONE_MB * ONE_KB) @@ -89,8 +86,6 @@ #define FALSE (!TRUE) #endif /* FALSE */ -#define BUFLEN (16 * ONE_KB) -#define MAX_NAME_LEN ONE_KB /* internal variables */ static const char *prog; @@ -322,7 +317,7 @@ uncompress_buffer(Bytef *dest, uLongf *destLen, const Bytef *source, static void get_unique_name(void) { - const char *prefix = "/tmp", *tmpl = "/zip_perf.data"; + const char *prefix = NULL, *tmpl = "zip_perf.data"; const char *env = getenv("HDF5_PREFIX"); if (env) @@ -331,12 +326,19 @@ get_unique_name(void) if (option_prefix) prefix = option_prefix; - filename = calloc(1, strlen(prefix) + strlen(tmpl) + 1); + if (prefix) + /* 2 = 1 for '/' + 1 for null terminator */ + filename = (char *) HDmalloc(strlen(prefix) + strlen(tmpl) + 2); + else + filename = (char *) HDmalloc(strlen(tmpl) + 1); if (!filename) error("out of memory"); - strcpy(filename, prefix); + if (prefix){ + strcpy(filename, prefix); + strcat(filename, "/"); + } strcat(filename, tmpl); } |