Tcl Source Code

View Ticket
Login
Ticket UUID: ccc448a6bfd59cbdb2bd5cfd3392e386994883aa
Title: namespace ensemble subcommand name prefix matching and a subsequent error results in a segmentation fault
Type: Bug Version:
Submitter: pooryorick Created on: 2021-09-01 21:32:18
Subsystem: 21. [namespace] Assigned To: pooryorick
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2021-09-03 07:54:53
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2021-09-03 07:54:53
Description: (text/x-fossil-wiki)
When passed as a file to tclsh, the following script, with <code>eva</code>
missing the final <code>l</code>, results in a segmentation fault:

<code><verbatim>
    namespace eva n1 {error hello}
</verbatim></code>

An alternate script that produces the same result is:

<code><verbatim>
    namespace eval n1 {
        namespace ensemble create
        namespace export *
        proc p1 args {error hello}
    }
    namespace eva n1 {::n1 p1}
</verbatim></code>

The reason is that <code>TclSpellFix</code> sets <code>NULL</code> as the first
object pointer in <code>iPtr->ensembleRewrite.sourceObjs</code> and then later,
in <code>NRNamespaceEvalCmd</code>, <code>TclFetchEnsembleRoot</code> copies a
pointer to this array into <code>framePtr->objv</code>. Next, when an error
occurs, <code>TclLogCommandInfo</code> accesses this array and trips on the
<code>NULL</code>, causing the segmentation fault.
User Comments: jan.nijtmans added on 2021-09-03 07:54:53: (text/x-fossil-wiki)
Thanks! Closing

pooryorick added on 2021-09-02 23:05:08: (text/x-fossil-wiki)
Fix merged to core-8-6-branch in [da5128637598b0f1].

pooryorick added on 2021-09-02 22:43:11: (text/x-fossil-wiki)
Fix merged to core-8-branch in [bd393417060a158f].

pooryorick added on 2021-09-02 21:17:53: (text/x-fossil-wiki)
Warning silenced in [d49a1b03291b4cde].

jan.nijtmans added on 2021-09-02 10:07:56: (text/x-fossil-wiki)
Windows build fails due to the the following warning, which is threated as an error in debug builds:
<pre>
D:\a\tcl\tcl\win\..\generic\tclEnsemble.c(2247): error C2220: the following warning is treated as an error
D:\a\tcl\tcl\win\..\generic\tclEnsemble.c(2247): warning C4047: '=': 'Tcl_Obj *const *' differs in levels of indirection from 'Tcl_Obj *const '
</pre>

jan.nijtmans added on 2021-09-02 09:21:02:
Is this fix going to be backported to 8.7 -> 8.6 too?

pooryorick added on 2021-09-01 23:14:19: (text/x-fossil-wiki)
Fixed in commit [a2e801a3d6c1675b].