| Description: |
OriginalBugID: 5980 Bug
Version: 8.4a1
SubmitDate: '2000-07-06'
LastModified: '2000-09-26'
Severity: MED
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
OS: Linux-Red Hat
ClosedDate: '2000-09-26'
Name:
Mo DeJong
CVS:
Mon Jul 3
Comments:
I also bumped up the FIXED_SIZE, used it in both places and
undefined it when done. This one should be a no-brainer.
ReproducibleScript:
toplevel .t
button .t.
DesiredBehavior:
The button window name is not valid, Tk should report an error.
Patch:
Index: generic/tkWindow.c
===================================================================
RCS file: /cvsroot/tk/generic/tkWindow.c,v
retrieving revision 1.18
diff -u -r1.18 tkWindow.c
--- tkWindow.c2000/05/29 01:43:141.18
+++ tkWindow.c2000/07/03 13:58:19
@@ -747,6 +747,7 @@
Tcl_SetHashValue(hPtr, winPtr);
winPtr->pathName = Tcl_GetHashKey(&parentPtr->mainPtr->nameTable, hPtr);
return TCL_OK;
+#undef FIXED_SIZE
}
/*
@@ -1004,8 +1005,8 @@
* new window; window will be a top-level
* window. */
{
-#define FIXED_SPACE 5
- char fixedSpace[FIXED_SPACE+1];
+#define FIXED_SIZE 200
+ char fixedSpace[FIXED_SIZE+1];
char *p;
Tk_Window parent;
int numChars;
@@ -1016,17 +1017,19 @@
* copy the parent's name somewhere else to avoid modifying
* the pathName string (for large names, space for the copy
* will have to be malloc'ed); (b) must special-case the
- * situation where the parent is ".".
+ * situation where the parent is "."; (c) Watch out for the
+ * other spacial case where the child window is named ".",
+ * this can happen if a button is named ".t." for instance.
*/
p = strrchr(pathName, '.');
- if (p == NULL) {
+ if (p == NULL || ((p[0] == '.' && p[1] == '\0') && (p != pathName))) {
Tcl_AppendResult(interp, "bad window path name \"", pathName,
"\"", (char *) NULL);
return NULL;
}
numChars = p-pathName;
- if (numChars > FIXED_SPACE) {
+ if (numChars > FIXED_SIZE) {
p = (char *) ckalloc((unsigned) (numChars+1));
} else {
p = fixedSpace;
@@ -1082,6 +1085,7 @@
return CreateTopLevelWindow(interp, parent, pathName+numChars+1,
screenName);
}
+#undef FIXED_SIZE
}
/*
Index: tests/window.test
===================================================================
RCS file: /cvsroot/tk/tests/window.test,v
retrieving revision 1.4
diff -u -r1.4 window.test
--- window.test1999/04/16 01:51:441.4
+++ window.test2000/07/03 13:58:20
@@ -41,6 +41,26 @@
"button .t.b -text hello"
(command bound to event)}}
+
+test window-1.2 {Tk_CreateWindowFromPath procedure, invalid window name} {
+ catch {destroy .t}
+ toplevel .t
+ list [catch {button .t.} err] $err
+} {1 {bad window path name ".t."}}
+
+test window-1.3 {Tk_CreateWindowFromPath procedure, invalid window name} {
+ catch {destroy .t}
+ toplevel .t
+ list [catch {button .t..} err] $err
+} {1 {bad window path name ".t.."}}
+
+test window-1.4 {Tk_CreateWindowFromPath procedure, invalid window name} {
+ list [catch {button ..} err] $err
+} {1 {bad window path name ".."}}
+
+
+catch {destroy .t}
+
# Most of the tests below don't produce meaningful results; they
# will simply dump core if there are bugs.
PatchFiles:
generic/tkWindow.c
tests/window.test
While admittedly odd, there is nothing wrong with this. Simple
tests show that using the empty string for a name works:
>Main< () 49 % toplevel .t
.t
>Main< () 50 % button .t.
.t.
>Main< () 51 % pack .t.
>Main< () 52 % .t. configure -text hello
>Main< () 53 % .t. cget -text
hello
I believe this is OK, as we also allow things like variables to
be the empty string. Unless this specifically breaks some element
of Tk, we should just leave it. Hmmm, to think of the obfuscation
possibilities of create some window named .....
-- 09/26/2000 hobbs
|