diff options
author | nijtmans <nijtmans> | 2011-01-25 15:57:09 (GMT) |
---|---|---|
committer | nijtmans <nijtmans> | 2011-01-25 15:57:09 (GMT) |
commit | 043805d94684739088de3023be744c746efd35b0 (patch) | |
tree | da1d93d308e4f722c8fefef3b156c2bbba94d6da /generic/tclHash.c | |
parent | b297ff0dce26cde3cc43c0f929a44976936b601e (diff) | |
download | tcl-043805d94684739088de3023be744c746efd35b0.zip tcl-043805d94684739088de3023be744c746efd35b0.tar.gz tcl-043805d94684739088de3023be744c746efd35b0.tar.bz2 |
[Bug 3129448]: Possible over-allocation on 64-bit platforms, part 2,
backported strcpy->memcpy change but not change in any struct.
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r-- | generic/tclHash.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c index ae2eca8..9ae23e3 100644 --- a/generic/tclHash.c +++ b/generic/tclHash.c @@ -1,4 +1,4 @@ -/* +/* * tclHash.c -- * * Implementation of in-memory hash tables for Tcl and Tcl-based @@ -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.12.2.1 2004/11/11 01:18:07 das Exp $ + * RCS: @(#) $Id: tclHash.c,v 1.12.2.2 2011/01/25 15:57:09 nijtmans Exp $ */ #include "tclInt.h" @@ -191,11 +191,11 @@ Tcl_InitCustomHashTable(tablePtr, keyType, typePtr) Tcl_HashKeyType *typePtr; /* Pointer to structure which defines * the behaviour of this table. */ { -#if (TCL_SMALL_HASH_TABLE != 4) +#if (TCL_SMALL_HASH_TABLE != 4) panic("Tcl_InitCustomHashTable: TCL_SMALL_HASH_TABLE is %d, not 4\n", TCL_SMALL_HASH_TABLE); #endif - + tablePtr->buckets = tablePtr->staticBuckets; tablePtr->staticBuckets[0] = tablePtr->staticBuckets[1] = 0; tablePtr->staticBuckets[2] = tablePtr->staticBuckets[3] = 0; @@ -341,7 +341,7 @@ Tcl_FindHashEntry(tablePtr, key) } } } - + return NULL; } @@ -454,7 +454,7 @@ Tcl_CreateHashEntry(tablePtr, key, newPtr) hPtr = (Tcl_HashEntry *) ckalloc((unsigned) sizeof(Tcl_HashEntry)); hPtr->key.oneWordValue = (char *) key; } - + hPtr->tablePtr = tablePtr; #if TCL_HASH_KEY_STORE_HASH # if TCL_PRESERVE_BINARY_COMPATABILITY @@ -530,7 +530,7 @@ Tcl_DeleteHashEntry(entryPtr) #else typePtr = tablePtr->typePtr; #endif - + #if TCL_HASH_KEY_STORE_HASH if (typePtr->hashKeyProc == NULL || typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) { @@ -543,7 +543,7 @@ Tcl_DeleteHashEntry(entryPtr) #else bucketPtr = entryPtr->bucketPtr; #endif - + if (*bucketPtr == entryPtr) { *bucketPtr = entryPtr->nextPtr; } else { @@ -820,12 +820,12 @@ AllocArrayEntry(tablePtr, keyPtr) unsigned int size; count = tablePtr->keyType; - + 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++) { *iPtr2 = *iPtr1; @@ -929,14 +929,14 @@ AllocStringEntry(tablePtr, keyPtr) { CONST char *string = (CONST char *) keyPtr; Tcl_HashEntry *hPtr; - unsigned int size; - - 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); + unsigned int size, allocsize; + allocsize = size = strlen(string) + 1; + if (size < sizeof(hPtr->key)) { + allocsize = sizeof(hPtr->key); + } + hPtr = (Tcl_HashEntry *) ckalloc(sizeof(Tcl_HashEntry) + allocsize - sizeof(hPtr->key)); + memcpy(hPtr->key.string, string, size); return hPtr; } |