Artifacts Associated With Ticket 1224888fffffffffffffffffffffffffffffffff
Ticket change [e4b3e5ab35] (rid 88001) by davidw on 2005-06-21 14:29:27:
- assignee initialized to: "dgp"
- cmimetype initialized to: "text/plain"
- comment initialized to:
How to reproduce: 1) Make a local copy of tclsh called something *besides* tclsh or anything else that is in your path. Make sure that '.' is not in your path. 2) Compile this, using the right paths and name of the executable for your environment: #include <unistd.h> int main(int argc, char *argv[], char *envp[]) { char *myargv[] = {"mytclsh", NULL}; execve("/home/davidw/workshop/protect/mytclsh", myargv, envp); } 3) Run it, try 'info name' - it's empty. Here's why: 5454 execve("/home/davidw/workshop/protect/mytclsh", ["mytclsh"], [/* 29 vars * /]) = 0 argv0 has no / in it, and mytclsh is not in PATH, so we hit tclUnixFile.c line 123, and thus have no info nameofexecutable. I found this bug while trying to get starpacks working as CGI's under Apache. The execve program above is a recreation of how Apache launches CGI's. Thanks, Dave - foundin initialized to: "None"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "davidw"
- subsystem initialized to: "36. Pathname Management"
- title initialized to: "possible to have an empty info nameofexecutable"
- type initialized to: "Bug"
Ticket change [4e2f2cc3b5] (rid 127179) by davidw on 2005-06-21 21:43:36:
- icomment:
Logged In: YES user_id=240 Quick patch inline: This seems to fix the problem, but I don't know if it causes others. --- tclUnixFile.c 1 Dec 2004 23:18:55 -0000 1.44 +++ tclUnixFile.c 21 Jun 2005 14:42:29 -0000 @@ -120,8 +120,12 @@ p++; } } - TclSetObjNameOfExecutable(Tcl_NewObj(), NULL); - goto done; + /* It's not in the path, so just use it in the current working + * directory. */ + Tcl_DStringSetLength(&buffer, 0); + name = Tcl_DStringAppend(&buffer, "./", -1); + name = Tcl_DStringAppend(&buffer, argv0, -1); + goto gotName; - login: "davidw"
- mimetype: "text/plain"
- username: "davidw"
- icomment:
Ticket change [2f0d6e5f5d] (rid 92989) by dgp on 2005-06-21 22:24:12:
- icomment:
Logged In: YES user_id=80530 hmmm.... the proposed patch takes effect only after the PATH has been searched. So whenever a program by the same truncated name *is* on the PATH, Tcl will find the wrong one. Seems that Apache really ought to pass the absolute name in argv0.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [8c3c3296b4] (rid 127716) by jcw on 2005-06-21 22:25:38:
- icomment:
Logged In: YES user_id=1983 Great catch! Possible solutions: on Linux and systems which support /proc, you could get at the exe's own path via "/proc/self/exe" which is a symlink pointing to the right file. Another way out might be http://autopackage.org/docs/binreloc/ As workaround, I s'pose one could use full pathnames in apache? -jcw
- login: "jcw"
- mimetype: "text/plain"
- username: "jcw"
- icomment:
Ticket change [ff67465fd6] (rid 108748) by dgp on 2005-06-21 22:28:39:
- icomment:
Logged In: YES user_id=80530 and on the other side of things, TclpFindExecutable() comments say [info nameof] will be set to NULL if the executable can't be found. Won't this patch prevent that by always supplying ./foo as a (possibly false) last resort ?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [1d1946267c] (rid 90730) by gwlester on 2005-06-21 22:52:56:
- icomment:
Logged In: YES user_id=121110 While this bug appears to be a Unix only, the correct behavior needs to be verified on Windows and, if applicable, MacOsX.
- login: "gwlester"
- mimetype: "text/plain"
- username: "gwlester"
- icomment:
Ticket change [22e155a333] (rid 130832) by davidw on 2005-06-21 23:35:13:
- icomment:
Logged In: YES user_id=240 The patch was a quick hack and the objections to it are quite valid... I'm sure we can come up with something better. However, even if Apache isn't doing things quite right, I don't think it's egregiously wrong, either, and I think that Tcl ought to be "liberal with what it accepts" as a general principle. How does this sound for an algorithm: 1) If argv0 has slashes in it, we are ok, we just use that. 2) If there are no slashes, and a file that matches pwd+argv0 exists and is executable, use that. 3) Search the PATH. 4) Can't figure anything out, so just make it NULL.
- login: "davidw"
- mimetype: "text/plain"
- username: "davidw"
- icomment:
Ticket change [6378be75f7] (rid 92587) by dgp on 2005-06-22 00:23:25:
- icomment:
Logged In: YES user_id=80530 the thing I dislike about that is its implicit assumption that "." is first on the PATH. For executables actually launched from the shell (still the vast majority, right?), that can give false answers. If we have no choice but to give a false answer to one or the other, I'd give it to Apache.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [a316c04030] (rid 110000) by patthoyts on 2005-06-22 04:30:16:
- icomment:
Logged In: YES user_id=202636 To reply to gwlester's point - this isn't really an issue on Windows as on windows there is a reliable way to find the path to the binary using GetModuleFilename() and this is used in win/tclAppInit.c to set argv[0] appropriately.
- login: "patthoyts"
- mimetype: "text/plain"
- username: "patthoyts"
- icomment:
Ticket change [92755af9ca] (rid 120763) by dkf on 2005-06-22 05:07:19:
- icomment:
Logged In: YES user_id=79902 I'd be tempted to put the search of the PATH first too. OTOH, doing a readlink("/proc/self/exe") would be better on those OSes that support it (alas, neither Solaris or Irix as far as I can see) though if we do that, it perhaps ought to be a feature searched for using configure? (We'd need a fallback anyway in case /proc isn't mounted for some odd reason.) - login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [0c23aab189] (rid 114125) by dkf on 2005-06-22 05:45:38:
- icomment:
Logged In: YES user_id=79902 FreeBSD (of uncertain vintage but probably fairly old) vintage supports the following readlink() target: /proc/[pid]/file (no /proc/self, different name inside)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [5b204b4665] (rid 118265) by das on 2005-06-23 15:38:17:
- icomment:
Logged In: YES user_id=90580 Mac OS X 10.2 and later has #include <mach-o/dyld.h> int _NSGetExecutablePath(char *buf, unsigned long *bufsize);
- login: "das"
- mimetype: "text/plain"
- username: "das"
- icomment:
Ticket change [6ddca0d7b2] (rid 128774) by davidw on 2005-07-19 22:40:13:
- icomment:
Logged In: YES user_id=240 The apache folks seem to be of the opinion that that system behaves like it does as historical accident. However, they don't really regard it as a bug, and aren't about to change it (who knows who may depend on it at this point), so it doesn't look as if we can shuffle this problem off to them.
- login: "davidw"
- mimetype: "text/plain"
- username: "davidw"
- icomment:
Ticket change [57ec9c8334] (rid 117715) by rkeene on 2009-03-21 00:59:58:
- icomment:
This is still a problem for me. I would like TclpFindExecutable() to be more robust and look for OS-specific ways to determine the executable name. Something similar to: const char *exepaths[] = { "/proc/self/exe", "/proc/%lu/exe", "/proc/%lu/file", "/proc/%lu/object/a.out" }; char pathbuf[PATH_MAX + 1], pathbuf_copy[PATH_MAX + 1]; int pathbuf_len; int exefileexists, recursedepth, idx; if (name == NULL || *name == '\0') { /* Attempt to use "/proc/self/exe" to determine where we are */ for (idx = 0; idx < (sizeof(exepaths) / sizeof(*exepaths)); idx++) { if (strchr(exepaths[idx], '%') == NULL) { sprintf(pathbuf_copy, exepaths[idx]); } else { sprintf(pathbuf_copy, exepaths[idx], (unsigned long) getpid()); } exefileexists = access(pathbuf_copy, F_OK); if (exefileexists == 0) { for (recursedepth = 0; recursedepth < 100; recursedepth++) { pathbuf_len = readlink(pathbuf_copy, pathbuf, sizeof(pathbuf)); if (pathbuf_len < 0) { break; } if (pathbuf_len >= sizeof(pathbuf) || pathbuf_len == 0) { return; } memcpy(pathbuf_copy, pathbuf, pathbuf_len); pathbuf_copy[pathbuf_len] = '\0'; } name = pathbuf_copy; goto gotName; } } } in unix/tclUnixFile.c's TclpFindExecutable if it can't find the executable using the current methods. - login: "rkeene"
- mimetype: "text/plain"
- username: "rkeene"
- icomment:
Ticket change [c177c97a6b] (rid 111325) by stevenaaus on 2011-10-11 08:39:55:
- icomment:
Hmmm... Scid vs. PC now suffers from this problem with wish8.6b2. We compile our own custom wish - tkscid - and install it into local/bin (or bin - they both bug out), and from it [info nameofexecutable] just returns {}. Never seen this bug before 8.6b2, and not sure what to do. - login: "stevenaaus"
- mimetype: "text/plain"
- username: "stevenaaus"
- icomment:
Ticket change [7a54891f43] (rid 90297) by dkf on 2011-10-12 16:49:56:
- icomment:
Doing a readlink() on /proc/[pid]/exe is elegant, but won't work on OSX. There, the only reliable method I've found for getting the executable path from the PID is by calling lsof in a subprocess: lsof -a -p [pid] -F n -d txt Then you need the first line that starts with 'n', and you need all of that line except the first character. Ugh. Works though. (Poking in the normal system process information doesn't work; that gives you the process name without the path to it.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [e18a498fc0] (rid 87469) by stevenaaus on 2011-10-12 17:43:57:
- icomment:
> Doing a readlink() on /proc/[pid]/exe is elegant This should come in handy. Cheers Just clarifying - i never had this issue with any version of 8.4, 8.5 or 8.6a1, so perhaps it is a regression.
- login: "stevenaaus"
- mimetype: "text/plain"
- username: "stevenaaus"
- icomment:
Ticket change [234a2c3285] (rid 130898) by rkeene on 2011-10-12 19:19:43:
- icomment:
In KitCreator I also attempt to use dladdr() if an acceptable implementation is found. Mac OS X appears to support this ( http://developer.apple.com/library/ios/#documentation/system/conceptual/manpages_iphoneos/man3/dladdr.3.html ) http://kitcreator.rkeene.org/fossil/artifact?name=0cfdc14cf7c88b31081e9e0ac689a710a26d6375&ln=294-301
- login: "rkeene"
- mimetype: "text/plain"
- username: "rkeene"
- icomment:
Ticket change [68373a0c50] (rid 103022) by dkf on 2011-10-13 17:54:23:
- icomment:
I also like the dladdr() solution, though the name it yields is not necessarily normalized. Still, that's a practical solution (and would be easy to check for with autoconf). My little test code: #include <dlfcn.h> #include <stdio.h> int main(int argc,char**argv) { Dl_info info; if (!dladdr(main,&info)) { printf("not found\n"); return 1; } printf("\"%s\"\n",info.dli_fname); return 0; } - login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [ea34728bb4] (rid 103328) by dkf on 2011-10-13 17:58:08:
- foundin changed to: "obsolete: 8.5.10"
- icomment:
dgp: What's the position on normalization of [info nameofexecutable]? (dladdr() is present on OSX, Solaris and Linux for sure: I've checked.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
Ticket change [ebfbadffa6] (rid 103632) by dkf on 2011-10-13 19:17:23:
- foundin changed to: "obsolete: 8.4.19"
- icomment:
I've committed something on the bug-1224888 branch. It needs more work (especially detection of the validity of the magic!) but it would be interesting to see if it works. https://core.tcl.tk/tcl/timeline?r=bug-1224888
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
Ticket change [3c01b98d61] (rid 120846) by dgp on 2011-10-14 01:47:45:
- icomment:
The branch produces segfault in test unixFile-1.1 This is on a platform where.. checking for dladdr... no
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [73bfd37afa] (rid 105090) by dgp on 2011-10-14 01:51:55:
- icomment:
Program received signal SIGSEGV, Segmentation fault. 0x0000003716e7288e in free () from /lib64/libc.so.6 (gdb) bt #0 0x0000003716e7288e in free () from /lib64/libc.so.6 #1 0x00000000004cb7d2 in TclpFree ( cp=0x2f6c74692f3a6e69 <Address 0x2f6c74692f3a6e69 out of bounds>) at /home/dgp/fossil/tcl8.4/unix/../generic/tclAlloc.c:710 #2 0x0000000000429ea5 in Tcl_Free ( ptr=0x2f6c74692f3a6e69 <Address 0x2f6c74692f3a6e69 out of bounds>) at /home/dgp/fossil/tcl8.4/unix/../generic/tclCkalloc.c:1167 #3 0x00000000004a86d6 in Tcl_DStringFree (dsPtr=0x7fffffff7f10) at /home/dgp/fossil/tcl8.4/unix/../generic/tclUtil.c:1698 #4 0x00000000004b6788 in TclpFindExecutable (argv0=0x783ca0 "junk") at /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:225 #5 0x0000000000454329 in Tcl_FindExecutable (argv0=0x783ca0 "junk") at /home/dgp/fossil/tcl8.4/unix/../generic/tclEncoding.c:1228 #6 0x0000000000420239 in TestfindexecutableCmd (clientData=0x0, interp=0x700030, argc=2, argv=0x7fffffff8320) at /home/dgp/fossil/tcl8.4/unix/tclUnixTest.c:465 - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [ca3864f4a0] (rid 122425) by dkf on 2011-10-14 04:04:51:
- icomment:
Thank you for testing; I'd put the code two lines too high. :-)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [175b1a8996] (rid 122476) by dgp on 2011-10-18 00:34:17:
- icomment:
==== unixFile-1.1 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) "" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): /local/tmp/dgp/fossil/tcl8.4/unix/junk ==== unixFile-1.1 FAILED ==== unixFile-1.2 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) "/dummy" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): ==== unixFile-1.2 FAILED ==== unixFile-1.3 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) "/dummy:[pwd]" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): /local/tmp/dgp/fossil/tcl8.4/unix/junk ==== unixFile-1.3 FAILED ==== unixFile-1.4 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) "/dummy:" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): /local/tmp/dgp/fossil/tcl8.4/unix/junk ==== unixFile-1.4 FAILED ==== unixFile-1.5 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) "/dummy:/dummy" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): ==== unixFile-1.5 FAILED ==== unixFile-1.6 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) "/dummy::/dummy" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): /local/tmp/dgp/fossil/tcl8.4/unix/junk ==== unixFile-1.6 FAILED ==== unixFile-1.7 Tcl_FindExecutable FAILED ==== Contents of test case: set env(PATH) ":/dummy" testfindexecutable junk ---- Result was: /local/tmp/dgp/fossil/tcl8.4/unix/tcltest"j ---- Result should have been (exact matching): /local/tmp/dgp/fossil/tcl8.4/unix/junk ==== unixFile-1.7 FAILED - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [2157dbb6b6] (rid 130568) by dgp on 2011-11-01 00:14:33:
- icomment:
On another of my systems, this branch fails to build: /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c: In function ‘TclpFindExecutable’: /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:64: error: ‘Dl_info’ undeclared (first use in this function) /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:64: error: (Each undeclared identifier is reported only once /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:64: error: for each function it appears in.) /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:64: error: expected ‘;’ before ‘dlinfoBuffer’ /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:100: error: ‘RTLD_DEFAULT’ undeclared (first use in this function) /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:104: warning: implicit declaration of function ‘dladdr’ /home/dgp/fossil/tcl8.4/unix/tclUnixFile.c:104: error: ‘dlinfoBuffer’ undeclared (first use in this function)
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [df88dd79e3] (rid 115027) by nijtmans on 2011-11-01 02:43:11:
- icomment:
>On another of my systems, this branch fails >to build: Probably because configure.in is changed but configure is not re-generated. done now. Does that help?
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
- icomment:
Ticket change [7b60780896] (rid 90503) by dgp on 2011-11-01 03:16:32:
- icomment:
thanks; now back to the unixFile-1.* fails.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [2781718882] (rid 141075) by dkf on 2015-01-07 23:30:29:
- closer changed to: "nobody"
- comment changed to:
How to reproduce: 1) Make a local copy of tclsh called something *besides* tclsh or anything else that is in your path. Make sure that '.' is not in your path. 2) Compile this, using the right paths and name of the executable for your environment: #include <unistd.h> int main(int argc, char *argv[], char *envp[]) { char *myargv[] = {"mytclsh", NULL}; execve("/home/davidw/workshop/protect/mytclsh", myargv, envp); } 3) Run it, try 'info name' - it's empty. Here's why: 5454 execve("/home/davidw/workshop/protect/mytclsh", ["mytclsh"], [/* 29 vars * /]) = 0 argv0 has no / in it, and mytclsh is not in PATH, so we hit tclUnixFile.c line 123, and thus have no info nameofexecutable. I found this bug while trying to get starpacks working as CGI's under Apache. The execve program above is a recreation of how Apache launches CGI's. Thanks, Dave - login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Remind"
- severity changed to: "Minor"
Ticket change [0483fa57cb] (rid 141076) by dgp on 2015-01-13 14:34:06:
- assignee changed to: "dkf"
- icomment:
Can't get anywhere with rebasing the branch to something live. Everything I try fails the test suite catastrophically with apparent mem corruption in the name of the tcltest executable. I'll happily test when someone else gets the branch resurrected.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [da49855214] (rid 141095) by jan.nijtmans on 2015-01-22 20:04:28:
- icomment:
Please try again ;-) The reason probably was that "main" was made MODULE_SCOPE, so dlsym() cannot find it any more .....
- login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [0f3d73eba1] (rid 141097) by dgp on 2015-01-22 21:02:43:
- icomment:
No improvement.... ... Tests began at Thu Jan 22 16:02:41 EST 2015 aaa_exit.test Test file error: couldn't execute "/local/tmp/dgp/fossil/tcl-only/unix/tcltestQÿ": no such file or directory append.test Test file error: couldn't execute "/local/tmp/dgp/fossil/tcl-only/unix/tcltestQÿ": no such file or directory ...
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [a3b72962c5] (rid 141138) by dkf on 2015-02-04 11:01:14:
- assignee changed to: "dgp"
- login: "dkf"
- mimetype: "text/plain"
Ticket change [0a541b8c2d] (rid 141145) by drh on 2015-02-04 18:12:23:
- icomment:
Adding a comment merely to test Fossil ticket handle. Ignore this comment.
- login: "drh"
- mimetype: "text/plain"
- username: "drh"
- icomment:
Ticket change [14fc56c7d7] (rid 141397) by dkf on 2015-03-17 20:32:10:
- icomment:
It's going to be really hard to figure out what is wrong without knowing the path through the tangle of code that is being taken. It's an awful tangle right now. <p> I've added support for <tt>_NSGetExecutablePath</tt> on OSX to the branch. A bunch of tests in unixFile.test now fail because Tcl ceases to be fool-able as to its executable name. The name isn't (always) a normalized one; will that matter? <p> Anyone digging into the depths of this should start with <a href="http://stackoverflow.com/q/1023306/301832">http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe</a> which summarizes a lot of the key techniques on different platforms.
- login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [70c43eadbe] (rid 158452) by aspect on 2017-11-16 12:55:34:
- icomment:
The errors below come from readlink's silly failure to terminate its result. I've pushed a patch that handles it properly and passes the test suite. The implementation in TclpFindExecutable looks pretty good, but it could do with being broken out into individually-testable parts. Looking at the linked SO discussion, it seems all we're missing for "full" coverage is the Solaris getexecname() and FreeBSD sysctl approaches. Both these platforms apparently "often" have /proc/ with one of the paths included in exenames[]. I think this branch (once brought up to date with trunk) should eliminate the need for kitcreator's workaround. I know we have people who can test on FreeBSD (gahr?) but how about Solaris/Illumos? Anyone have access to one of those?
- login: "aspect"
- mimetype: "text/plain"
- icomment:
Ticket change [6c095dcca3] (rid 158498) by aspect on 2017-11-17 04:56:48:
- icomment:
merged trunk. Correction to previous comment: unixFile-1.x are FAILing, as expected: these tests prove that TclpFindExecutable can be tricked by a bogus argv[0], which is the point of this ticket. Updating these tests is the obvious step, but as mentioned below a test suite which exercises the different paths on various platforms would be a Good Idea.
- login: "aspect"
- mimetype: "text/plain"
- icomment: