Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2002-08-27
00:39 • Closed ticket [599788ffff]: error in (array element script) causing tclsh segfau... artifact: 5ea57da335 user: msofer
2002-08-26
00:39 • Ticket [599788ffff]: 5 changes artifact: 9d594bf5cb user: msofer
2002-08-25
20:56 • Ticket [599788ffff]: 4 changes artifact: 10d81a2eff user: msofer
19:20 • Ticket [599788ffff]: 5 changes artifact: 5e7d8159f1 user: msofer
07:29 • Ticket [599788ffff]: 2 changes artifact: c85b8c1816 user: wilkason
07:25 • Ticket [599788ffff]: 4 changes artifact: 3e747b2e02 user: wilkason
07:25 • Add attachment test.tcl to ticket [599788ffff] artifact: 1786739822 user: wilkason
00:25 • New ticket [599788ffff] error in catch causing tclsh segfault. artifact: 3393d4ca68 user: wilkason

error in (array element script) causing tclsh segfault

Closed / Fixed599788ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2002-08-25 00:25:31
The crash originates in generic\tclExecute.c 
GetSrcInfoForPc at line 4574 
at CVS head on 8/24/02 The code is below, what 
happens is the call to 
macro TclGetInt4AtPtr with value 0xFF returns a huge 
negative number thus 
later causing offsets to break and eventually a crash in 
tclBasic.c 
Tcl_LogCommandInfo. The error was introduced 
sometime after 8.4b2. The offending 
source code is below:

if ((unsigned int) (*srcDeltaNext) == 
(unsigned int) 0xFF) {
    srcDeltaNext++;
    delta = TclGetInt4AtPtr(srcDeltaNext);    // 
<- bad juju returned
    srcDeltaNext += 4;
} else {
    delta = TclGetInt1AtPtr(srcDeltaNext);
    srcDeltaNext++;
}
}

Source in the attached file to see it.
wilkasonplain2002-08-25 07:25:31
File Added - 29738: test.tcl
wilkason Ticket [599788ffff]: 2 changes [History diff]2002-08-25 07:29:10
msoferplain2002-08-25 19:20:22
Logged In: YES 
user_id=148712

I get the segfault also in 8.4b2, but not in 8.4b1. It
figure, since little has been changed that could trigger
this since 8.4b2.
The segfault is also triggered by 
   set a([x])
- assuming no command 'x' is defined.


The code section mentioned has never been touched since 8.0.
msoferplain2002-08-25 20:56:03
Logged In: YES 
user_id=148712

TclLogCommandInfo is getting wrong input: 'script' and
'command' do point to strings with the correct contents, but
'command' is not a substring of 'script' as it should. See
the debug session below:

(gdb) r
Starting program: /CVS/tcl_SF_clean/unix/tclsh 
% set a([set x])

Program received signal SIGSEGV, Segmentation fault.
0x0806d426 in Tcl_LogCommandInfo (interp=0x81070e0,
script=0x810f9a0 "set a([set x])\n", 
    command=0xbfffe88e "set x]\"", length=5) at
./../generic/tclBasic.c:3243
3243            if (*p == '\n') {
(gdb) p p
$1 = 0x8130000 <Address 0x8130000 out of bounds>
msoferplain2002-08-26 00:39:29
Logged In: YES 
user_id=148712

Found the problem; it is caused by the CONSTification of the
parser/compiler. In tclCompCmds.c, line 3267, we are
compiling the tokens from a *copy* of the relevant source
string, thus getting pointers to said copy instead of to the
original. 
Diagnostic done, fix not yet ...

The simplest script to show the bug is
    set a([error])
when it is compiled (ie, typed at the tclsh prompt or in a
proc body if sourced).
msoferplain2002-08-27 00:39:49
Logged In: YES 
user_id=148712

Fixed by copying the tokens instead of copying/reparsing the
source string.
Log in (anonymous is fine) to add a comment.

Attachments: