From 9f2dfbf322e9a4ecc4f8ac4ecf77f4af08244179 Mon Sep 17 00:00:00 2001 From: hobbs Date: Fri, 30 Mar 2001 21:52:28 +0000 Subject: * tests/bind.test (bind-22.18): * generic/tkBind.c (NameToWindow): handled the error case where a valid-looking but invalid identifier could be passed in certain event generate options causing a crash. [Bug #411307] --- generic/tkBind.c | 14 ++++++++++---- tests/bind.test | 24 +++++++----------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/generic/tkBind.c b/generic/tkBind.c index 71e5db1..d06d246 100644 --- a/generic/tkBind.c +++ b/generic/tkBind.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkBind.c,v 1.14 2000/11/22 01:49:37 ericm Exp $ + * RCS: @(#) $Id: tkBind.c,v 1.15 2001/03/30 21:52:28 hobbs Exp $ */ #include "tkPort.h" @@ -3716,7 +3716,7 @@ NameToWindow(interp, mainWin, objPtr, tkwinPtr) char *name; Tk_Window tkwin; int id; - + name = Tcl_GetStringFromObj(objPtr, NULL); if (name[0] == '.') { tkwin = Tk_NameToWindow(interp, name, mainWin); @@ -3725,12 +3725,18 @@ NameToWindow(interp, mainWin, objPtr, tkwinPtr) } *tkwinPtr = tkwin; } else { - if (TkpScanWindowId(NULL, name, &id) != TCL_OK) { + /* + * Check for the winPtr being valid, even if it looks ok to + * TkpScanWindowId. [Bug #411307] + */ + + if ((TkpScanWindowId(NULL, name, &id) != TCL_OK) || + ((*tkwinPtr = Tk_IdToWindow(Tk_Display(mainWin), (Window) id)) + == NULL)) { Tcl_AppendResult(interp, "bad window name/identifier \"", name, "\"", (char *) NULL); return TCL_ERROR; } - *tkwinPtr = Tk_IdToWindow(Tk_Display(mainWin), (Window) id); } return TCL_OK; } diff --git a/tests/bind.test b/tests/bind.test index 06d3078..ad84ed5 100644 --- a/tests/bind.test +++ b/tests/bind.test @@ -7,7 +7,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: bind.test,v 1.8 2000/08/03 20:36:17 ericm Exp $ +# RCS: @(#) $Id: bind.test,v 1.9 2001/03/30 21:52:28 hobbs Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -1945,7 +1945,7 @@ test bind-22.2 {HandleEventGenerate} { } {1 {bad window name/identifier "zzz"}} test bind-22.3 {HandleEventGenerate} { list [catch {event gen 47 } msg] $msg -} {1 {window id "47" doesn't exist in this application}} +} {1 {bad window name/identifier "47"}} test bind-22.4 {HandleEventGenerate} { setup bind .b.f