diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-01-14 19:36:01 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-01-14 19:36:01 (GMT) |
commit | 23130b569c3846a1fd098841bb2f9912dd9040de (patch) | |
tree | 3d616062dd8da4e3042e28df4451212f8fe10b83 /src/H5E.c | |
parent | d00ec8d85a03808eaa04fb3971ae6bb2c8ce2f42 (diff) | |
download | hdf5-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/H5E.c')
-rw-r--r-- | src/H5E.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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) } |