Skip to content
Tcl Source Code History Of Ticket 24b918147808e33e
Login

History Of Ticket 24b918147808e33e

Artifacts Associated With Ticket 24b918147808e33e

  1. Ticket change [ecdbee36b1] (rid 194159) by rupprecht on 2021-05-03 18:40:04:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      tl;dr this patch fixes a lifetime bug detected in trunk versions of Clang:
      
      $ git diff generic/tclIO.c
      diff --git a/generic/tclIO.c b/generic/tclIO.c
      index dc028b522..a23fff80f 100644
      --- a/generic/tclIO.c
      +++ b/generic/tclIO.c
      @@ -4296,9 +4296,10 @@ Write(
              nextNewLine = (char *)memchr(src, '\n', srcLen);
           }
       
      +    char safe[BUFFER_PADDING];
           while (srcLen + saved + endEncoding > 0) {
              ChannelBuffer *bufPtr;
      -       char *dst, safe[BUFFER_PADDING];
      +       char *dst;
              int result, srcRead, dstLen, dstWrote, srcLimit = srcLen;
       
              if (nextNewLine) {
      
      Longer summary: a recent update to clang improves optimizations related to memcpy:
      https://github.com/llvm/llvm-project/commit/f5446b769a7929806f72256fccd4826d66502e59.
      
      When we upgraded to a version of clang that includes this optimization, we
      encountered a build error from a step that was consuming the output of a tcl/tk
      script, and found that the tcl script was producing junk output. Upon further
      inspection, this is because the tcl interpreter built by clang was entirely
      optimizing away the "safe" buffer in the patch above. This appears to be valid,
      as the lifetime of the "safe" buffer ends at the closing of the for loop, and
      is not guaranteed to be preserved on the next loop iteration. Moving the buffer
      outside of the for loop will preserve the "safe" buffer for the necessary
      lifetime.
      
    5. foundin initialized to: "trunk"
    6. is_private initialized to: "0"
    7. login: "rupprecht"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "3ebba1c26822dc664ef602a582d54ffaec6356e8"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "rupprecht"
    14. subsystem initialized to: "53. Configuration and Build Tools"
    15. title initialized to: "Fix unsafe buffer lifetime"
    16. type initialized to: "Patch"
  2. Ticket change [01b85557b9] (rid 194171) by jan.nijtmans on 2021-05-03 19:55:07:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459338.32995333"
    3. closer changed to: "jan.nijtmans"
    4. foundin changed to: "8.5"
    5. icomment:
      Well, this but can be traced back to Tcl 8.5 (and probably much further back in history). Thanks for this detailed explanation and for the fix.
      
      Fixed now in all active branches (8.5 and up)
      
    6. login: "jan.nijtmans"
    7. mimetype: "text/x-fossil-wiki"
    8. resolution changed to: "Fixed"
    9. status changed to: "Closed"
    10. subsystem changed to: "25. Channel System"
  3. Ticket change [f66017aece] (rid 194208) by dkf on 2021-05-04 07:31:13:

    1. closedate changed to: "2459338.81334631"
    2. closer changed to: "dkf"
    3. icomment: "Good catch; that code was wrong."
    4. login: "dkf"
    5. mimetype: "text/x-fossil-wiki"