diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-07-05 07:45:35 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-07-05 07:45:35 (GMT) |
commit | 65ec1ae3b83f27031adbc962765efdd11bdddeb2 (patch) | |
tree | e61b3573db69fff6a5a904c3ef7cdd7d59706ebc /generic/tclIndexObj.c | |
parent | b3b04348558215a3acd092d58664c31a255781bf (diff) | |
download | tcl-65ec1ae3b83f27031adbc962765efdd11bdddeb2.zip tcl-65ec1ae3b83f27031adbc962765efdd11bdddeb2.tar.gz tcl-65ec1ae3b83f27031adbc962765efdd11bdddeb2.tar.bz2 |
protect Tcl_GetIndexFromObjStruct from empty strings in table
Diffstat (limited to 'generic/tclIndexObj.c')
-rw-r--r-- | generic/tclIndexObj.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index 79fc262..1076e32 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -207,6 +207,10 @@ Tcl_GetIndexFromObjStruct(interp, objPtr, tablePtr, offset, msg, flags, entryPtr = NEXT_ENTRY(entryPtr, offset), i++) { for (p1 = key, p2 = *entryPtr; *p1 == *p2; p1++, p2++) { if (*p1 == '\0') { + if (p1 == key) { + /* empty keys never match */ + continue; + } index = i; goto done; } @@ -260,24 +264,29 @@ Tcl_GetIndexFromObjStruct(interp, objPtr, tablePtr, offset, msg, flags, /* * Produce a fancy error message. */ - int count; + int count = 0; TclNewObj(resultPtr); Tcl_SetObjResult(interp, resultPtr); + entryPtr = tablePtr; + while ((*entryPtr != NULL) && !**entryPtr) { + entryPtr = NEXT_ENTRY(entryPtr, offset); + } Tcl_AppendStringsToObj(resultPtr, (numAbbrev > 1) && !(flags & TCL_EXACT) ? "ambiguous " : "bad ", msg, " \"", - key, "\": must be ", STRING_AT(tablePtr,offset,0), (char*)NULL); - for (entryPtr = NEXT_ENTRY(tablePtr, offset), count = 0; - *entryPtr != NULL; - entryPtr = NEXT_ENTRY(entryPtr, offset), count++) { + key, "\": must be ", *entryPtr, (char*)NULL); + entryPtr = NEXT_ENTRY(entryPtr, offset); + while (*entryPtr != NULL) { if (*NEXT_ENTRY(entryPtr, offset) == NULL) { Tcl_AppendStringsToObj(resultPtr, (count > 0) ? ", or " : " or ", *entryPtr, (char *) NULL); - } else { + } else if (**entryPtr) { Tcl_AppendStringsToObj(resultPtr, ", ", *entryPtr, (char *) NULL); + count++; } + entryPtr = NEXT_ENTRY(entryPtr, offset); } } return TCL_ERROR; |