Overview
| Artifact ID: | 2bba8435d878ffc8060c701b4a58611b079f140842db599c0263162639628a4e |
|---|---|
| Ticket: | 7f8a3d981843fe53d6a6a6bd659f3a3440bd15e3
signed integer overflow in tclExecute.c |
| User & Date: | chrstphrchvz on 2022-02-15 22:46:40 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed 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.) - foundin changed to: "core-8-6-branch"
- is_private changed to: "0"
- login: "chrstphrchvz"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "chrstphrchvz"
- subsystem changed to: "48. Number Handling"
- title changed to: "signed integer overflow in tclExecute.c"
- type changed to: "Patch"