Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2004-02-18
06:54 • Closed ticket [772288ffff]: Crash when std channels not open plus 7 other ch... artifact: 8d5352b0be user: hobbs
2004-02-07
02:34 • Ticket [772288ffff]: 5 changes artifact: d8b3574495 user: hobbs
2003-11-07
06:22 • Ticket [772288ffff]: 4 changes artifact: a3b9fbc949 user: hobbs
2003-10-02
20:15 • Ticket [772288ffff]: 4 changes artifact: 9e9424f9a2 user: rmax
20:15 • Add attachment open-std-channels.patch to ticket [772288ffffffffff|7722... artifact: 53aa1657de user: rmax
20:15 • Ticket [772288ffff] Crash when std channels not open status still Open with ... artifact: f9de8bee66 user: rmax
16:38 • Ticket [772288ffff]: 4 changes artifact: 1af25c2653 user: rmax
2003-07-19
03:19 • Ticket [772288ffff]: 4 changes artifact: 3c546627e8 user: hobbs
03:15 • Ticket [772288ffff]: 1 change artifact: be272f835c user: hobbs
2003-07-16
20:18 • Add attachment channelbug.patch to ticket [772288ffff] artifact: 95bb627da5 user: dkf
20:18 • Ticket [772288ffff] Crash when std channels not open status still Open with ... artifact: 44a5153fcf user: dkf
13:18 • New ticket [772288ffff]. artifact: ebed174ca5 user: dkf

Crash when std channels not open

Closed / Fixed772288ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-07-16 13:18:15
The following script crashes both the HEAD and the 8.4
branch:
  open /dev/null
when run like this (from BASH, but there are other
equivalent situations):
  tclsh bug.tcl <&-

The effect of the invokation is to make tclsh run
without stdin opened (the same also happens with stdout
and stderr.)  This is caused by leaving the
initialisation of the channel table until the call to
Tcl_RegisterChannel() as part of the closing stages of
the [open] implementation, which ensures that fd0 (or 1
or 2) is put in the table twice, once for stdin/out/err
and once for the newly created channel for [open], with
the second time being the crash.

The attached patch fixes this, but causes test
encoding-24.3 to fail, and will break any script that
depends on setting [encoding system] early so as to
alter the encodings of the std channels.

This problem was discovered by rmax
dkfplain2003-07-16 20:18:16
File Added - 55966: channelbug.patch
hobbs Ticket [772288ffff]: 1 change [History diff]2003-07-19 03:15:26
hobbsplain2003-07-19 03:19:03
Logged In: YES 
user_id=72656

I want a much better understanding of the implications of this 
bug before placing it into 8.4.x
rmaxplain2003-10-02 16:38:28
Logged In: YES 
user_id=124643

Any news here, Jeff?
Today another colleague got hit by this bug, because stdin
is closed on processes started from fvwm2 buttons or menus.
rmaxplain2003-10-02 20:15:13
Logged In: YES 
user_id=124643

How about this patch, at least as a workaround to prevent
the crash until a better solution is found? Unlike Donal's
proposal no tests fail with this patch applied. There might
be better places for adding these lines, but
TclpInitPlatform was the most reasonable place I have found.
rmaxplain2003-10-02 20:15:16
File Added - 63206: open-std-channels.patch
hobbsplain2003-11-07 06:22:45
Logged In: YES 
user_id=72656

The alternate patch ignores Windows ... but is that 100% 
valid?  I recently had to solve this by checking for the 
standard channels being NULL on Windows.  I can't repro this 
with a variation of bug.tcl though.
hobbsplain2004-02-07 02:34:00
Logged In: YES 
user_id=72656

we should have a test case for this.
hobbsplain2004-02-18 06:54:39
Logged In: YES 
user_id=72656

test unixInit-7.1 {closed standard channel} -body {
    set tclsh [interpreter]
    makeFile {puts [open /dev/null]} crash.tcl
    makeFile [subst -nocommands {
close stdin
exec $tclsh crash.tcl
    }] crashtest.tcl
    exec $tclsh crashtest.tcl
} -returnCodes 0

in 8.4.6 and 8.5a1.
Log in (anonymous is fine) to add a comment.

Attachments: