Artifacts Associated With Ticket ab123cfd3d
Ticket change [663475dd46] (rid 213937) by chrstphrchvz on 2023-04-27 04:12:21:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
Triggered by scan-13.9. <tt>-fsanitize=signed-integer-overflow</tt> error for 32-bit <tt>long</tt>: <blockquote><pre> generic/tclScan.c:321:15: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'long int' </pre></blockquote>
- foundin initialized to: "trunk"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- private_contact initialized to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "18. Commands M-Z"
- title initialized to: "ValidateFormat(): signed integer overflow"
- type initialized to: "Bug"
Ticket change [2adb0fc3d3] (rid 213943) by chrstphrchvz on 2023-04-27 07:16:01:
- foundin changed to: "core-8-6-branch"
- icomment:
This issue as well as [d4ede611a7a7] are present on 8.6 and 8.7, as revealed by running the contents of scan-13.9 (<tt>scan abc {%2147483648$s}</tt>): <blockquote><pre> tcl86/generic/tclScan.c:318:15: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int' tcl86/generic/tclScan.c:495:14: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' tcl86/generic/tclScan.c:684:12: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'long int' tcl86/generic/tclScan.c:840:16: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' tcl86/generic/tclScan.c:840:7: runtime error: applying non-zero offset 4294967292 to null pointer AddressSanitizer:DEADLYSIGNAL ================================================================= ==14995==ERROR: AddressSanitizer: SEGV on unknown address 0x3fffffff (pc 0xb638796b bp 0xbf88eed8 sp 0xbf88ecd0 T0) ==14995==The signal is caused by a READ memory access. #0 0xb638796b in Tcl_ScanObjCmd tcl86/generic/tclScan.c:840 #1 0xb5a80a1c in Dispatch tcl86/generic/tclBasic.c:4467 #2 0xb5a80e22 in TclNRRunCallbacks tcl86/generic/tclBasic.c:4503 #3 0xb5a7dbc3 in Tcl_EvalObjv tcl86/generic/tclBasic.c:4226 #4 0xb5a8c904 in TclEvalEx tcl86/generic/tclBasic.c:5372 #5 0xb6267bdb in Tcl_FSEvalFileEx tcl86/generic/tclIOUtil.c:1824 #6 0xb62a34b2 in Tcl_MainEx tcl86/generic/tclMain.c:403 #7 0x509523 in main tcl86/unix/tclAppInit.c:91 #8 0xb4a25128 (/usr/lib/libc.so.6+0x1f128) #9 0xb4a251fc in __libc_start_main (/usr/lib/libc.so.6+0x1f1fc) #10 0x5093ea in _start (tcl86/unix/tcltest+0x443ea) AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV tcl86/generic/tclScan.c:840 in Tcl_ScanObjCmd ==14995==ABORTING </pre></blockquote> - login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
Ticket change [dbebd4825d] (rid 213944) by chrstphrchvz on 2023-04-27 07:20:31:
- comment changed to:
Triggered by scan-13.9 on 9.0. <tt>-fsanitize=signed-integer-overflow</tt> error for 32-bit <tt>long</tt>: <blockquote><pre> generic/tclScan.c:321:15: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'long int' </pre></blockquote>
- login: "chrstphrchvz"
- mimetype: "text/plain"
- comment changed to:
Ticket change [7cbc61e3de] (rid 213965) by apnadkarni on 2023-04-27 14:29:12:
- icomment:
Fix seems simple but I'd like to reproduce the issue first so I can verify. Could you let me know the configure command for the build? I get a "undefined reference to __ubsan_handle_add_overflow" link error. Sorry, not familiar with address sanitizer.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [8943499afd] (rid 214104) by chrstphrchvz on 2023-04-29 19:21:22:
- icomment:
That error sounds like <tt>-fsanitize=undefined</tt> might need to be added to <tt>LDFLAGS</tt>.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [1053bc9742] (rid 214176) by apnadkarni on 2023-05-01 06:52:35:
- icomment: "Proposed fix in [bug-ab123cfd3d]."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
Ticket change [619b3e737d] (rid 214183) by apnadkarni on 2023-05-01 10:39:11:
- closedate changed to: "2460065.94387791"
- closer changed to: "apnadkarni"
- icomment: "Fixed in [3da8d2069c]. Verified on Ubuntu 20."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Add attachment "ab123cfd3d02-8.6.diff" [208eca8968] (rid 214276) by chrstphrchvz on 2023-05-02 10:37:50.
Ticket change [11dc381be8] (rid 214277) by chrstphrchvz on 2023-05-02 10:39:56:
- closer changed to: "nobody"
- icomment:
Reopening because I would still like for this to be fixed in 8.6 and 8.7. See attached patch for core-8-6-branch. (For core-8-branch, [3da8d2069c69] can be applied directly along with copying over scan-13.9. But for 8.6, I am not sure anyone would want to bring back compat/strtoull.c, which was removed in 2007.) I agree that storing the result of <tt>strtoul()</tt> in a <tt>signed int</tt> caused several issues, including large arguments being erroneously accepted due to truncation from 64-bit to 32-bit, the comment about <tt>value</tt>/<tt>longval</tt> being “guaranteed to be > 0” not being true, and the signed integer overflow and the scan-13.9 crash. To clarify, the overflow is detected by UBSan (UndefinedBehaviorSanitizer) rather than ASan (AddressSanitizer); consider revising the check-in message for [787712b4c733] and [3da8d2069c69]. ASan, like Valgrind, is really only useful with <tt>PURIFY</tt> defined. I usually configure with both UBSan and ASan enabled, using <tt>CFLAGS='-DPURIFY -fsanitize=address -fsanitize=undefined' LDFLAGS='-fsanitize=address' ./configure --enable-symbols …</tt> ; I haven’t had to specify <tt>-fsanitize=undefined</tt> in <tt>LDFLAGS</tt> so far. I also apply a workaround for [ac874937c5]. I then usually run with <tt>ASAN_OPTIONS=allocator_may_return_null=1:detect_leaks=0:malloc_context_size=99</tt>.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "None"
- status changed to: "Open"
Ticket change [7a70a5c4ff] (rid 214280) by apnadkarni on 2023-05-02 11:02:56:
- icomment:
Fixed the commit message. As for 8.6, 8.7, that would have to wait I'm afraid just as a matter of priority.
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [e7daa0499a] (rid 214281) by apnadkarni on 2023-05-02 11:04:46:
- icomment:
(Not saying it's unimportant but my focus is on other areas for the moment)
- login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [5c4f1bcc7b] (rid 214350) by apnadkarni on 2023-05-02 17:59:22:
- closedate changed to: "2460067.24956242"
- closer changed to: "apnadkarni"
- icomment:
Fixed in all three branches. Serendipity that one of the other bugs I was looking at affected 8.6 as well. Tested with `../configure CFLAGS="-m32 -fsanitize=signed-integer-overflow" LDFLAGS="-lubsan"` (and patched dltest Makefile) but please test and re-open if issue persists. Thanks for the patch.
- login: "apnadkarni"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [a5f47b7fc8] (rid 214352) by chrstphrchvz on 2023-05-02 18:22:18:
- closedate changed to: "2460067.26549039"
- closer changed to: "chrstphrchvz"
- icomment:
Be aware that UBSan says to avoid <tt>-lubsan</tt>; using gcc or clang as the linker with <tt>-fsanitize=undefned</tt> should be enough.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"