From 18500d2958ab58a718a10b5c7f98b2b3f3c398a9 Mon Sep 17 00:00:00 2001 From: das Date: Wed, 2 Aug 2006 20:04:40 +0000 Subject: * unix/tclUnixPipe.c (TclpCreateProcess): for USE_VFORK: ensure standard channels are initialized before vfork() so that the child doesn't potentially corrupt global state in the parent's address space. --- ChangeLog | 6 ++++++ unix/tclUnixPipe.c | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5e138d1..9e9a23c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-08-03 Daniel Steffen + + * unix/tclUnixPipe.c (TclpCreateProcess): for USE_VFORK: ensure standard + channels are initialized before vfork() so that the child doesn't + potentially corrupt global state in the parent's address space. + 2006-07-30 Kevin Kenny * tests/clock.test: Allowed UTC as a synonym for GMT in two diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c index de92407..6825f24 100644 --- a/unix/tclUnixPipe.c +++ b/unix/tclUnixPipe.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixPipe.c,v 1.23.2.6 2006/07/20 06:21:46 das Exp $ + * RCS: @(#) $Id: tclUnixPipe.c,v 1.23.2.7 2006/08/02 20:04:40 das Exp $ */ #include "tclInt.h" @@ -430,6 +430,23 @@ TclpCreateProcess(interp, argc, argv, inputFile, outputFile, errorFile, newArgv[i] = Tcl_UtfToExternalDString(NULL, argv[i], -1, &dsArray[i]); } +#ifdef USE_VFORK + /* + * After vfork(), do not call code in the child that changes global state, + * because it is using the parent's memory space at that point and writes + * might corrupt the parent: so ensure standard channels are initialized in + * the parent, otherwise SetupStdFile() might initialize them in the child. + */ + if (!inputFile) { + Tcl_GetStdChannel(TCL_STDIN); + } + if (!outputFile) { + Tcl_GetStdChannel(TCL_STDOUT); + } + if (!errorFile) { + Tcl_GetStdChannel(TCL_STDERR); + } +#endif pid = fork(); if (pid == 0) { int joinThisError = errorFile && (errorFile == outputFile); -- cgit v0.12