Tcl Source Code

View Ticket
Login
Ticket UUID: 2826248
Title: Redirecting to a ref chan results in a seg fault
Type: Bug Version: obsolete: 8.6b1
Submitter: andy22286 Created on: 2009-07-23 22:17:13
Subsystem: 24. Channel Commands Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-07-25 00:43:06
Resolution: Fixed Closed By: andreas_kupries
    Closed on: 2009-07-24 17:43:06
Description:
When using a ref chan as part of an [exec] command, on redirection to the channel from another subprocess, a segmentation fault occurs.  This is due to a NULL function pointer, as detailed below.  See attached for sample script and associated valgrind error report.

As stated by aku,

akuTclpMakefile (tclUnixPipe) calls Tcl_GetChannelHandle (tclIO), this runs ->getHandleProc. This is NULL for reflected channels.
akuAccording to my comment in tclIORChan.c this getHandleProc should be NULL'able, i.e. NULL allowed. Seems not. Or some check is missing somewhere.
akuright, tcl.h says the same, getHandleProc can be set to NULL if not supported.
akuThat means any channel type without getHandleProc will crash 'exec' and 'open|' when using a chanel of that type.

akuso, we have to add a NULL check in Tcl_GetChannelHandle, and return TCL_ERROR if this occurs.

akuI will likely have to do some other things around this to get a nice error message. The standard message will just claim 'not opened for reading or writing', which is bogus for this case.
User Comments: andreas_kupries added on 2009-07-25 00:43:06:

allow_comments - 1

Backported to 8.5.
Closing.

andreas_kupries added on 2009-07-24 05:52:38:
Passes testsuite. Committed for HEAD.
Keeping open, check 8.5 branch as well.

andreas_kupries added on 2009-07-24 05:28:41:
Attached a patch fixing the problem for me.

andreas_kupries added on 2009-07-24 05:27:14:

File Added - 336317: io-unos-channels-in-exec.patch

andy22286 added on 2009-07-24 05:22:42:
The sample script fails as detailed in the bug description on:
Linux 2.6.28-13-generic Ubuntu 9.04 GNU/Linux

andy22286 added on 2009-07-24 05:19:52:

File Added - 336315: chan.tcl.valgrind

andy22286 added on 2009-07-24 05:19:21:

File Deleted - 336314:

andy22286 added on 2009-07-24 05:19:09:

File Added - 336314: chan.tcl.valgrind

andy22286 added on 2009-07-24 05:17:13:

File Added - 336313: chan.tcl

Attachments: