Tcl Source Code

View Ticket
Login
Ticket UUID: 0de6c1d79cfba2ea1b21a6732cd9a6e1e1201563
Title: [child invokehidden info frame] dereferences NULL
Type: Bug Created on: 2024-03-19 02:56:44
Submitter: andy Assigned to: nobody
Subsystem: 17. Commands I-L Severity: Minor
Priority: 5 Medium Last modified: 2024-07-02 13:39:12
Status: Closed Closed by: apnadkarni
Resolution: Fixed Closed on: 2024-07-02 13:39:12
Version: 8.6.13
Description:

The following crashes Tcl:

interp create child
child hide info
child invokehidden info frame

This dies in tclCmdIL.c line 1163 because *cmdFramePtrPtr is NULL, since iPtr->cmdFramePtr is NULL.

Replacing "info frame" with "info level" returns 0, no crash.

Backtrace:

#0  InfoFrameCmd (dummy=0x0, interp=0xc5a640, objc=1, objv=0xc6f720)
    at /root/tclkit-dbg/tcl/build/unix/tclCmdIL.c:1163
#1  0x00000000005ca355 in Dispatch (data=0xc43498, interp=0xc5a640, result=0)
    at /root/tclkit-dbg/tcl/build/unix/tclBasic.c:4467
#2  0x00000000005ca3db in TclNRRunCallbacks (interp=0xc5a640, result=0,
    rootPtr=0x0) at /root/tclkit-dbg/tcl/build/unix/tclBasic.c:4503
#3  0x00000000006c7095 in NRPostInvokeHidden (data=0xcad058, interp=0xae4f40,
    result=0) at /root/tclkit-dbg/tcl/build/unix/tclInterp.c:3091
#4  0x00000000005ca3db in TclNRRunCallbacks (interp=0xae4f40, result=0,
    rootPtr=0x0) at /root/tclkit-dbg/tcl/build/unix/tclBasic.c:4503
#5  0x00000000005ccda9 in TclEvalObjEx (interp=0xae4f40, objPtr=0xca0500,
    flags=131072, invoker=0x0, word=0)
    at /root/tclkit-dbg/tcl/build/unix/tclBasic.c:6068
#6  0x00000000005ccd3d in Tcl_EvalObjEx (interp=0xae4f40, objPtr=0xca0500,
    flags=131072) at /root/tclkit-dbg/tcl/build/unix/tclBasic.c:6049
#7  0x00000000006c0131 in Tcl_RecordAndEvalObj (interp=0xae4f40,
    cmdPtr=0xca0500, flags=131072)
    at /root/tclkit-dbg/tcl/build/unix/tclHistory.c:190
#8  0x00000000006f0bfa in Tcl_MainEx (argc=-1, argv=0x7fffffffdb20,
    appInitProc=0x429e16 <TclKit_AppInit>, interp=0xae4f40)
    at /root/tclkit-dbg/tcl/build/unix/tclMain.c:520
#9  0x0000000000429ffe in main (argc=1, argv=0x7fffffffdb18) at main.c:7
User Comments:
apnadkarni added on 2024-05-08 13:58:26:
Still present in 9.0.

`info frame` (TIP 280) is very particular about the presence of an appropriately filled out `CmdFrame` structure. While most of the TclEvalxxx, byte code compiler etc. were adapted with TIP 280 to do the needful, some code paths, including that of interp invokehidden were omitted. Thus the crash.

Fixing `invokehidden` is non trivial (at least from my limited perspective) as with the introduction of NRE, the code path traverses through multiple layers of interp contexts, the NRE trampoline, the namespace ensemble, coroutine contexts.

I've started a branch apn-info-frame to at least try and protect against a crash in some semi-sensible fashion if not give a complete frame dictionary result.

apnadkarni added on 2024-07-02 11:37:05:
Closing as crash is fixed in [7077dea20e]. A follow-on bug remains - logged as [708b005695].

apnadkarni added on 2024-07-02 13:39:12:

@sebres - I do not agree with your [e40407c5e8] commit to raise an error instead of returning "type=precompiled" as better for consistency. Raising an error implies the caller has passed some invalid value. That is not the case here. The fault lies in the implementation, not the caller, in not having frame information available. So it seems more reasonable to return something that says "frame information not available" as opposed to something that tells the caller they made an error. It's misleading.

Moreover, with the above commit

% child invokehidden info frame
1
% child invokehidden info frame 0
bad level "0"
% child invokehidden info frame 1
bad level "1"

does not seem consistent at all. info frame returns a level but then you try to get information and it says bad level.

The dummied up use of "precompiled" as stated in comments is really in place of "framinfonotavailable" because the former also has no frame info available. Adding another type would require a TIP.

This is something I am not going to argue further as it is not that important to me. But if you change your mind, I'd prefer not to raise an error.