summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2009-01-09 15:12:23 (GMT)
committerdgp <dgp@users.sourceforge.net>2009-01-09 15:12:23 (GMT)
commit7c046b459d010a331697abb8a76eecc8a81968c4 (patch)
treea900701f698bbc9c644e088bb73e0631e417acc7
parentb98ad0d6cb97c6c201972b177bc0578706aee6cd (diff)
downloadtcl-7c046b459d010a331697abb8a76eecc8a81968c4.zip
tcl-7c046b459d010a331697abb8a76eecc8a81968c4.tar.gz
tcl-7c046b459d010a331697abb8a76eecc8a81968c4.tar.bz2
* generic/tclStringObj.c (STRING_SIZE): Corrected failure to limit
memory allocation requests to the sizes that can be supported by Tcl's memory allocation routines. [Bug 2494093].
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclStringObj.c11
2 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index f9413c6..c6b9740 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-01-09 Don Porter <dgp@users.sourceforge.net>
+
+ * generic/tclStringObj.c (STRING_SIZE): Corrected failure to limit
+ memory allocation requests to the sizes that can be supported by
+ Tcl's memory allocation routines. [Bug 2494093].
+
2009-01-08 Don Porter <dgp@users.sourceforge.net>
* generic/tclStringObj.c (STRING_UALLOC): Added missing parens
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 9ab1abb..21c2e85 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.70.2.2 2009/01/08 17:55:41 dgp Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.70.2.3 2009/01/09 15:12:23 dgp Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -108,9 +108,12 @@ typedef struct String {
#define STRING_UALLOC(numChars) \
((numChars) * sizeof(Tcl_UniChar))
#define STRING_SIZE(ualloc) \
- ((unsigned) ((ualloc) \
- ? sizeof(String) - sizeof(Tcl_UniChar) + (ualloc) \
- : sizeof(String)))
+ ((unsigned) ((ualloc) \
+ ? ((sizeof(String) - sizeof(Tcl_UniChar) + (ualloc) > INT_MAX) \
+ ? Tcl_Panic("unable to alloc %u bytes", \
+ sizeof(String) - sizeof(Tcl_UniChar) + (ualloc)), INT_MAX \
+ : (sizeof(String) - sizeof(Tcl_UniChar) + (ualloc))) \
+ : sizeof(String)))
#define GET_STRING(objPtr) \
((String *) (objPtr)->internalRep.otherValuePtr)
#define SET_STRING(objPtr, stringPtr) \