Artifacts Associated With Ticket 983f933f11
Ticket change [449953ad35] (rid 249675) by chrstphrchvz on 2025-12-20 02:07:37:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
Example command (based on test source-7.4) and UBSan error: <pre> % source -encoding bogus /dev/null tcl91/generic/tclEncoding.c:2477:18: runtime error: applying zero offset to null pointer tcl91/generic/tclEncoding.c:1236:6: runtime error: applying zero offset to null pointer unknown encoding "bogus" </pre> As with [c9e68eb6], this sort of problem is not because of functions where the undefined behavior occurs, but rather because of whatever is passing <tt>NULL</tt> to those functions. LLDB backtrace for first error: <pre> * frame #0: 0x0000000100557920 libclang_rt.asan_osx_dynamic.dylib`__ubsan_on_report frame #1: 0x0000000100552000 libclang_rt.asan_osx_dynamic.dylib`__ubsan::Diag::~Diag() + 240 frame #2: 0x000000010055707a libclang_rt.asan_osx_dynamic.dylib`handlePointerOverflowImpl(__ubsan::PointerOverflowData*, unsigned long, unsigned long, __ubsan::ReportOptions) + 1066 frame #3: 0x0000000100556c46 libclang_rt.asan_osx_dynamic.dylib`__ubsan_handle_pointer_overflow + 54 frame #4: 0x0000000101a2fa27 libtcl9.1.dylib`UtfToUtfProc(clientData=0x0000000000000200, src=0x0000000000000000, srcLen=0, flags=16778243, statePtr=0x00007ff7bfefbb20, dst="", dstLen=199, srcReadPtr=0x00007ff7bfefbb40, dstWrotePtr=0x00007ff7bfefbb50, dstCharsPtr=0x00007ff7bfefbb60) at tclEncoding.c:2477:18 frame #5: 0x0000000101a3e534 libtcl9.1.dylib`Tcl_ExternalToUtfDStringEx(interp=0x0000000000000000, encoding=0x0000607000000fe0, src=0x0000000000000000, srcLen=0, flags=16778243, dstPtr=0x00007ff7bfefbf20, errorLocPtr=0x0000000000000000) at tclEncoding.c:1231:11 frame #6: 0x0000000101a3dce7 libtcl9.1.dylib`Tcl_ExternalToUtfDString(encoding=0x0000000000000000, src=0x0000000000000000, srcLen=0, dstPtr=0x00007ff7bfefbf20) at tclEncoding.c:1132:5 frame #7: 0x0000000101f83f7b libtcl9.1.dylib`TclGetProcessGlobalValue(pgvPtr=0x000000010277f240) at tclUtil.c:4258:2 frame #8: 0x0000000101a45ab0 libtcl9.1.dylib`OpenEncodingFileChannel(interp=0x0000619000003780, name="bogus") at tclEncoding.c:1768:20 frame #9: 0x0000000101a3a774 libtcl9.1.dylib`LoadEncodingFile(interp=0x0000619000003780, name="bogus") at tclEncoding.c:1884:12 frame #10: 0x0000000101a2bc33 libtcl9.1.dylib`Tcl_GetEncoding(interp=0x0000619000003780, name="bogus") at tclEncoding.c:757:12 frame #11: 0x0000000101c0cdee libtcl9.1.dylib`Tcl_SetChannelOption(interp=0x0000619000003780, chan=0x00006060000b13e0, optionName="-encoding", newValue="bogus") at tclIO.c:8299:17 frame #12: 0x0000000101cee7b5 libtcl9.1.dylib`TclNREvalFile(interp=0x0000619000003780, pathPtr=0x0000604000297f90, encodingName="bogus") at tclIOUtil.c:1879:9 frame #13: 0x00000001017fc685 libtcl9.1.dylib`TclNRSourceObjCmd(dummy1170=0x0000000000000000, interp=0x0000619000003780, objc=4, objv=0x0000611000014ae0) at tclCmdMZ.c:1217:14 frame #14: 0x00000001016535bb libtcl9.1.dylib`Dispatch(data=0x00006040002982d8, interp=0x0000619000003780, dummy4623=0) at tclBasic.c:4662:12 frame #15: 0x0000000101635eed libtcl9.1.dylib`TclNRRunCallbacks(interp=0x0000619000003780, result=0, rootPtr=0x0000000000000000) at tclBasic.c:4678:11 frame #16: 0x00000001016484f8 libtcl9.1.dylib`TclEvalObjEx(interp=0x0000619000003780, objPtr=0x00006040001cb210, flags=131072, invoker=0x0000000000000000, word=0) at tclBasic.c:6125:12 frame #17: 0x0000000101648373 libtcl9.1.dylib`Tcl_EvalObjEx(interp=0x0000619000003780, objPtr=0x00006040001cb210, flags=131072) at tclBasic.c:6106:12 frame #18: 0x0000000101bb91b2 libtcl9.1.dylib`Tcl_RecordAndEvalObj(interp=0x0000619000003780, cmdPtr=0x00006040001cb210, flags=131072) at tclHistory.c:182:11 frame #19: 0x0000000101d86d81 libtcl9.1.dylib`Tcl_MainEx(argc=-1, argv=0x00007ff7bfeff560, appInitProc=(tclsh9.1`Tcl_AppInit at tclAppInit.c:124), interp=0x0000619000003780) at tclMain.c:523:13 frame #20: 0x0000000100001e2d tclsh9.1`main(argc=1, argv=0x00007ff7bfeff560) at tclAppInit.c:98:5 frame #21: 0x00007ff803fe8530 dyld`start + 3056 </pre> - foundin initialized to: "core-8-6-branch"
- 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: "source test triggers undefined behavior"
- type initialized to: "Bug"
Ticket change [622614b5bb] (rid 249819) by chrstphrchvz on 2025-12-26 23:06:52:
- icomment:
Would something like the following be an appropriate fix? ``` --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -4255,8 +4255,12 @@ TclGetProcessGlobalValue( * in our epoch-indexed cache. */ - Tcl_ExternalToUtfDString(NULL, pgvPtr->value, pgvPtr->numBytes, &newValue); - value = Tcl_DStringToObj(&newValue); + if (pgvPtr->value) { + Tcl_ExternalToUtfDString(NULL, pgvPtr->value, pgvPtr->numBytes, &newValue); + value = Tcl_DStringToObj(&newValue); + } else { + TclNewObj(value); + } hPtr = Tcl_CreateHashEntry(cacheMap, INT2PTR(pgvPtr->epoch), NULL); Tcl_MutexUnlock(&pgvPtr->mutex); ``` - login: "chrstphrchvz"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [32e0e04600] (rid 249865) by apnadkarni on 2025-12-28 05:13:48:
- icomment:
Christopher, Could you please retest with the bug-983f933f11 branch? I could not verify myself as I could not reproduce the warnings. What were the configure flags used? I tried the following and could not reproduce the error on Ubuntu 20. ``` ../../configure CFLAGS="-fsanitize=undefined,pointer-overflow" LDFLAGS="-fsanitize=undefined,pointer-overflow" make -s shell make -s test TESTFLAGS='-f source.test' ``` Also, I presume you were using the trunk for the build (the ticket says core-8-6-branch) but the stack dump shows 9.1. With regards to your proposed patch, it may fix the warnings in this case but not in cases where `Tcl_ExternalToUtfDString` is called with NULL pointers from elsewhere so not sure if it is adequate. Fixing `Tcl_ETUDS` feels safer assuming the branch resolves the issue.
- login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [9398b05337] (rid 250019) by chrstphrchvz on 2025-12-29 17:35:37:
- icomment:
I did verify the issue exists in 8.6, and that the bug-983f933f11 branch resolves the issue. The lack of offset with NULL pointer UBSan error could be due to the compiler used; I have only seen it when using sufficiently recent versions of Clang, and not under GCC.
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [65615ba0cc] (rid 250046) by apnadkarni on 2025-12-30 03:22:10:
- closedate changed to: "2461039.6404046"
- closer changed to: "apnadkarni"
- icomment: "Fixed in [ea956d4e83]."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"