Date: Fri, 28 Nov 1997 19:23:34 +0900 (JST) From: kagotani@in.it.okayama-u.ac.jp To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/5172: [2.2.5] /bin/sh dumps core Message-ID: <199711281023.TAA02509@loach.in.it.okayama-u.ac.jp> Resent-Message-ID: <199711281030.CAA06390@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 5172 >Category: bin >Synopsis: /bin/sh dumps core when exec'ing a bogus script >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Nov 28 02:30:00 PST 1997 >Last-Modified: >Originator: Hiroto Kagotani >Organization: Okayama University, Japan >Release: FreeBSD 2.2.5-RELEASE i386 >Environment: On the console or on any terminal emulator running any shell. >Description: If the interpreter of an executable script does not exist, and the directory containing the script is not the last part of PATH variable, then /bin/sh dumps core when exec'int the script. >How-To-Repeat: Create two executable scripts named "a" and "b" as follows: --- a --- #!/bin/sh PATH=.:/bin b --------- --- b --- #!/no/such/file --------- And type "./a" in your shell. Then, you will get: % ./a Segmentation fault - core dumped % >Fix: shellexec() in /bin/sh assumes that tryexec() does not change argv[0]. But execve(2) called in tryexec() changes it. (I'm not sure whether this is a spec or a bug of execve(2).) So, my sample fix preserves argv[0] before calling execve(2), and restores it after. --------- diff -u /usr/src/bin/sh/exec.c ./exec.c --- /usr/src/bin/sh/exec.c Mon Aug 25 18:09:46 1997 +++ ./exec.c Fri Nov 28 18:17:22 1997 @@ -164,6 +164,7 @@ char *p; #endif + char *argv0 = argv[0]; #ifdef SYSV do { execve(cmd, argv, envp); @@ -171,6 +172,7 @@ #else execve(cmd, argv, envp); #endif + argv[0] = argv0; e = errno; if (e == ENOEXEC) { initshellproc(); --------- >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199711281023.TAA02509>