diff options
author | dgp <dgp@noemail.net> | 2009-09-28 21:20:50 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2009-09-28 21:20:50 (GMT) |
commit | aabcfee0dc094c0fe6a749244e20d8d8cb3a9118 (patch) | |
tree | 4bbcc35d2c98ef432ee08599ec2bd541b906a6ba /generic/tclCkalloc.c | |
parent | 4f5e719af672b8f11cac1210e90d0e9707909c5b (diff) | |
download | tcl-aabcfee0dc094c0fe6a749244e20d8d8cb3a9118.zip tcl-aabcfee0dc094c0fe6a749244e20d8d8cb3a9118.tar.gz tcl-aabcfee0dc094c0fe6a749244e20d8d8cb3a9118.tar.bz2 |
* generic/tclAlloc.c: Cleaned up various routines in the
* generic/tclCkalloc.c: call stacks for memory allocation to
* generic/tclParse.c: guarantee that any size values computed
* generic/tclThreadAlloc.c: are within the domains of the routines
they get passed to. [Bugs 2557696 and 2557796].
FossilOrigin-Name: b61f883a5364c3b2e5c347f6f08d8694fd5c3563
Diffstat (limited to 'generic/tclCkalloc.c')
-rw-r--r-- | generic/tclCkalloc.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/generic/tclCkalloc.c b/generic/tclCkalloc.c index 98e8c5b..ab51f85 100644 --- a/generic/tclCkalloc.c +++ b/generic/tclCkalloc.c @@ -13,7 +13,7 @@ * * This code contributed by Karl Lehenbauer and Mark Diekhans * - * RCS: @(#) $Id: tclCkalloc.c,v 1.19 2003/01/19 07:21:18 hobbs Exp $ + * RCS: @(#) $Id: tclCkalloc.c,v 1.19.2.1 2009/09/28 21:20:51 dgp Exp $ */ #include "tclInt.h" @@ -368,13 +368,17 @@ Tcl_DbCkalloc(size, file, line) CONST char *file; int line; { - struct mem_header *result; + struct mem_header *result = NULL; if (validate_memory) Tcl_ValidateAllMemory (file, line); - result = (struct mem_header *) TclpAlloc((unsigned)size + - sizeof(struct mem_header) + HIGH_GUARD_SIZE); + + /* Don't let size argument to TclpAlloc overflow */ + if (size <= UINT_MAX - HIGH_GUARD_SIZE - sizeof(struct mem_header)) { + result = (struct mem_header *) TclpAlloc((unsigned)size + + sizeof(struct mem_header) + HIGH_GUARD_SIZE); + } if (result == NULL) { fflush(stdout); TclDumpMemoryInfo(stderr); @@ -453,13 +457,16 @@ Tcl_AttemptDbCkalloc(size, file, line) CONST char *file; int line; { - struct mem_header *result; + struct mem_header *result = NULL; if (validate_memory) Tcl_ValidateAllMemory (file, line); - result = (struct mem_header *) TclpAlloc((unsigned)size + - sizeof(struct mem_header) + HIGH_GUARD_SIZE); + /* Don't let size argument to TclpAlloc overflow */ + if (size <= UINT_MAX - HIGH_GUARD_SIZE - sizeof(struct mem_header)) { + result = (struct mem_header *) TclpAlloc((unsigned)size + + sizeof(struct mem_header) + HIGH_GUARD_SIZE); + } if (result == NULL) { fflush(stdout); TclDumpMemoryInfo(stderr); |