Skip to content

Commit

Permalink
Make it impossible for the indexType object to cache negative index v…
Browse files Browse the repository at this point in the history
…alues. And - if it happens - at least don't crash on it.
jan.nijtmans committed Dec 18, 2021
1 parent a128b4d commit f60e164
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions generic/tclIndexObj.c
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ typedef struct {
#define NEXT_ENTRY(table, offset) \
(&(STRING_AT(table, offset)))
#define EXPAND_OF(indexRep) \
STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index)
(((indexRep)->index >= 0) ? STRING_AT((indexRep)->tablePtr, (indexRep)->offset*(indexRep)->index) : "")

/*
*----------------------------------------------------------------------
@@ -280,7 +280,9 @@ Tcl_GetIndexFromObjStruct(

if (objPtr && (objPtr->typePtr == &indexType)) {
indexRep = objPtr->internalRep.twoPtrValue.ptr1;
if (indexRep->tablePtr==tablePtr && indexRep->offset==offset) {
if ((indexRep->tablePtr == tablePtr)
&& (indexRep->offset == offset)
&& (indexRep->index >= 0)) {
*indexPtr = indexRep->index;
return TCL_OK;
}
@@ -339,7 +341,7 @@ Tcl_GetIndexFromObjStruct(
* operation.
*/

if (objPtr) {
if (objPtr && (index >= 0)) {
if (objPtr->typePtr == &indexType) {
indexRep = objPtr->internalRep.twoPtrValue.ptr1;
} else {

0 comments on commit f60e164

Please sign in to comment.