From 30949cbba8e868da7e1fa1e4200be6385bd07797 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 23 Nov 2000 13:50:10 +0000 Subject: Fixed bug #120819 by prohibiting images from starting with a period; I'm still not quite sure what exactly was going wrong in the bug, but I suspect the problem might have actually been due to the deletion of all images while in the midst of creating an image. The restriction is pretty light when it comes to existing code, since it previously caused a core dump due to an image typePtr field being set to random garbage, an indication of over-eager use of free()... --- ChangeLog | 8 ++++++++ doc/image.n | 11 +++++++---- generic/tkImage.c | 14 +++++++++++++- tests/image.test | 5 ++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ca0b5f..3eaeb60 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-11-23 Donal K. Fellows + + * doc/image.n: + * tests/image.test (image-1.10): + * generic/tkImage.c (Tk_ImageObjCmd): Prohibited image names that + start with "." since they can cause some really obscure crashes. + Fixes Bug #120819. [POTENTIAL INCOMPATABILITY] + 2000-11-21 Eric Melski Overall change: Implemented TIP 5, which exports diff --git a/doc/image.n b/doc/image.n index 4277ef4..dcd5034 100644 --- a/doc/image.n +++ b/doc/image.n @@ -5,7 +5,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: image.n,v 1.3 2000/05/15 18:21:47 ericm Exp $ +'\" RCS: @(#) $Id: image.n,v 1.4 2000/11/23 13:50:10 dkf Exp $ '\" .so man.macros .TH image n 4.0 Tk "Tk Built-In Commands" @@ -27,9 +27,12 @@ It can take several different forms, depending on the Creates a new image and returns its name. \fItype\fR specifies the type of the image, which must be one of the types currently defined (e.g., \fBbitmap\fR). -\fIname\fR specifies the name for the image; if it is omitted then -Tk picks a name of the form \fBimage\fIx\fR, where \fIx\fR is -an integer. +\fIname\fR specifies the name for the image +.VS 8.4 +(which may not start with a period "." character); +.VE 8.4 +if it is omitted then Tk picks a name of the form \fBimage\fIx\fR, +where \fIx\fR is an integer. There may be any number of \fIoption\fR\-\fIvalue\fR pairs, which provide configuration options for the new image. The legal set of options is defined separately for each image diff --git a/generic/tkImage.c b/generic/tkImage.c index 31ac3bb..2ebb5de 100644 --- a/generic/tkImage.c +++ b/generic/tkImage.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: tkImage.c,v 1.7 2000/05/15 18:21:47 ericm Exp $ + * RCS: @(#) $Id: tkImage.c,v 1.8 2000/11/23 13:50:11 dkf Exp $ */ #include "tkInt.h" @@ -232,6 +232,18 @@ Tk_ImageObjCmd(clientData, interp, objc, objv) sprintf(idString, "image%d", dispPtr->imageId); name = idString; firstOption = 3; + } else if (arg[0] == '.') { + /* + * It is a really bad idea to create an image with the + * same name as the root window, and who knows what + * will happen if any other (potential) window name is + * used. So it's prohibited for safety, so stopping + * bug #120819 + */ + Tcl_AppendResult(interp, "image names cannot start with " + "period symbols: \"", arg, "\" is illegal", + (char *)NULL); + return TCL_ERROR; } else { name = arg; firstOption = 4; diff --git a/tests/image.test b/tests/image.test index b2abc36..296eedf 100644 --- a/tests/image.test +++ b/tests/image.test @@ -7,7 +7,7 @@ # Copyright (c) 1998-1999 by Scriptics Corporation. # All rights reserved. # -# RCS: @(#) $Id: image.test,v 1.4 2000/05/15 18:21:47 ericm Exp $ +# RCS: @(#) $Id: image.test,v 1.5 2000/11/23 13:50:10 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -80,6 +80,9 @@ test image-1.9 {Tk_ImageCmd procedure, "create" option} { eval image delete [image names] list [catch {image create test -badName foo} msg] $msg [image names] } {1 {bad option name "-badName"} {}} +test image-1.10 {Tk_ImageCmd procedure, "create" option} { + list [catch {image create test .} msg] $msg +} {1 {image names cannot start with period symbols: "." is illegal}} test image-2.1 {Tk_ImageCmd procedure, "delete" option} { list [catch {image delete} msg] $msg -- cgit v0.12