summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-01-14 19:36:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-01-14 19:36:01 (GMT)
commit23130b569c3846a1fd098841bb2f9912dd9040de (patch)
tree3d616062dd8da4e3042e28df4451212f8fe10b83 /src
parentd00ec8d85a03808eaa04fb3971ae6bb2c8ce2f42 (diff)
downloadhdf5-23130b569c3846a1fd098841bb2f9912dd9040de.zip
hdf5-23130b569c3846a1fd098841bb2f9912dd9040de.tar.gz
hdf5-23130b569c3846a1fd098841bb2f9912dd9040de.tar.bz2
[svn-r9825] Purpose:
Bug fix Description: Fix possible overrun in error description string by allocating large enough string on the fly. Platforms tested: FreeBSD 4.10 (sleipnir) Too minor to require h5committest
Diffstat (limited to 'src')
-rw-r--r--src/H5E.c22
-rw-r--r--src/H5Epublic.h5
2 files changed, 21 insertions, 6 deletions
diff --git a/src/H5E.c b/src/H5E.c
index eafa2a4..c178e77 100644
--- a/src/H5E.c
+++ b/src/H5E.c
@@ -1485,7 +1485,9 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line
va_list ap; /* Varargs info */
H5E_t *estack; /* Pointer to error stack to modify */
H5E_msg_t *maj_ptr, *min_ptr; /* Pointer to major and minor error info */
- char tmp[H5E_LEN]; /* Buffer to place formatted description in */
+ int tmp_len; /* Current size of description buffer */
+ int desc_len; /* Actual length of description when formatted */
+ char *tmp=NULL; /* Buffer to place formatted description in */
herr_t ret_value=SUCCEED; /* Return value */
/* Don't clear the error stack! :-) */
@@ -1513,7 +1515,20 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line
/* Format the description */
va_start(ap, fmt);
- HDvsnprintf(tmp, H5E_LEN, fmt, ap);
+
+ /* Allocate space for the formatted description buffer */
+ tmp_len=128;
+ if((tmp=H5MM_malloc((size_t)tmp_len))==NULL)
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+
+ /* If the description doesn't fit into the initial buffer size, allocate more space and try again */
+ while((desc_len=HDvsnprintf(tmp, (size_t)tmp_len, fmt, ap))>tmp_len) {
+ H5MM_xfree(tmp);
+ tmp_len = desc_len+1;
+ if((tmp=H5MM_malloc((size_t)tmp_len))==NULL)
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
+ } /* end while */
+
va_end(ap);
/* Push the error on the stack */
@@ -1521,6 +1536,9 @@ H5Epush_stack(hid_t err_stack, const char *file, const char *func, unsigned line
HGOTO_ERROR(H5E_ERROR, H5E_CANTSET, FAIL, "can't push error on stack")
done:
+ if(tmp)
+ H5MM_xfree(tmp);
+
FUNC_LEAVE_API(ret_value)
}
diff --git a/src/H5Epublic.h b/src/H5Epublic.h
index 461bc08..1671967 100644
--- a/src/H5Epublic.h
+++ b/src/H5Epublic.h
@@ -27,10 +27,7 @@
/* Value for the default error stack */
#define H5E_DEFAULT 0
-/* Limit of error strings recorded */
-#define H5E_LEN 128
-
-/* Take out _new later */
+/* Different kinds of error information */
typedef enum H5E_type_t {
H5E_MAJOR,
H5E_MINOR