summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-05 08:17:28 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-05 08:17:28 (GMT)
commit36245ad98788adfc0a8906fdd9c61ac0b82990b4 (patch)
tree9091a83722c4d8a04394f9581c455801cb073041 /generic
parent8e7b0459fe6011676a85f83cddada3b34aa4e8e9 (diff)
parentb4acd4935320a64a571f6496290d44d1fafce047 (diff)
downloadtcl-36245ad98788adfc0a8906fdd9c61ac0b82990b4.zip
tcl-36245ad98788adfc0a8906fdd9c61ac0b82990b4.tar.gz
tcl-36245ad98788adfc0a8906fdd9c61ac0b82990b4.tar.bz2
protect Tcl_GetIndexFromObjStruct from empty strings in table
Diffstat (limited to 'generic')
-rw-r--r--generic/tclIndexObj.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c
index b206b35..85e0730 100644
--- a/generic/tclIndexObj.c
+++ b/generic/tclIndexObj.c
@@ -302,6 +302,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;
}
@@ -356,26 +360,31 @@ Tcl_GetIndexFromObjStruct(
* Produce a fancy error message.
*/
- int count;
+ int count = 0;
TclNewObj(resultPtr);
+ entryPtr = tablePtr;
+ while ((*entryPtr != NULL) && !**entryPtr) {
+ entryPtr = NEXT_ENTRY(entryPtr, offset);
+ }
Tcl_AppendStringsToObj(resultPtr,
(numAbbrev>1 && !(flags & TCL_EXACT) ? "ambiguous " : "bad "),
msg, " \"", key, NULL);
- if (STRING_AT(tablePtr, offset, 0) == NULL) {
+ if (*entryPtr == NULL) {
Tcl_AppendStringsToObj(resultPtr, "\": no valid options", NULL);
} else {
Tcl_AppendStringsToObj(resultPtr, "\": must be ",
- STRING_AT(tablePtr, offset, 0), NULL);
- for (entryPtr = NEXT_ENTRY(tablePtr, offset), count = 0;
- *entryPtr != NULL;
- entryPtr = NEXT_ENTRY(entryPtr, offset), count++) {
+ *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_SetObjResult(interp, resultPtr);