summaryrefslogtreecommitdiffstats
path: root/generic/tclInt.h
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2009-09-29 05:03:46 (GMT)
committerdgp <dgp@users.sourceforge.net>2009-09-29 05:03:46 (GMT)
commit1d9466df83ad7999d5e606e39121eb3dd68b737f (patch)
treedb950a0e96ba25eff12acf38eb8a9aa06ee10edb /generic/tclInt.h
parent9ed15c4edf59c0dda55797c0debad69464c092c0 (diff)
downloadtcl-1d9466df83ad7999d5e606e39121eb3dd68b737f.zip
tcl-1d9466df83ad7999d5e606e39121eb3dd68b737f.tar.gz
tcl-1d9466df83ad7999d5e606e39121eb3dd68b737f.tar.bz2
* generic/tclAlloc.c: Cleaned up various routines in the
* generic/tclCkalloc.c: call stacks for memory allocation to * generic/tclInt.h: guarantee that any size values computed * generic/tclThreadAlloc.c: are within the domains of the routines they get passed to. [Bugs 2557696 and 2557796].
Diffstat (limited to 'generic/tclInt.h')
-rw-r--r--generic/tclInt.h17
1 files changed, 14 insertions, 3 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index d34be28..1d1851e 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -15,7 +15,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclInt.h,v 1.443 2009/09/24 17:19:18 dgp Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.444 2009/09/29 05:03:46 dgp Exp $
*/
#ifndef _TCLINT
@@ -3875,10 +3875,15 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
*----------------------------------------------------------------
*/
+#define TCL_MAX_TOKENS (int)(UINT_MAX / sizeof(Tcl_Token))
#define TCL_MIN_TOKEN_GROWTH 50
#define TclGrowTokenArray(tokenPtr, used, available, append, staticPtr) \
{ \
int needed = (used) + (append); \
+ if (needed > TCL_MAX_TOKENS) { \
+ Tcl_Panic("max # of tokens for a Tcl parse (%d) exceeded", \
+ TCL_MAX_TOKENS); \
+ } \
if (needed > (available)) { \
int allocated = 2 * needed; \
Tcl_Token *oldPtr = (tokenPtr); \
@@ -3886,12 +3891,18 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
if (oldPtr == (staticPtr)) { \
oldPtr = NULL; \
} \
+ if (allocated > TCL_MAX_TOKENS) { \
+ allocated = TCL_MAX_TOKENS; \
+ } \
newPtr = (Tcl_Token *) attemptckrealloc((char *) oldPtr, \
- (unsigned) (allocated * sizeof(Tcl_Token))); \
+ (unsigned int) (allocated * sizeof(Tcl_Token))); \
if (newPtr == NULL) { \
allocated = needed + (append) + TCL_MIN_TOKEN_GROWTH; \
+ if (allocated > TCL_MAX_TOKENS) { \
+ allocated = TCL_MAX_TOKENS; \
+ } \
newPtr = (Tcl_Token *) ckrealloc((char *) oldPtr, \
- (unsigned) (allocated * sizeof(Tcl_Token))); \
+ (unsigned int) (allocated * sizeof(Tcl_Token))); \
} \
(available) = allocated; \
if (oldPtr == NULL) { \