From 1acbd7884a685ddd69efcf085700c36f2192bc95 Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 10 Nov 2005 11:22:20 +0000 Subject: Fix [Bug 1353022] --- ChangeLog | 3 +++ win/tkWinDialog.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e2d38f..950754d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ * win/tkWinDialog.c (ConvertExternalFilename): Factored out the encoding conversion and de-backslash-ing code that is used in many places in this file. + (GetFileNameW, GetFileNameA, ChooseDirectoryValidateProc): Make sure + that data is freed correctly and that certain (hopefully impossible) + failure modes won't cause crashes. [Bug 1353022] 2005-11-06 Pat Thoyts diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c index e22b2a9..4fada3a 100644 --- a/win/tkWinDialog.c +++ b/win/tkWinDialog.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinDialog.c,v 1.40 2005/11/10 11:12:07 dkf Exp $ + * RCS: @(#) $Id: tkWinDialog.c,v 1.41 2005/11/10 11:22:21 dkf Exp $ * */ @@ -665,6 +665,7 @@ GetFileNameW( Tcl_UtfToExternal(NULL, unicodeEncoding, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds), 0, NULL, (char *) file, sizeof(file), NULL, NULL, NULL); + Tcl_DStringFree(&ds); break; } case FILE_MULTIPLE: @@ -1100,6 +1101,7 @@ GetFileNameA( Tcl_UtfToExternal(NULL, NULL, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds), 0, NULL, (char *) file, sizeof(file), NULL, NULL, NULL); + Tcl_DStringFree(&ds); break; } case FILE_MULTIPLE: @@ -1879,9 +1881,16 @@ ChooseDirectoryValidateProc( * like ~ are converted correctly. */ - Tcl_TranslateFileName(chooseDirSharedData->interp, - (char *)lParam, &initDirString); - lstrcpyn (string, Tcl_DStringValue(&initDirString), MAX_PATH); + if (Tcl_TranslateFileName(chooseDirSharedData->interp, + (char *)lParam, &initDirString) == NULL) { + /* + * Should we expose the error (in the interp result) to the user + * at this point? + */ + chooseDirSharedData->utfRetDir[0] = '\0'; + return 1; + } + lstrcpyn(string, Tcl_DStringValue(&initDirString), MAX_PATH); Tcl_DStringFree(&initDirString); if (SetCurrentDirectory((char *)string) == 0) { -- cgit v0.12