Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-03-02
22:35 • Closed ticket [404865ffff]: rare bug in InfoLevelCmd plus 3 other changes artifact: 3df175b117 user: dkf
21:51 • Ticket [404865ffff]: 1 change artifact: c84cb3dfff user: dkf
21:05 • Ticket [404865ffff]: 4 changes artifact: 2a6a4a5a23 user: dkf
2001-03-01
17:06 • Ticket [404865ffff]: 4 changes artifact: 9aaf1ba674 user: dkf
17:06 • Add attachment infolevel-bug.tcl to ticket [404865ffffffffff|404865ffff... artifact: 8f92f638b6 user: dkf
16:41 • Ticket [404865ffff] rare bug in InfoLevelCmd status still Open with 4 other ... artifact: 0b89494ead user: dkf
00:57 • Ticket [404865ffff]: 4 changes artifact: 5eb98bfd61 user: msofer
00:49 • Ticket [404865ffff]: 4 changes artifact: 2e94f34e48 user: dgp
2001-02-28
21:26 • Ticket [404865ffff]: 5 changes artifact: 7df7bcec41 user: dkf
21:19 • Ticket [404865ffff]: 5 changes artifact: d1fb197a6a user: dkf
13:22 • New ticket [404865ffff]. artifact: 8fade80a5b user: msofer

rare bug in InfoLevelCmd

Closed / Fixed404865ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2001-02-28 13:22:37
(I could *not* trigger this rare event, but I'm sure
from the code that the bug is there)
InfoLevelCmd uses "iPtr->varFramePtr->objv" - as far as
I can tell, it is the only user.
Now "iPtr->varFramePtr->objv" is a pointer into the
evaluation stack: it is set in TclObjInterpProc
(tclProc.c), which gets it from TclExecuteByteCode
(tclExecute.c) [see INST_INVOKE]
The trouble is that the evaluation stack may grow (and
move), so that some combination of events will leave
iPtr->varFramePtr->objv pointing to ckfreed memory.
The combination of events could be:
 - proc A invokes proc B; proc B grows the stack
 - after returning from B, proc a requests "info level"

I do not see yet any nice & simple solution. Among the
clumsy and/or complicated solutions:
 - store instead a stack offset into the CallFrame; let
InfoLevelCmd know about the execution stack (to my
eyes, a very bad thing)
  - do not free the old stack memory until execution is
back at level 0, thereby keeping the pointers valid

Remark also that fixing matters in the first manner
will work for bytecodes, but may break "info level" for
non-compiled scripts! The second one may be very costly
in memory.
dkfplain2001-02-28 21:19:51
Logged In: YES 
user_id=79902

The following exercises the bug:

   set s {list }
   for {set i 0} {$i<2000} {incr i} {append s "$i "}
   proc B {} [append s {; puts [string length [info body
B][info body B]]}
   proc A {} {
      puts A=[info level]=[info level 0]; B; puts A=[info
level]=[info level 0]
   }
   A
dkfplain2001-02-28 21:26:37
Logged In: YES 
user_id=79902

The following exercises the bug:

   set s {list }
   for {set i 0} {$i<2000} {incr i} {append s "$i "}
   proc B {} [append s {; puts [string length [info body
B][info body B]]}
   proc A {} {
      puts A=[info level]=[info level 0]; B; puts A=[info
level]=[info level 0]
   }
   A
dgpplain2001-03-01 00:49:12
Logged In: YES 
user_id=80530

Looks like the TEXTAREA entry box mangled
the demonstration script.  Could you upload
it as an attached file?
msoferplain2001-03-01 00:57:49
Logged In: YES 
user_id=148712

The code does not demonstrate the effect in my setup (linux
RH 6.2). It is difficult to trigger the event, as dkf
explained to me: you have to cause the memory at the
previous location of the evaluation stack to be reused in
order for the bug to cause a core dump.
dkfplain2001-03-01 16:41:30
Logged In: YES 
user_id=79902

This bug has certainly existed since 8.1.0, and might also
exist in 8.0.* (the diffs get a little large at that point
for convenient reading...)
dkfplain2001-03-01 17:06:51
File Added - 4056: infolevel-bug.tcl

Logged In: YES 
user_id=79902

Added a script to do this, but I still can't guarantee that
it will actually successfully trigger the error for anyone
other that me (it is *very* dependant on the allocation
mechanism).  However, when I've tested with some version of
8.0, 8.3 and the current 8.4, I systematically get a crash
with the code as attached, and no crash if I put a comment
character in front of the list command.
dkfplain2001-03-02 21:05:15
Logged In: YES 
user_id=79902

I attach a *very* basic fix.  It is not yet of a quality
that I'd like to see in the core, but it does indicate the
sort of thing that needs to be done.
dkf Ticket [404865ffff]: 1 change [History diff]2001-03-02 21:51:17
dkf Closed ticket [404865ffff]. [History diff]2001-03-02 22:35:35
Log in (anonymous is fine) to add a comment.

Attachments: