#4190 Tcl_IsChannelExisting() broken

obsolete: 8.5.5
closed-fixed
5
2008-11-23
2008-11-23
gustafn
No

Tcl_IsChannelExisting() broken in versions at least from 8.4.14 until 8.5.5 + head version.

If there exists e.g. a channel named "file76", a test for channel "sock7" will report,
that "sock7" exists already. Similarly, when there exists a channel named "sock182",
a test for "sock18" will be incorrect.

The bug is pretty obvious in Tcl_IsChannelExisting() in tcl/generic/tclIO.c

if ((*chanName == *name) &&
(memcmp(name, chanName, (size_t) chanNameLen) == 0)) {
return 1;
}

This comparison just tests, whether there exists a channel having the same first characters
as the queried channel, but not, if the name existing channel and the queried channel have the
same length.

There are many possible fixes; the fastest fix is most likely to increase chanNameLen
by 1, or to compare the string lengths to make the test more explicit.

Discussion

  • You are right about the +1, since both compared strings are null-terminated by construction.
    Fixed in HEAD.
    Please tell if you need a backport.
    (Notice this bug cannot harm the core alone, since there is no client of Tcl_IsChannelExisting; so it is only of concern for extensions/embedders).

     
    • status: open --> closed-fixed
     
  • gustafn
    gustafn
    2008-11-23

    A backport to 8.4.* would be nice (not sure if backport is the appropriate name),
    since the problem showed up on busy sites using aolserver and libthread, where
    libthread is using Tcl_IsChannelExisting() in ::thread::transfer. If i remember
    correctly, there is however no intention from the Tcl team to release another
    8.4 version. Most aolserver/OpenACS/DotLRN sites are still using Tcl 8.4

    I have no problem to fix this on our sites, but it is painful to tell other people
    to fix this on their systems as well...

    Many thanks!

    -gustaf

     
  • You will be pleased to know that Andreas has just committed it to 8.5 *and* 8.4, and that you may expect an AS version of 8.4 (possibly through the teacup) with it.

     
  • gustafn
    gustafn
    2008-11-23

    i am pleased! Many thanks to you and Andreas!

     
  • You will be pleased to know that Andreas has just committed it to 8.5 *and* 8.4, and that you may expect an AS version of 8.4 (possibly through the teacup) with it.

     
  • Sorry, duplicated comment due to a reload in browser :-}

     
  • To clarify in this game of telephone. I said that I backported because AS has customers which are based on 8.4. I did not say that a new release of an ActiveTcl 8.4 is forthcoming, which is partially implied by Alexandre's comment. He is right that the fix will go into the core pieces which are in the teapot, which are our basekits. The regular Tclsh/Wish are not distributed through the teapot.