summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-11-08 02:23:46 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-11-08 02:23:46 (GMT)
commitf74bde3e62a0e7b36227e064d0463424b5d9bbab (patch)
tree37d0f620b744586a7b4d95eacf6eae1ea85deaf2 /generic
parent98c6b22c1002fae94f8abf7422758530a9a6fdeb (diff)
parentbe0c5786a08e4843d792d5321e8245e551126317 (diff)
downloadtcl-f74bde3e62a0e7b36227e064d0463424b5d9bbab.zip
tcl-f74bde3e62a0e7b36227e064d0463424b5d9bbab.tar.gz
tcl-f74bde3e62a0e7b36227e064d0463424b5d9bbab.tar.bz2
[3298012] Stop RebuildTable asking ckalloc for more than it can give.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclHash.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 1991aea..4fdd673 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -1014,12 +1014,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) {
@@ -1031,9 +1037,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.