summaryrefslogtreecommitdiffstats
path: root/generic/tclHash.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2002-02-26 02:09:56 (GMT)
committerhobbs <hobbs>2002-02-26 02:09:56 (GMT)
commit3fe14a87d3988f8477a4b6fb2e29d201872d070e (patch)
tree0f4374d22055c382a2e5ad45fa49d011f84feab0 /generic/tclHash.c
parent9a1be64616396b29d2c100d299456fb824c2010f (diff)
downloadtcl-3fe14a87d3988f8477a4b6fb2e29d201872d070e.zip
tcl-3fe14a87d3988f8477a4b6fb2e29d201872d070e.tar.gz
tcl-3fe14a87d3988f8477a4b6fb2e29d201872d070e.tar.bz2
* generic/tclHash.c (AllocArrayEntry, AllocStringEntry):
Before invoking ckalloc when creating a Tcl_HashEntry, check that the amount of memory being allocated is at least as large as sizeof(Tcl_HashEntry). The previous code was allocating memory regions that were one or two bytes short. [Bug #521950] (dejong)
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r--generic/tclHash.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 41593f6..e7bd472 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclHash.c,v 1.10 2002/01/25 21:36:09 dgp Exp $
+ * RCS: @(#) $Id: tclHash.c,v 1.11 2002/02/26 02:16:09 hobbs Exp $
*/
#include "tclInt.h"
@@ -814,11 +814,14 @@ AllocArrayEntry(tablePtr, keyPtr)
register int *iPtr1, *iPtr2;
Tcl_HashEntry *hPtr;
int count;
+ unsigned int size;
count = tablePtr->keyType;
- hPtr = (Tcl_HashEntry *) ckalloc((unsigned) (sizeof(Tcl_HashEntry)
- + (count*sizeof(int)) - sizeof(hPtr->key)));
+ size = sizeof(Tcl_HashEntry) + (count*sizeof(int)) - sizeof(hPtr->key);
+ if (size < sizeof(Tcl_HashEntry))
+ size = sizeof(Tcl_HashEntry);
+ hPtr = (Tcl_HashEntry *) ckalloc(size);
for (iPtr1 = array, iPtr2 = hPtr->key.words;
count > 0; count--, iPtr1++, iPtr2++) {
@@ -923,9 +926,12 @@ AllocStringEntry(tablePtr, keyPtr)
{
CONST char *string = (CONST char *) keyPtr;
Tcl_HashEntry *hPtr;
+ unsigned int size;
- hPtr = (Tcl_HashEntry *) ckalloc((unsigned)
- (sizeof(Tcl_HashEntry) + strlen(string) + 1 - sizeof(hPtr->key)));
+ size = sizeof(Tcl_HashEntry) + strlen(string) + 1 - sizeof(hPtr->key);
+ if (size < sizeof(Tcl_HashEntry))
+ size = sizeof(Tcl_HashEntry);
+ hPtr = (Tcl_HashEntry *) ckalloc(size);
strcpy(hPtr->key.string, string);
return hPtr;