Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 40b2eb0a5d0edd79a622fe01bcc618ed02e4ed9aad98825c110eea381de46697
Ticket: 46dda6fc2904ee86cc45b3ddc14ce6fb6b4303e4
Tcl 9: segfault with execution leave trace when proc result contains \<newline>
User & Date: xdelaruelle on 2023-02-12 12:25:28
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed to:
    Hello,
    
    I was testing how my software [1] is coping with Tcl 9 and I think I have spotted an issue on the "trace" feature.
    
    I observe that tclsh segfaults when an execution leave trace is triggered and procedure result contains a "\<newline>" sequence.
    
    I would expect the script to continue until its end.
    
    I have made a small code example to reproduce this issue. 3 different files are needed:
    
    * myfile_ok
    * myfile_bad
    * test.tcl
    
    This example works fine on Tcl 8.5, 8.6, 8.7. Issue is observed on 9.0, I have tested it against 9.0a3 and 9.0b1 (current core-9-0-b1 git branch).
    
    Regards,
    Xavier
    
    [1] https://github.com/cea-hpc/modules
    
    ### myfile_ok
    ```
    set myvar foo
    switch -- $myvar {
        foo - bar - baz - foobar {
            set res pass
        }
        other {
            set res fail
        }
    }
    ```
    
    ### myfile_bad
    ```
    set myvar foo
    switch -- $myvar {
        foo - bar -\
        baz - foobar {
            set res pass
        }
        other {
            set res fail
        }
    }
    ```
    
    ### test.tcl
    ```
    proc myproc {what} {
        set fname myfile_${what}
        set fid [open $fname]
        set res [read $fid]
        close $fid
        return $res
    }
    
    proc traceEnter {cmdstring op} {
        puts "trace enter $cmdstring"
    }
    proc traceLeave {cmdstring code result op} {
        puts "trace leave $cmdstring"
    }
    
    puts "before myproc ok"
    set content [myproc ok]
    puts "after myproc ok"
    
    puts "before myproc bad"
    set content [myproc bad]
    puts "after myproc bad"
    
    puts {}
    
    trace add execution myproc enter traceEnter
    trace add execution myproc leave traceLeave
    
    puts "with trace before myproc ok"
    set content [myproc ok]
    puts "with trace after myproc ok"
    
    puts "with trace before myproc bad"
    set content [myproc bad]
    puts "with trace after myproc bad"
    
    puts {}
    
    interp create foo
    interp alias foo myproc {} myproc
    
    interp eval foo {
        puts "interp with trace before myproc ok"
        set content [myproc ok]
        puts "interp with trace after myproc ok"
    
        puts "interp with trace before myproc bad"
        set content [myproc bad]
        puts "interp with trace after myproc bad"
    }
    ```
    
    ### Test execution
    ```
    $ /usr/local/tcl8.7/bin/tclsh8.7 test.tcl
    before myproc ok
    after myproc ok
    before myproc bad
    after myproc bad
    
    with trace before myproc ok
    trace enter myproc ok
    trace leave myproc ok
    with trace after myproc ok
    with trace before myproc bad
    trace enter myproc bad
    trace leave myproc bad
    with trace after myproc bad
    
    interp with trace before myproc ok
    trace enter myproc ok
    trace leave myproc ok
    interp with trace after myproc ok
    interp with trace before myproc bad
    trace enter myproc bad
    trace leave myproc bad
    interp with trace after myproc bad
    
    $ /usr/local/tcl9.0b1/bin/tclsh9.0 test.tcl
    before myproc ok
    after myproc ok
    before myproc bad
    after myproc bad
    
    with trace before myproc ok
    trace enter myproc ok
    trace leave myproc ok
    with trace after myproc ok
    with trace before myproc bad
    trace enter myproc bad
    Segmentation fault (core dumped)
    $ echo $?
    139
    ```
    
    # Crash information
    ```
    Process 386290 (tclsh9.0) of user 1000 dumped core.
    Module /usr/local/tcl9.0b1/lib/libtcl9.0.so with build-id 254e417b3c6ef47f536226ded9b324e619f1d399
    Module linux-vdso.so.1 with build-id e09c2d859d0bcca3cc4ad2a1f473b243838cf213
    Module ld-linux-x86-64.so.2 with build-id 321b87738a8ee7220b3c045c0d4d93150be54470
    Module libc.so.6 with build-id 8257ee907646e9b057197533d1e4ac8ede7a9c5c
    Module libm.so.6 with build-id 7c51a65c054f2ddc34c8325d82a1150f580f0d91
    Module libz.so.1 with build-id aec7e77c3a6ce5dd195a8c86a8fb1178715cf45f
    Metadata for module libz.so.1 owned by FDO found: {
            "type" : "rpm",
            "name" : "zlib",
            "version" : "1.2.11-33.fc36",
            "architecture" : "x86_64",
            "osCpe" : "cpe:/o:fedoraproject:fedora:36"
    }
    
    Module libtcl9.0.so with build-id 254e417b3c6ef47f536226ded9b324e619f1d399
    Module tclsh9.0 with build-id decbc80d055a6d0934d199146c0757bd7da1d020
    Stack trace of thread 386290:
    #0  0x00007fcfd06c3635 TclScanElement (libtcl9.0.so + 0x149635)
    #1  0x00007fcfd06c52c4 Tcl_DStringAppendElement (libtcl9.0.so + 0x14b2c4)
    #2  0x00007fcfd06be33a TraceExecutionProc (libtcl9.0.so + 0x14433a)
    #3  0x00007fcfd06be5b2 TclCheckExecutionTraces (libtcl9.0.so + 0x1445b2)
    #4  0x00007fcfd05c0b07 TEOV_RunLeaveTraces (libtcl9.0.so + 0x46b07)
    #5  0x00007fcfd05bfe82 TclNRRunCallbacks (libtcl9.0.so + 0x45e82)
    #6  0x00007fcfd05c1cf3 TclEvalEx (libtcl9.0.so + 0x47cf3)
    #7  0x00007fcfd069c581 TclSubstTokens (libtcl9.0.so + 0x122581)
    #8  0x00007fcfd05c1bb5 TclEvalEx (libtcl9.0.so + 0x47bb5)
    #9  0x00007fcfd068580a Tcl_FSEvalFileEx (libtcl9.0.so + 0x10b80a)
    #10 0x00007fcfd06903c8 Tcl_MainEx (libtcl9.0.so + 0x1163c8)
    #11 0x00000000004010dd main (tclsh9.0 + 0x10dd)
    #12 0x00007fcfd0229510 __libc_start_call_main (libc.so.6 + 0x29510)
    #13 0x00007fcfd02295c9 __libc_start_main@@GLIBC_2.34 (libc.so.6 + 0x295c9)
    #14 0x0000000000401105 _start (tclsh9.0 + 0x1105)
    ELF object binary architecture: AMD x86-64
    ```
    
  5. foundin changed to: "9.0b1"
  6. is_private changed to: "0"
  7. login: "xdelaruelle"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "231d7ecff918d0384f1ee469cf171339e824104a"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "xdelaruelle"
  14. subsystem changed to: "46. Traces"
  15. title changed to:
    Tcl 9: segfault with execution leave trace when proc result contains \<newline>
    
  16. type changed to: "Bug"