Skip to content
Tcl Source Code View Ticket
Login

View Ticket

List command can used to read beyond bounds of input

Closed / Fixed35a8f1c04a9c1610b250f97b9361c35fadc583deCreated 8 years agoUpdated 8 years ago
Descriptionwiki2018-11-08 21:47:57
I cannot say I entirely know what is going wrong, only that I know it's incorrect.

Run the following in a Tcl shell:

puts "[list {#"""}]"

It seems like the Tcl interpreter is mishandling the literal #""" inside the curly braces which results in extra data to be appended to the output. I've found through experimentation that the string must start with a # and the number of quotes (must be greater than two) is proportional to the amount of additional data which follows the output.

In trials it was common for null characters to be printed, which depending on your shell might not show up, so you may need to convert the output to hex.

Here are some examples:

 
% info tclversion
8.5
% list {#""""""""""""""""""""""""""""""""""""""""""""""""""""""}
{#""""""""""""""""""""""""""""""""""""""""""""""""""""""}  auto_index(::tcl::tm::roots) [list source [file joi
% list {#""""""""""""""""""""""""""""""""""""""""""""""""""""""}
{#""""""""""""""""""""""""""""""""""""""""""""""""""""""} tïtcl]]

% list {#""""""""""""""""""""""""""""""""""""""""""""""""""""""} {#""""""""""""""""""""""""""""""""""""""""""""""""""""""} ïHÕ Ðï % list {#""""""""""""""""""""""""""""""""""""""""""""""""""""""} {#""""""""""""""""""""""""""""""""""""""""""""""""""""""} ï

Referenced by5
  • 848f2df503[35a8f1c04a] Fix bad lengths when creating string rep of some lists. check-in2018-11-13 21:10:33
  • 0b52c3617e[35a8f1c04a] Fix bad lengths when creating string rep of some lists. check-in2018-11-09 16:42:37
  • b2575c74bc[35a8f1c04a] Fix bad lengths when creating string rep of some lists. check-in2018-11-09 16:00:57
  • 2ec58720e9closes [35a8f1c04a]: minimalist fix - beware of discrepancy between TclScanElement and TclConvertElement (prefer braces considering TCL_DONT_QUOTE_HASH in case of first list element) check-in2018-11-09 14:19:08
  • d76fb9091btest case to cover bug [35a8f1c04a] check-in2018-11-09 14:13:15
dgpplain2018-11-09 00:50:48
Well spotted. See this confirmation:

% string length [list {#"}]
4
% string length [list {#""}]
6
% string length [list {#"""}]
8

Contrast with:

% string length [list {#x}]
4
% string length [list {#xx}]
5
% string length [list {#xxx}]
6
sebreswiki2018-11-09 14:23:07

Nice one... Found the bug (a discrepancy between TclScanElement and TclConvertElement if not TCL_DONT_QUOTE_HASH).

Fixed in [2ec58720e9] now, branch bug-35a8f1c04a.

Log in (anonymous is fine) to add a comment.