Artifacts Associated With Ticket 0df7a1ec2674a76a
Ticket change [caea86e1a4] (rid 142884) by scmc on 2015-08-21 18:19:48:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Hello, I'm embedding Tcl in a process running in FreeBSD capability mode (a.k.a. Capsicum) on an amd64 platform. When doing so, use of system calls referencing global namespaces (e.g., the file system) is restricted. In the function TclpFindExecutable, the call to TclpGetCwd fails because calling getcwd will fail with errno 94, ECAPMODE - "Not permitted in capability mode". This happens if argv consists of a relative path. If that call fails, the variable cwd is uninitialized. Use of uninitialized variable causes application crash. GDB output with stack trace: Program terminated with signal 10, Bus error. #0 0x00000000004e1a9b in UtfToUtfProc (clientData=0x0, src=0x800000000000 <Address 0x800000000000 out of bounds>, srcLen=5984000, flags=2, statePtr=0x7fffffffe038, dst=0x8010b5db5 "", dstLen=6402, srcReadPtr=0x7fffffffe01c, dstWrotePtr=0x7fffffffe018, dstCharsPtr=0x7fffffffe014, pureNullMode=1) at /home/scmc/src/tcl8.6.4/generic/tclEncoding.c:2329 2329 if (UCHAR(*src) < 0x80 && !(UCHAR(*src) == 0 && pureNullMode == 0)) { (gdb) bt #0 0x00000000004e1a9b in UtfToUtfProc (clientData=0x0, src=0x800000000000 <Address 0x800000000000 out of bounds>, srcLen=5984000, flags=2, statePtr=0x7fffffffe038, dst=0x8010b5db5 "", dstLen=6402, srcReadPtr=0x7fffffffe01c, dstWrotePtr=0x7fffffffe018, dstCharsPtr=0x7fffffffe014, pureNullMode=1) at /home/scmc/src/tcl8.6.4/generic/tclEncoding.c:2329 #1 0x00000000004dfca0 in UtfIntToUtfExtProc (clientData=0x0, src=0x7ffffffffb47 "", srcLen=5984000, flags=2, statePtr=0x7fffffffe038, dst=0x8010b58fc "", dstLen=6402, srcReadPtr=0x7fffffffe01c, dstWrotePtr=0x7fffffffe018, dstCharsPtr=0x7fffffffe014) at home/scmc/src/tcl8.6.4/generic/tclEncoding.c:2194 #2 0x00000000004e1649 in Tcl_UtfToExternalDString (encoding=0x80100b150, src=0x7ffffffffb47 "", srcLen=5984000, dstPtr=0x7fffffffe370) at /home/scmc/src/tcl8.6.4/generic/tclEncoding.c:1327 #3 0x00000000005b02e4 in TclpFindExecutable (argv0=0x7fffffffe998 "./tcl") at tclUnixFile.c:177 #4 0x0000000000549fba in Tcl_MainEx (argc=1, argv=0x7fffffffe738, appInitProc=0x400410 <Tcl_AppInit>, interp=0x801044400) at /home/scmc/src/tcl8.6.4/generic/tclMain.c:317 The following change fixes this problem for me, however I am not sure it's the way to go (e.g., it causes [info nameofexecutable] to return an empty string). --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -164,12 +164,13 @@ TclpFindExecutable( if ((name[0] == '.') && (name[1] == '/')) { name += 2; } + + if (TclpGetCwd(NULL, &cwd) == NULL) { + goto done; + } Tcl_DStringInit(&nameString); Tcl_DStringAppend(&nameString, name, -1); - - TclpGetCwd(NULL, &cwd); - Tcl_DStringFree(&buffer); Tcl_UtfToExternalDString(NULL, Tcl_DStringValue(&cwd), Tcl_DStringLength(&cwd), &buffer); //Sebastian Cato - foundin initialized to: "8.6.4"
- is_private initialized to: "0"
- login: "scmc"
- priority initialized to: "5 Medium"
- private_contact initialized to: "e384c2e057a673ceab61eaee941d49e4645ed529"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "scmc"
- subsystem initialized to: "38. Init - Library - Autoload"
- title initialized to:
unix/tclUnixFile.c: return value of call to TclpGetCwd in TclpFindExecutable is not checked, variable cwd is used uninitialized
- type initialized to: "Bug"
Ticket change [11b70fba1b] (rid 142899) by jan.nijtmans on 2015-08-25 12:06:36:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2457260.00458905"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed in core-8-5-branch and trunk, will be in next release. Thanks for the report!
- login: "jan.nijtmans"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"