summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2005-08-17 18:40:41 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2005-08-17 18:40:41 (GMT)
commit918c992dea6a975193f2f3fa1ced9f1f907c4aff (patch)
tree07e64c083d1c735018cc27c4cea36b0e11959dde
parente5022d40a8a0ff1e8a5f9304330020abe32eab3d (diff)
downloadhdf5-918c992dea6a975193f2f3fa1ced9f1f907c4aff.zip
hdf5-918c992dea6a975193f2f3fa1ced9f1f907c4aff.tar.gz
hdf5-918c992dea6a975193f2f3fa1ced9f1f907c4aff.tar.bz2
[svn-r11258] Purpose:
Bug fix. Description: Reactivated the code for snprintf and vsnprintf for Tflops but added the SN_SIZ_MIN as an attempt to require the minimum amount of space needed, hoping vsnprintf/snprintf do not print larger than it per request. Also added code to detect overflow and return error (IF overflow has not crashed the application yet.) These are all short term patches. Platforms tested: Tested at Tflops.
-rw-r--r--src/H5.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/H5.c b/src/H5.c
index f719877..cd4d2a2 100644
--- a/src/H5.c
+++ b/src/H5.c
@@ -731,9 +731,13 @@ H5close(void)
/* disable the code of HDsnprintf and HDvsnprintf below to see if they
- * still needed by how what platforms. AKC 2005/8/11.
+ * are still needed by what platforms. AKC 2005/8/11.
+ * Turn it on for the Tflops (__PUMAGON__) machine. AKC 2005/8/12.
+ * The SN_SIZ_MIN is an attempt to require the minimum amount of space needed,
+ * hoping vsnprintf/snprintf do not print larger than it per request.
*/
-#if 0
+#ifdef __PUMAGON__
+#define H5_SN_SIZE_MIN 256
#ifndef H5_HAVE_SNPRINTF
/*-------------------------------------------------------------------------
* Function: HDsnprintf
@@ -770,9 +774,15 @@ HDsnprintf(char *buf, size_t UNUSED size, const char *fmt, ...)
int n;
va_list ap;
+ if (size < H5_SN_SIZE_MIN) /* Not safe to call vsprintf */
+ return -1;
va_start(ap, fmt);
n = HDvsprintf(buf, fmt, ap);
va_end(ap);
+ if (n >= size){
+ /* buffer overflow has occurred. Attempt to report an error. */
+ return -1;
+ }
return n;
}
#endif /* H5_HAVE_SNPRINTF */
@@ -807,10 +817,18 @@ HDsnprintf(char *buf, size_t UNUSED size, const char *fmt, ...)
int
HDvsnprintf(char *buf, size_t UNUSED size, const char *fmt, va_list ap)
{
- return HDvsprintf(buf, fmt, ap);
+ int n;
+ if (size < H5_SN_SIZE_MIN) /* Not safe to call vsprintf */
+ return -1;
+ n = HDvsprintf(buf, fmt, ap);
+ if (n >= size){
+ /* buffer overflow has occurred. Attempt to report an error. */
+ return -1;
+ }
+ return n;
}
#endif /* H5_HAVE_VSNPRINTF */
-#endif /* 0 */
+#endif /* __PUMAGON__ */
/*-------------------------------------------------------------------------