Skip to content
Tcl Source Code History Of Ticket 7f8a3d9818
Login

History Of Ticket 7f8a3d9818

Artifacts Associated With Ticket 7f8a3d9818

  1. Ticket change [2bba8435d8] (rid 198144) by chrstphrchvz on 2022-02-15 22:46:40:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      tclExecute.c tries to check for signed integer overflow after the fact using the <tt>Overflowing()</tt> macro, but does not avoid undefined behavior from occuring in the expressions which overflow; casting operands to unsigned types avoids this (see attached patch).
      
      Below are example triggers for every instance I found and corresponding UBSan (<tt>-fsanitize=signed-integer-overflow</tt>) errors.
      
      For 32-bit <tt>long</tt> and 64-bit <tt>long long</tt>:
      
      <blockquote><pre>
      % set a 0x7fffffff; incr a 1
      <span style="font-weight:bold">tcl/generic/tclExecute.c:1901:7:<span style="color:red"> runtime error: </span>signed integer overflow: 2147483647 + 1 cannot be represented in type 'long int'</span>
      2147483648
      % proc e3932 {} {global x; set x 0x7fffffff; incr x 1}
      % e3932
      <span style="font-weight:bold">tcl/generic/tclExecute.c:3932:12:<span style="color:red"> runtime error: </span>signed integer overflow: 2147483647 + 1 cannot be represented in type 'long int'</span>
      % proc e3980_1952 {} {global x; set x 0x7fffffffffffffff; incr x 1}
      % e3980_1952
      <span style="font-weight:bold">tcl/generic/tclExecute.c:3980:11:<span style="color:red"> runtime error: </span>signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long long int'</span>
      <span style="font-weight:bold">tcl/generic/tclExecute.c:1952:6:<span style="color:red"> runtime error: </span>signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long long int'</span>
      </pre></blockquote>
      
      For 64-bit <tt>long</tt>:
      
      <blockquote><pre>
      % proc e6509 {} {return [expr {0x7fffffffffffffff+1}]}
      % e6509
      <span style="font-weight:bold">tcl/generic/tclExecute.c:6509:16:<span style="color:red"> runtime error: </span>signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long'</span>
      <span style="font-weight:bold">tcl/generic/tclExecute.c:9149:16:<span style="color:red"> runtime error: </span>signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long'</span>
      9223372036854775808
      % proc e6524 {} {return [expr {-0x7fffffffffffffff-2}]}
      % e6524
      <span style="font-weight:bold">tcl/generic/tclExecute.c:6524:16:<span style="color:red"> runtime error: </span>signed integer overflow: -9223372036854775807 - 2 cannot be represented in type 'long'</span>
      <span style="font-weight:bold">tcl/generic/tclExecute.c:9165:16:<span style="color:red"> runtime error: </span>signed integer overflow: -9223372036854775807 - 2 cannot be represented in type 'long'</span>
      -9223372036854775809
      </pre></blockquote>
      
      (There is more signed integer overflow in tclExecute.c which I have yet to report/suggest fixes for.)
      
    5. foundin initialized to: "core-8-6-branch"
    6. is_private initialized to: "0"
    7. login: "chrstphrchvz"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "chrstphrchvz"
    13. subsystem initialized to: "48. Number Handling"
    14. title initialized to: "signed integer overflow in tclExecute.c"
    15. type initialized to: "Patch"
  2. Add attachment "tclExecute-sif.diff" [2358d417b9] (rid 198145) by chrstphrchvz on 2022-02-15 22:47:29.

  3. Ticket change [86bf264502] (rid 198183) by jan.nijtmans on 2022-02-16 16:22:06:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459627.18201394"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Fixed [8524520e5b055b74|here]
      
      Thanks for the report!
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"