Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 01c37693a746f7578c165778e0254d4a2e647cecf7dc5b5a9427402e92a25f09
Ticket: 3837178c2548d802c3946cc0918fedfcf6699e57
Tcl_DStringSetObjLength(): TIP 660 out-of-bounds write
User & Date: chrstphrchvz on 2023-05-07 02:39:51
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    <tt>Tcl_DStringSetLength()</tt> previously treated negative <tt>length</tt> as 0 (an undocumented behavior some found concerning: [2613599]). The check for negative <tt>length</tt> was removed when TIP 494 made <tt>length</tt> unsigned (originally in [6d05288cf774], partially restored in [c0829cbacc86], and removed again in [84a5f246b739]). TIP 660 changed <tt>length</tt> back to signed without restoring the check for negative <tt>length</tt>, which at a minimum allows writing <tt>'\0'</tt> out-of-bounds.
    
    Please consider adding the following (or similar) to tests/dstring.test in all maintained branches, regardless of what is done about this ticket:
    
    <blockquote><pre>
    test dstring-4.3 {truncation} -constraints testdstring -setup {
        testdstring free
    } -body {
        testdstring append "xwvut" -1
        # Pass a negative length to Tcl_DStringSetLength();
        # if not caught, causing '\0' to be written out-of-bounds,
        # try corrupting dsPtr-&gt;length which begins
        # 2*sizeof(Tcl_Size) bytes before dsPtr->staticSpace[],
        # so that the result is -256 (on little endian systems)
        # rather than e.g. -8 or -16.
        # (sizeof(Tcl_Size) does not seem to be available via Tcl,
        # so assume sizeof(Tcl_Size) == sizeof(void*) for Tcl 9.)
        testdstring trunc [expr {-2*([package vsatisfies $tcl_version 9.0-]
    	? $tcl_platform(pointerSize) : 4)}]
        list [testdstring get] [testdstring length]
    } -cleanup {
        testdstring free
    } -result {{} 0}
    </pre></blockquote>
    
  5. foundin changed to: "trunk"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "chrstphrchvz"
  14. subsystem changed to: "11. Conversions from String"
  15. title changed to:
    Tcl_DStringSetObjLength(): TIP 660 out-of-bounds write
    
  16. type changed to: "Bug"