Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 5b629d166950d8b5cf2118b6fc6e6154ec3268fa2fc9e57eb8887b2f5b2dacbe
Ticket: ea69b0258a9833cb61ada42d1fc742d90aec04d0
Crash when using a channel transformation on TCP client socket
User & Date: petrokaz on 2023-01-12 15:04:29
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed to:
    Tcl crashes when I setup a channel transformation on a non-blocking TCP client socket, and then remove it.
    
    Here is the minimal reproducible example.
    A dummy echo server:
    ```
    ncat -l -k -e /bin/cat --crlf 0.0.0.0 4400
    ```
    
    And my Tcl script:
    
    ```
    package require tcl::transform::observe
    
    proc sleep {delay} {
        after $delay {set ::sleepVar 1}
        vwait ::sleepVar
    }
    
    proc writable {sock} {
        chan event $sock writable {}
        chan configure $sock -translation {crlf binary} -blocking 0 -buffering full -encoding binary
        chan event $sock readable [list readable $sock]
        set ::status "connected"
    }
    
    proc readable {sock} {
        set readCount [chan gets $sock line]
        if {$readCount <= 0} {
            if {[eof $sock]} { 
                puts "Connection aborted"
                close $sock
                set :status "closed"
                break
            }
            # we don't have a full line yet - wait for next chan event
            return
        }
        set ::msg $line
    }
    
    set sock [socket -async localhost 4400]
    chan event $sock writable [list writable $sock]
    vwait ::status
    puts "Status $status"
    tcl::transform::observe $sock stdout ""
    
    puts $sock "Hello\r\n"
    flush $sock
    
    vwait ::msg
    puts "Got $msg"
    # sleep 0 ;#- avoids crash
    chan pop $sock
    
    sleep 100 ;# crashes here
    
    puts DONE
    ```
    
    This produces the following output:
    
    ```
    Status connected
    Hello
    
    Got Hello
    Segmentation fault (core dumped)
    ```
    
    The lines "hello\\r\\n" are printed by the channel observer. Then Tcl crashes after I remove the channel transformation and enter the event loop.
    
    The crash does NOT occur if I uncomment the line sleep 0 ;#- avoids crash
    
    The crash does NOT occur if I don't use the channel transformation.
    
    I can reproduce the crash with 100% chance on OpenSUSE 15.4/Tcl 8.6.12 (from repos) and Windows/Tcl 8.6.13 (from Magicsplat).
    
    Thanks in advance.
    
  5. foundin changed to: "8.6.13"
  6. is_private changed to: "0"
  7. login: "petrokaz"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "e603fff52985a053bcf4cafd5d99e14a243356ca"
  10. resolution changed to: "None"
  11. severity changed to: "Critical"
  12. status changed to: "Open"
  13. submitter changed to: "petrokaz"
  14. subsystem changed to: "26. Channel Transforms"
  15. title changed to:
    Crash when using a channel transformation on TCP client socket
    
  16. type changed to: "Bug"