Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Redirecting to a ref chan results in a seg fault

Closed / Fixed2826248fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2009-07-23 22:17:13
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.
andy22286plain2009-07-24 05:17:13
File Added - 336313: chan.tcl
andy22286plain2009-07-24 05:19:09
File Added - 336314: chan.tcl.valgrind
andy22286plain2009-07-24 05:19:21
File Deleted - 336314:
andy22286plain2009-07-24 05:19:52
File Added - 336315: chan.tcl.valgrind
andy22286plain2009-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
andreas_kupriesplain2009-07-24 05:27:14
File Added - 336317: io-unos-channels-in-exec.patch
andreas_kupriesplain2009-07-24 05:28:41
Attached a patch fixing the problem for me.
andreas_kupriesplain2009-07-24 05:52:38
Passes testsuite. Committed for HEAD.
Keeping open, check 8.5 branch as well.
andreas_kupriesplain2009-07-25 00:43:06
allow_comments - 1

Backported to 8.5.
Closing.
Log in (anonymous is fine) to add a comment.

Attachments: