summaryrefslogtreecommitdiffstats
path: root/generic/tclHash.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-11-07 21:32:04 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-11-07 21:32:04 (GMT)
commitfd61a8e89e832f6814d5deb7fe5a0c171e638167 (patch)
treef13077a145f46b924dfa7a1f9d771bced681be33 /generic/tclHash.c
parent4ab9cb54181038d61f85f76f76a7b23e7a7c59ca (diff)
downloadtcl-fd61a8e89e832f6814d5deb7fe5a0c171e638167.zip
tcl-fd61a8e89e832f6814d5deb7fe5a0c171e638167.tar.gz
tcl-fd61a8e89e832f6814d5deb7fe5a0c171e638167.tar.bz2
Attempted bug fix.
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r--generic/tclHash.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 256b073..b553c68 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -1013,12 +1013,18 @@ static void
RebuildTable(
register Tcl_HashTable *tablePtr) /* Table to enlarge. */
{
- int oldSize, count, index;
- Tcl_HashEntry **oldBuckets;
+ int count, index, oldSize = tablePtr->numBuckets;
+ Tcl_HashEntry **oldBuckets = tablePtr->buckets;
register Tcl_HashEntry **oldChainPtr, **newChainPtr;
register Tcl_HashEntry *hPtr;
const Tcl_HashKeyType *typePtr;
+ /* Avoid outgrowing capability of the memory allocators */
+ if (oldSize > UINT_MAX / (4 * sizeof(Tcl_HashEntry *))) {
+ tablePtr->rebuildSize = INT_MAX;
+ return;
+ }
+
if (tablePtr->keyType == TCL_STRING_KEYS) {
typePtr = &tclStringHashKeyType;
} else if (tablePtr->keyType == TCL_ONE_WORD_KEYS) {
@@ -1030,9 +1036,6 @@ RebuildTable(
typePtr = &tclArrayHashKeyType;
}
- oldSize = tablePtr->numBuckets;
- oldBuckets = tablePtr->buckets;
-
/*
* Allocate and initialize the new bucket array, and set up hashing
* constants for new array size.