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)
commit88acd72e58f591661319bbc034aaf33d2761ecfb (patch)
treec9af6aceb37225fda81cba776805a7d789461d3a /generic
parentd6aa0064e65e681ec2c51e78400bafa27d8a684c (diff)
parent20266f1569a02073d42b92dc82be9bb625932f25 (diff)
downloadtcl-88acd72e58f591661319bbc034aaf33d2761ecfb.zip
tcl-88acd72e58f591661319bbc034aaf33d2761ecfb.tar.gz
tcl-88acd72e58f591661319bbc034aaf33d2761ecfb.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);
}