summary refs log tree commit diff
path: root/src/exec.c (follow)
Commit message (Collapse)AuthorAge
* [BUILTIN] Small optimisation of command -pv changeHerbert Xu2014-09-26
| | | | | | | | This patch moves the pathval call into the describe_command function and also eliminates an unnecessary branch when DEBUG is off. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] command: allow combining -p with -vHarald van Dijk2014-09-26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On 10/07/13 20:18, Craig Loomis wrote: > Dash (0.5.7 and git master) does not implement 'command -p' > according to the standard, and opens an intriguing security hole to > anyone trying this scheme. > > When using 'command -v' to simply print the path to an executable, > '-p' has no effect: You're right. dash has never supported combining -p with -v, but back in 2005 this was seemingly accidentally changed from reporting a syntax error to silently ignoring the -p option, only about a month after dash moved to git. Making sure that -p is respected even when -v is used is easy enough, see attached patch. Tested even with explicit PATH overrides: PATH=/path/to/some/other/dash command -pv dash correctly outputs /bin/dash on my system. > the path that 'command -p cmd' uses is a compiled-in constant > from dash's src/var.c:defpathvar, which starts with > "/usr/local/sbin:/usr/local/bin". To me, that is both completely > unexpected and pretty scary -- /usr/local/bin is (very) often less > well secured or checked than, say, /bin: Agreed. However, IMO, it does make sense for defpathvar to start with /usr/local/*: it has two separate functions, it also serves as the default path (hence the name) when dash is started with no PATH set at all. I think fixing this should be done in a way so that command -p does not use defpathvar, not by changing defpathvar. bash uses the same confstr function for this that getconf uses, and it shouldn't be too much work to make dash use that too. If no one else comes up with a working patch or a better approach, I'll try to get that working. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Improve LINENO supportHarald van Dijk2011-03-15
| | | | | | | | | | | | This patch improves LINENO support by storing line numbers in the parse tree, for commands as well as for function definitions. It makes LINENO behaves properly when calling functions, and has the added benefit of improved line numbers in error messages when the last-parsed command is not the last-executed one. It removes the earlier LINENO support, and instead sets LINENO from evaltree when a command is executed Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EVAL] Let funcnode refer to a function definition, not its first commandHarald van Dijk2011-03-15
| | | | | | | | | | | | It is not unrelated: I changed the meaning of struct funcnode's field n to refer to the function definition, rather than the list of the function's commands, because I needed to refer to the function definition node from evalfun, which only gets passed a funcnode. But it is something that could be applied independently (without being useful by itself), so I've attached it as a separate patch for easier review. Signed-off-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [SHELL] Port to SolarisBrian Koropoff2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Solaris lacks paths.h and the various _PATH_* #defines. Check for them in configure.ac and fall back on the usual suspects when they are missing. - Older Solaris lacks isblank(), and versions that have it use a macro. Check for the declaration in configure.ac and fall back on a naive version when missing. - Older Solaris does not support %jd (intmax_t) in format strings, but it does support the PRIdMAX macro from inttypes.h. Do a configure check for PRIdMAX and use it in the code. If it doesn't exist, define it to "lld" when sizeof(long long) equals sizeof(intmax_t) as this is more likely to work on older systems. Otherwise, use "jd" and hope for the best. - Older Solaris lacks stdint.h, but inttypes.h provides the same types and works on all platforms I've tried dash on, so just use it instead. - Older Solaris doesn't like it when vsnprintf() is passed a NULL buffer (in violation of the POSIX spec, of course). Pass a 1-byte dummy buffer instead. - Solaris lacks tempfile and mktemp programs. Fall back on a "good-enough" custom function in mkbuiltins. Signed-off-by: Brian Koropoff <bkoropoff@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Use EXEXIT in place of EXEXECJonathan Nieder2010-11-28
| | | | | | | | | | | | | | | | | | | | | | The intended semantics of EXEXEC are identical to EXEXIT, so simplify by using EXEXIT directly. Functional change: in edge cases (exec within a trap handler), this causes the exit status from exec not to be clobbered. For example, without this patch: $ sh -c 'trap "exec nonexistent" EXIT'; echo $? exec: 1: nonexistent: not found 0 And with it: $ sh -c 'trap "exec nonexistent" EXIT'; echo $? exec: 1: nonexistent: not found 127 Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXEC] Fixed _PATH_BSHELL warningHerbert Xu2008-05-03
| | | | | | | | | | | | | | | | With klcc we get klcc -DHAVE_CONFIG_H -I. -I.. -include ../config.h -DBSD=1 -DSHELL -DIFS_BROKEN -Wall -D__CTYPE_NO_INLINE -MT exec.o -MD -MP -MF .deps/exec.Tpo -c -o exec.o exec.c exec.c: In function 'tryexec': exec.c:160: warning: comparison with string literal results in unspecified behavior Storing it in a local variable fixes the problem. Thanks to Dan McGee for reporting this. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [EXEC] Fixed execing of scripts with no hash-bangHerbert Xu2007-10-15
| | | | | | | | | | | | | | | | | | | | | | | | | | The function tryexec used the original name instead of the path found through PATH search. This patch fixes that. Test case: trap 'rm -f $TMP' EXIT TMP=$(tempfile -s nosuchthing) cat <<- EOF > $TMP echo OK EOF chmod u+x $TMP cd / PATH=${TMP%/*} ${TMP##*/} Old result: /bin/sh: Can't open filelgY4Fanosuchthing New result: OK
* [REDIR] Remove redundant CLOEXEC callsHerbert Xu2007-05-12
| | | | | Now that we're marking file descriptors as CLOEXEC in savefd, we no longer need to close them on exec or in setinputfd.
* [BUILTIN] Fixed command -v segmentation faultHerbert Xu2006-10-22
| | | | | | | | | | | | | | | On Sat, Oct 21, 2006 at 02:19:18PM +0000, Gerrit Pape wrote: > Hi Herbert, please see > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=387458 > > On Thu, Sep 14, 2006 at 03:50:02PM +0200, Julien Danjou wrote: > > I just found this bug which is easily reproductible: > > > > % dash -c 'command -v' > > zsh: segmentation fault dash -c 'command -v' Since bash's behaviour is minimalist here, I've decided to adopt its behaviour here as well which is to return success silently.
* [SYSTEM] Added default implementation of bsearchHerbert Xu2005-10-29
| | | | Added impelmentation of bsearch since klibc doesn't have it yet.
* [BUILTIN] Stop using sysexits.h in commandcmdHerbert Xu2005-10-29
| | | | | | | | | | | This gets rid of the only reference of sysexits.h in dash which is from commandcmd. This is needed for klibc support since it doesn't have sysexits.h. The only uses of sysexits.h in commandcmd is superfluous anyway. In fact, it is overly sensitive about usages such as 'command -vV ls'. By making its behaviour close to that of bash/ksh, we end up saving a bit of space too.
* Copyright/licence updates and remove all traces of sys/cdefs.hHerbert Xu2005-10-29
| | | | | | | | | | | This change updates the BSD licence to the three-clause version since NetBSD has already done so. This makes dash GPL-compatible. It also adds Christos Zoulas (NetBSD ash maintainer) to the COPYING file. I've added "copyright by Herbert Xu" to most files. Finally all CVS IDs and inclusion of sys/cdefs.h have been removed. The latter is needed for support of klibc.
* Removed some unnecessary inclusions of input.h.herbert2005-09-26
|
* Renamed error to sh_error.herbert2005-09-26
|
* Eliminated global exerrno.herbert2005-09-26
|
* Initial import.Herbert Xu2005-09-26