Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: debaa2f082285b5567a799e8e8aea004198af8f09219dec1c2d075a9c1cf3cbe
Ticket: 183a1adcc07cddc6b55d0fc636c392ea461f1ccc
Buffer overflow in Tcl_UtfToExternal
User & Date: apnadkarni on 2023-03-12 17:05:18
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-markdown"
  4. comment changed to:
    When passed a one byte buffer, Tcl_UtfToExternal writes the null terminator beyond the buffer. In the TIP-656 branch,
    
    ```
    % testencoding Tcl_UtfToExternal unicode A {start end} {} 1
    Tcl_ExternalToUtf wrote past output buffer
    ```
    
    The function is identical to the core-8-branch so the bug should appear [there](https://core.tcl-lang.org/tcl/file?ci=3a7e4c1c38532805&name=generic/tclEncoding.c&ln=1588-1592) as well. 8.6 has slightly different [code](https://core.tcl-lang.org/tcl/file?ci=0336bcea26d73927&name=generic/tclEncoding.c&ln=1418-1425) but has same issue.
    
    Basically, the encoding's nul length is subtracted from the passed destination buffer length without checking for a negative result. Subsequently the nul bytes (2 in this case) are written to the buffer. 
    
    Although a single byte buffer might seem unlikely, the possibility exists in streaming operation where caller might repeatedly call the function using the same (updated) buffer until `TCL_CONVERT_NOSPACE` is returned and there happens to be just one free byte in the buffer.
    
  5. foundin changed to: "8.6"
  6. is_private changed to: "0"
  7. login: "apnadkarni"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "9546e9877f1a8899e25a89082561ee694e7fb402"
  10. resolution changed to: "None"
  11. severity changed to: "Critical"
  12. status changed to: "Open"
  13. submitter changed to: "apnadkarni"
  14. subsystem changed to: "11. Conversions from String"
  15. title changed to: "Buffer overflow in Tcl_UtfToExternal"
  16. type changed to: "Bug"