From a847875480c40480b57e2c692a0cf929aba18b03 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 22 Sep 2025 10:09:29 +0000 Subject: Bug [c9e68eb6ca] - check getenv result for TCL_LIBRARY --- unix/tclUnixInit.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index c7de6a8..8c16d74 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -479,8 +479,10 @@ TclpInitLibraryPath( */ str = getenv("TCL_LIBRARY"); /* INTL: Native. */ - Tcl_ExternalToUtfDString(NULL, str, -1, &buffer); - str = Tcl_DStringValue(&buffer); + if (str != NULL) { + Tcl_ExternalToUtfDString(NULL, str, -1, &buffer); + str = Tcl_DStringValue(&buffer); + } if ((str != NULL) && (str[0] != '\0')) { Tcl_DString ds; -- cgit v0.12 From b74718ee37115ce70b36b70a6fd197b8ff86857c Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 22 Sep 2025 10:34:22 +0000 Subject: Bug [c9e68eb6ca] - Windows version --- win/tclWinInit.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/win/tclWinInit.c b/win/tclWinInit.c index 29e177d..3e4daab 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -221,6 +221,7 @@ AppendEnvironment( { int pathc; WCHAR wBuf[MAX_PATH]; + DWORD dw; char buf[MAX_PATH * 3]; Tcl_Obj *objPtr; Tcl_DString ds; @@ -245,13 +246,14 @@ AppendEnvironment( Tcl_Panic("no '/' character found in lib"); } - /* - * The "L" preceding the TCL_LIBRARY string is used to tell VC++ that - * this is a Unicode string. - */ - - GetEnvironmentVariableW(L"TCL_LIBRARY", wBuf, MAX_PATH); - WideCharToMultiByte(CP_UTF8, 0, wBuf, -1, buf, MAX_PATH * 3, NULL, NULL); + dw = GetEnvironmentVariableW(L"TCL_LIBRARY", wBuf, MAX_PATH); + if (dw <= 0 || dw >= (sizeof(buf) / sizeof(buf[0]))) { + return; + } + if (WideCharToMultiByte( + CP_UTF8, 0, wBuf, -1, buf, MAX_PATH * 3, NULL, NULL) == 0) { + return; + } if (buf[0] != '\0') { objPtr = Tcl_NewStringObj(buf, -1); -- cgit v0.12 From 937f3434c1300404d5643a2943e5dfba734d4022 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 23 Sep 2025 11:42:28 +0000 Subject: Fix for fix. If getenv returns NULL, Tcl_DString buffer still needs initialization --- unix/tclUnixInit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 8c16d74..6460c90 100644 --- a/unix/tclUnixInit.c +++ b/unix/tclUnixInit.c @@ -482,6 +482,8 @@ TclpInitLibraryPath( if (str != NULL) { Tcl_ExternalToUtfDString(NULL, str, -1, &buffer); str = Tcl_DStringValue(&buffer); + } else { + Tcl_DStringInit(&buffer); } if ((str != NULL) && (str[0] != '\0')) { -- cgit v0.12