Overview
| Artifact ID: | caea86e1a43686858f466d22ab233830b9de8a8f |
|---|---|
| Ticket: | 0df7a1ec2674a76a04f8ce3f405a1c1f8273ec20
unix/tclUnixFile.c: return value of call to TclpGetCwd in TclpFindExecutable is not checked, variable cwd is used uninitialized |
| User & Date: | scmc on 2015-08-21 18:19:48 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed 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 changed to: "8.6.4"
- is_private changed to: "0"
- login: "scmc"
- priority changed to: "5 Medium"
- private_contact changed to: "e384c2e057a673ceab61eaee941d49e4645ed529"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "scmc"
- subsystem changed to: "38. Init - Library - Autoload"
- title changed to:
unix/tclUnixFile.c: return value of call to TclpGetCwd in TclpFindExecutable is not checked, variable cwd is used uninitialized
- type changed to: "Bug"