summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-05 07:55:19 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-05 07:55:19 (GMT)
commitb4acd4935320a64a571f6496290d44d1fafce047 (patch)
treec9af6aceb37225fda81cba776805a7d789461d3a /generic
parent3113ab14988ed48917f5c96cb00bfd3366af54a7 (diff)
parent65ec1ae3b83f27031adbc962765efdd11bdddeb2 (diff)
downloadtcl-b4acd4935320a64a571f6496290d44d1fafce047.zip
tcl-b4acd4935320a64a571f6496290d44d1fafce047.tar.gz
tcl-b4acd4935320a64a571f6496290d44d1fafce047.tar.bz2
protect Tcl_GetIndexFromObjStruct from empty strings in table
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIndexObj.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c
index 7991533..2d87205 100644
--- a/generic/tclIndexObj.c
+++ b/generic/tclIndexObj.c
@@ -202,6 +202,10 @@ Tcl_GetIndexFromObjStruct(
entryPtr = NEXT_ENTRY(entryPtr, offset), idx++) {
for (p1 = key, p2 = *entryPtr; *p1 == *p2; p1++, p2++) {
if (*p1 == '\0') {
+ if (p1 == key) {
+ /* empty keys never match */
+ continue;
+ }
index = idx;
goto done;
}
@@ -256,22 +260,27 @@ Tcl_GetIndexFromObjStruct(
* 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), NULL);
- for (entryPtr = NEXT_ENTRY(tablePtr, offset), count = 0;
- *entryPtr != NULL;
- entryPtr = NEXT_ENTRY(entryPtr, offset), count++) {
+ "\": must be ", *entryPtr, NULL);
+ entryPtr = NEXT_ENTRY(entryPtr, offset);
+ while (*entryPtr != NULL) {
if (*NEXT_ENTRY(entryPtr, offset) == NULL) {
Tcl_AppendStringsToObj(resultPtr, ((count > 0) ? "," : ""),
" or ", *entryPtr, NULL);
- } else {
+ } else if (**entryPtr) {
Tcl_AppendStringsToObj(resultPtr, ", ", *entryPtr, NULL);
+ count++;
}
+ entryPtr = NEXT_ENTRY(entryPtr, offset);
}
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", msg, key, NULL);
}