Artifacts Associated With Ticket 7f8a3d9818
Ticket change [2bba8435d8] (rid 198144) by chrstphrchvz on 2022-02-15 22:46:40:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- 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.) - foundin initialized to: "core-8-6-branch"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "48. Number Handling"
- title initialized to: "signed integer overflow in tclExecute.c"
- type initialized to: "Patch"
Add attachment "tclExecute-sif.diff" [2358d417b9] (rid 198145) by chrstphrchvz on 2022-02-15 22:47:29.
Ticket change [86bf264502] (rid 198183) by jan.nijtmans on 2022-02-16 16:22:06:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459627.18201394"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed [8524520e5b055b74|here] Thanks for the report!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"