script crashes Tcl 8.4.X on Solaris (verified by J. Hobbs)
Closed873294ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2004-01-08 20:25:24
# this script crashes under Tcl 8.4.X (all versions)
# 32 bit compile under gcc 3.3.1
# on:
# SunOS ldas-suntest2 5.9 Generic_112233-07 sun4u sparc
SUNW,Sun-Fire-280R Solaris
# and possibly others... but does not crash under Tcl
<= 8.3.5
proc solaris { file } {
if { [ catch {
set now [ clock seconds ]
set usr [ file attributes $file -owner ]
set fid [ open $file r ]
fconfigure $fid -encoding binary -translation
binary
set numinfo [ read $fid 88 ]
set fname [ read $fid 16 ]
set args [ read $fid 80 ]
set more [ read $fid 16 ]
::close $fid
;## the meaty part
binary scan $numinfo IIIIIIIIIIIIIIISSI \
. . pid ppid . . ruser . . . . vsz rsz . .
pcpu pmem stt
;## try to make sense out of pr_wstat
binary scan $more I state
if { $state == 0 } {
set state R
} else {
set state Z
}
regsub -all \x00 $fname {} fname
regsub -all \x00 $args {} args
set etime [ expr { $now - $stt } ]
if { ! [ string equal 0 $pmem ] } {
set pmem [ expr { $pmem / 327.67 } ]
set pmem [ format %.2f $pmem ]
}
if { ! [ string equal 0 $pcpu ] } {
set pcpu [ expr { $pcpu / 327.67 } ]
set pcpu [ format %.2f $pcpu ]
}
} err ] } {
return -code error $err
}
puts stderr "$pid $state $usr $vsz $rsz $pcpu
$pmem $etime $fname $args"
}
foreach file [ glob /proc/*/psinfo ] {
puts stderr $file
solaris $file
}
kennykbplain2004-01-09 03:52:48
Logged In: YES
user_id=99768
Stack trace:
#0 0xff2c2a80 in Tcl_DuplicateObj (objPtr=0x2bfe0)
at ./../generic/tclObj.c:741
#1 0xff2e9e2c in TclPtrSetVar (interp=0x23e50,
varPtr=0x2ac00, arrayPtr=0x0,
part1=0x21f10 "::errorInfo", part2=0x0,
newValuePtr=0x2c6d0, flags=5)
at ./../generic/tclVar.c:1645
#2 0xff2e99ac in Tcl_ObjSetVar2 (interp=0x23e50,
part1Ptr=0x23d58,
part2Ptr=0x0, newValuePtr=0x2c6d0, flags=5) at
./../generic/tclVar.c:1511
#3 0xff237b98 in Tcl_AddObjErrorInfo (interp=0x23e50,
message=0xffbee280 "\n while executing\n\"fconfigure
$fid -encoding binary -translation binary\"", length=-1) at
./../generic/tclBasic.c:5204
#4 0xff234af0 in Tcl_LogCommandInfo (interp=0x23e50,
script=0x2e4a0 "\n \n if { [ catch {\n \n
set now [ clock seconds ]\n set usr [ file
attributes $file -owner ]\n \n set fid [ open
$file r ]\n \n fconfigure $fid -encodi"...,
command=0x2e551 "fconfigure $fid -encoding binary
-translation binary\n \n set numinfo [ read
$fid 88 ]\n set fname [ read $fid 16 ]\n set
args [ read $fid 80 ]\n set more [ read "...,
length=52) at ./../generic/tclBasic.c:3319
#5 0xff286fdc in TclExecuteByteCode (interp=0x23e50,
codePtr=0x35f08)
at ./../generic/tclExecute.c:4041
#6 0xff2795a4 in TclCompEvalObj (interp=0x23e50,
objPtr=0x2c7d8)
at ./../generic/tclExecute.c:980
#7 0xff2d468c in TclObjInterpProc (clientData=0x2b178,
interp=0x23e50,
objc=2, objv=0x260ac) at ./../generic/tclProc.c:1082
#8 0xff234494 in TclEvalObjvInternal (interp=0x23e50,
objc=2, objv=0x260ac,
command=0x0, length=0, flags=0) at
./../generic/tclBasic.c:3085
#9 0xff27abb8 in TclExecuteByteCode (interp=0x23e50,
codePtr=0x2e208)
at ./../generic/tclExecute.c:1401
#10 0xff2795a4 in TclCompEvalObj (interp=0x23e50,
objPtr=0x2c760)
at ./../generic/tclExecute.c:980
#11 0xff235cd4 in Tcl_EvalObjEx (interp=0x23e50,
objPtr=0x2c760, flags=0)
at ./../generic/tclBasic.c:4005
#12 0xff241a18 in Tcl_ForeachObjCmd (dummy=0x0,
interp=0x23e50, objc=4,
objv=0xffbef0d0) at ./../generic/tclCmdAH.c:1860
#13 0xff234494 in TclEvalObjvInternal (interp=0x23e50, objc=4,
objv=0xffbef0d0,
command=0x39d90 "foreach file [ glob /proc/*/psinfo ]
{\n puts stderr $file\n solaris $file\n}\n",
length=89, flags=0)
at ./../generic/tclBasic.c:3085
#14 0xff2353d8 in Tcl_EvalEx (interp=0x23e50,
script=0x39750 "# this script crashes under Tcl 8.4.X
(all versions)\n# 32 bit compile under gcc 3.3.1\n# on:\n#
SunOS ldas-suntest2 5.9 Generic_112233-07 sun4u sparc
SUNW,Sun-Fire-280R Solaris\n# and possibly others... "...,
numBytes=1689, flags=0) at ./../generic/tclBasic.c:3674
#15 0xff2aeea4 in Tcl_FSEvalFile (interp=0x23e50,
pathPtr=0x23770)
at ./../generic/tclIOUtil.c:1524
#16 0xff2bab0c in Tcl_Main (argc=1, argv=0xffbef738,
appInitProc=0x10950 <Tcl_AppInit>) at
./../generic/tclMain.c:292
#17 0x1093c in main (argc=2, argv=0xffbef734) at
./../unix/tclAppInit.c:90
kennykbplain2004-01-09 06:32:47
Logged In: YES user_id=99768 Further notes for whoever is looking at this. The code gets to the point where it's pushing the value of 'pmem' onto the stack in the [puts stderr] at line 53. At that point the value's refcount is zero and it is the second object on tclFreeObjList.
dkf Ticket [873294ffff]: 1 change
[History diff]2004-01-09 17:01:44
kennykbplain2004-01-10 01:35:06
Logged In: YES user_id=99768 Simpler example: binary scan \000\001\000 a a b; puts $b The first byte is scanned into 'a' - and stored in the scan cache. The reference in the scan cache isn't counted in the ref count. The second byte is stored into 'a' as well, decrementing the refcount of the first obj and freeing it. The third byte pulls the first obj (now a free object) back from the scan cache and stores it in b. Now the free obj list is corrupt. The fix is to do refcounting around Tcl_SetHashValue - and then decrement all the ref counts prior to each of the calls to Tcl_DeleteHashTable (replace them all with a call to a static fn that does it, I guess). A temporary work-around would be to make sure that no variable name is repeated in [binary scan]. Using the @ format group might be helpful.
hobbsplain2004-01-10 02:12:40
Logged In: YES user_id=72656 This was already fixed on 12-02-2003 by DKF (with additional patch on 12-17 by DAS. This is post-8.4.5, but will be in any future release.
kennykbplain2004-01-10 02:15:41
Logged In: YES user_id=99768 Duplicate of bug 851747, fixed last month. Fix will be in 8.4.6 and 8.5
Log in (anonymous is fine) to add a comment.