Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c605a2269eb376353b9209e66fda2613ac93369192762c3833ee657cbc8f9870
Ticket: bca10e3790f6c2962c0302d6f62ef9c6fadf5752
Undefined behavior in ResultAdd()
User & Date: chrstphrchvz on 2021-12-28 23:11:04
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    <tt>ResultAdd()</tt> (generic/tclIOGT.c) is sometimes called with <tt>size_t toWrite = 0</tt> and a <tt>ResultBuffer *r</tt> such that <tt>r-&gt;buf = NULL</tt>. In this case, <tt>r-&gt;used = 0</tt> and <tt>r-&gt;allocated = 0</tt>, so <tt>ResultAdd()</tt> will not allocate a new buffer. This leads to <tt>NULL + 0</tt> pointer arithmetic when doing <tt>r-&gt;buf + r-&gt;used</tt>, and calling <tt>memcpy()</tt> with <tt>NULL</tt> as the destination (even though the copy length <tt>toWrite</tt> is 0), both of which are undefined behavior. [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks|UBSan <tt>-fsanitize=nonnull-attribute</tt> (GCC) and <tt>-fsanitize=pointer-overflow</tt>] errors during test iogt-1.1:
    
    <pre>
    <span style="font-weight:bold">tcl/generic/tclIOGT.c:1445:5: <span style="color:red">runtime error:</span> null pointer passed as argument 1, which is declared to never be null
    tcl/generic/tclIOGT.c:1445:12: <span style="color:red">runtime error:</span> applying zero offset to null pointer</span>
    </pre>
    
  5. foundin changed to: "8.6.12"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "chrstphrchvz"
  13. subsystem changed to: "52. Portability Support"
  14. title changed to: "Undefined behavior in ResultAdd()"
  15. type changed to: "Bug"