Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-07-14
10:20 • Closed ticket [3366265fff]: buffer overflow due to TclObjInterpProc flaw plu... artifact: b868330926 user: dgp
09:43 • Ticket [3366265fff]: 4 changes artifact: d3d0b87019 user: dgp
00:54 • Ticket [3366265fff]: 4 changes artifact: 7288e3e987 user: dgp
00:44 • Ticket [3366265fff]: 4 changes artifact: b83fdabd8c user: dgp
2011-07-13
17:41 • New ticket [3366265fff]. artifact: d1f4e33e66 user: dgp

buffer overflow due to TclObjInterpProc flaw

Closed / Fixed3366265fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2011-07-13 17:41:36
New test in a --enable-symbols=all build :

test proc-3.7 {TclObjInterpProc, wrong num args} {
    proc {} {x} {}
    list [catch {{}} msg] $msg
} {1 {wrong # args: should be "{} x"}}

produces this memory validation failure:

Test file error: hi guard byte 0 is 0x0
total mallocs                  35586
total frees                    29673
current packets allocated       5913
current bytes allocated       510073
maximum packets allocated       6380
maximum bytes allocated       576498
high guard failed at 164b5498, /home/dgp/fossil/tcl8.4/unix/../generic/tclProc.c 1161
2 bytes allocated at (/home/dgp/fossil/tcl8.4/unix/../generic/tclProc.c 1158)
Memory validation failure

Thanks to "jboning" on the chat for reporting.
dgpplain2011-07-14 00:44:57
Problem is that line 1158 of tclProc.c allocates a buffer
of only 2 bytes to hold the formatted value of the command
name "{}", forgetting that Tcl_ConvertCountedElement() needs
one additional byte in which to write the terminating NUL.
dgpplain2011-07-14 00:54:31
Fix committed for 8.4.20.
dgpplain2011-07-14 09:43:29
On the 8.5 branch, the bug's moved over to
Tcl_WrongNumArgs().  It's also been defanged
because the TclStackAlloc() allocator is now used,
and that allocator doesn't have a memory debugger
to trip, and in the failing case of an empty proc name,
the TclStackAlloc() practice of allocating by pointer-sized
words automatically provides enough extra overhead
space to not permit a failure.

Nevertheless, imagining some future maintenance
programmer converting from TclStackAlloc() back
to ckalloc(), it's best to get the requested size correct.
dgpplain2011-07-14 10:20:09
allow_comments - 1

fix merged to trunk as well.
Log in (anonymous is fine) to add a comment.