summaryrefslogtreecommitdiffstats
path: root/bin/sh
Commit message (Collapse)AuthorAgeFilesLines
* sh: Fix heap-based buffer overflow in pathname generation.jilles2010-08-101-16/+15
| | | | | | | | | | | | | | The buffer for generated pathnames could be too small in some cases. It happened to be always at least PATH_MAX long, so there was never an overflow if the resulting pathnames would be usable. This bug may be abused if a script subjects input from an untrusted source to pathname generation, which a bad idea anyhow. Most shell scripts do not work on untrusted data. secteam@ says no advisory is necessary. PR: bin/148733 Reported by: Changming Sun snnn119 at gmail com MFC after: 10 days
* Remove unnecessary duplicate letters in mksyntax.c,jilles2010-08-081-2/+2
| | | | the table elements would just be overwritten twice.
* sh: Return 0 from eval if no command was given.jilles2010-08-031-1/+7
| | | | | | | | | | | This makes a difference if there is a command substitution. To make this work, evalstring() has been changed to set exitstatus to 0 if no command was executed (the string contained only whitespace). Example: eval $(false); echo $? should print 0.
* sh: Do not enter consecutive duplicates into the history.jilles2010-08-011-0/+1
| | | | | | | | | | | | This simply sets a flag in libedit. It has a shortcoming in that it does not apply to multi-line commands. Note that a configuration option for this is not going to happen, but always having this seems better than not having it. NetBSD has done the same. PR: bin/54683 Obtained from: NetBSD MFC after: 1 month
* sh: Fix crash due to uninitialized here-document.jilles2010-07-251-0/+3
| | | | | | | | | | | | | | | If an ; or & token was followed by an EOF token, pending here-documents were left uninitialized. Execution would crash, either in the main shell process for literal here-documents or in a child process for expanded here-documents. In the latter case the problem is hard to detect apart from the core dumps and log messages. Side effect: slightly different retries on inputs where EOF is not persistent. Note that tools/regression/bin/sh/parser/heredoc6.0 still causes a similar crash in a child process. The text passed to eval is malformed and should be rejected.
* sh: Allow a background command consisting solely of redirections.jilles2010-07-181-0/+1
| | | | | | | Example: </dev/null & MFC after: 2 weeks
* sh: There cannot be a TNOT in simplecmd(), remove checks.jilles2010-07-141-19/+3
| | | | | | simplecmd() only handles simple commands and function definitions, neither of which involves the ! keyword. The initial token on entry to simplecmd() is one of the following: TSEMI, TAND, TOR, TNL, TEOF, TWORD, TRP.
* sh: Use $PWD instead of getcwd() for the \w and \W prompt expansions.jilles2010-07-021-12/+11
| | | | | | This ensures that the logical working directory (which may include symlinks) is shown and is similar to the default behaviour of the pwd builtin.
* sh: Forget about terminated background processes sooner.jilles2010-06-294-9/+66
| | | | | | | | | | | | | | | | | | | | | | | | Unless $! has been referenced for a particular job or $! still contains that job's pid, forget about it after it has terminated. If $! has been referenced, remember the job until the wait builtin has reported its completion (either with the pid as parameter or without parameters). In interactive mode, jobs are forgotten after termination has been reported, which happens before primary prompts and through the jobs builtin. Even then, though, remember a job if $! has been referenced. This is similar to what is suggested by POSIX and should fix most memory leaks (which also tend to cause sh to use more CPU time) with long running scripts that start background jobs. Caveats: * Repeatedly referencing $! without ever doing 'wait', like while :; do foo & echo started foo: $!; sleep 60; done will still use a lot of memory and CPU time in the long run. * The jobs and jobid builtins do not cause a job to be remembered for longer like expanding $! does. PR: bin/55346
* sh: Fix compilation with -DNO_HISTORY.jilles2010-06-191-0/+1
| | | | | | | | | | | The LINENO code uses snprintf() and relied on "myhistedit.h" to pull in the necessary <stdio.h>. Compiling with -DNO_HISTORY disables all editing and history support and allows linking without -ledit -ltermcap. This may be useful for embedded systems. MFC after: 2 weeks
* sh: Add filename completion.jilles2010-06-151-0/+4
| | | | | | | | | | | | This uses the new libedit completion function with quoting support. Unlike NetBSD, there is no 'set +o tabcomplete' option to disable completion. I do not see any reason for such a special treatment, as completion is rather useful and it is possible to do bind ^I ed-insert to disable completion and insert a tab character instead. Submitted by: Guy Yur
* sh: Pass through SIGINT from a child if interactive and job controljilles2010-06-061-0/+6
| | | | | | | | | | | | | | | is enabled. This already worked if without job control. In either case, this depends on it that a process that terminates due to SIGINT exits on it (so not with status 1, or worse, 0). Example: sleep 5; echo continued This does not print "continued" any more if sleep is aborted via ctrl+c. MFC after: 1 month
* sh: Pass TERM changes to libedit.jilles2010-06-024-0/+22
| | | | | | | | I have changed the patch slightly to ignore TERM changes in subshells. PR: bin/146916 Submitted by: Guy Yur Obtained from: NetBSD
* sh: Fix a crash if a heredoc was not properly ended and parsing continued.jilles2010-05-301-0/+1
| | | | | | | | | Example (in interactive mode): cat <<EOF && ) The next command typed caused sh to segfault, because the state for the here document was not reset. Like parser_temp, this uses the fact that the parser is not re-entered.
* sh: Change interaction of command substitution and here documents.jilles2010-05-301-4/+13
| | | | | | | | | | | | | | | | | If a command substitution contains a newline token, this no longer starts here documents of outer commands. This way, we follow POSIX's idea of the command substitution being a separate script more closely. It also matches other shells better and is consistent with newline characters in quotes not starting here documents. The extension tested in parser/heredoc3.0 ($(cat <<EOF)\ntext\nEOF\n) continues to be supported. In particular, this change allows things like cat <<EOF && echo `pwd` (a `` command substitution after a here document) which formerly silently used an empty file as the here document, because the EOF of the inner command "pwd" also forced an empty here document.
* sh: Recognize "--" in . and exec.jilles2010-05-282-2/+14
| | | | | | | | | | | | | | | | | | Although "--" historically has not been required to be recognized for certain special builtins that do not take options in POSIX, some other implementations recognize options for them, requiring scripts to use "--" or avoid operands starting with "-". Operands starting with "-" can be avoided with eval by prepending a space, and cannot occur with break, continue, exit, return and shift as they only take numbers, nor with times as it does not take operands. With . and exec, avoiding "-" is not so easy as it may require reimplementing the PATH search; therefore the current proposal for POSIX is to require recognition of "--" for them. We continue to accept other strings starting with "-" as operands to . and exec, and also "--" if it is alone to . (which would otherwise be invalid anyway).
* sh(1): Rework documentation of shell variables.jilles2010-05-241-87/+118
| | | | | | | | | * Move the "environment variables" that do not need exporting to be effective or that are set by the shell without exporting to a new section "Special Variables". * Add special variables LINENO and PPID. * Add environment variables LANG, LC_* and PWD; also describe ENV under environment variables.
* sh(1): Improve wording of 'Special Parameters' section.jilles2010-05-241-7/+3
|
* sh: Reap any zombies before forking for a background command.jilles2010-05-241-1/+13
| | | | | | | | | | | | | | This prevents accumulating huge amounts of zombies if a script executes many background commands but no external commands or subshells. Note that zombies will not be reaped during long calculations (within the shell process) or read builtins, but those actions do not create more zombies. The terminated background commands will also still be remembered by the shell. PR: bin/55346
* sh: Fix pathname expansion with quoted slashes like *\/.jilles2010-05-111-9/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are git commits 36f0fa8fcbc8c7b2b194addd29100fb40e73e4e9 and d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4 in dash. Because this is the first code I'm importing from dash to expand.c, add the Herbert Xu copyright notice which is in dash's expand.c. When pathname expanding *\/, the CTLESC representing the quoted state was erroneously taken as part of the * pathname component. This CTLESC was then seen by the pattern matching code as escaping the '\0' terminating the string. The code is slightly different because dash converts the CTLESC characters to backslashes and removes all the other CTL* characters to allow substituting glob(3). The effect of the bug was also slightly different from dash (where nothing matched at all). Because a CTLESC can escape a '\0' in some way, whether files were included despite the bug depended on memory that should not be read. In particular, on many machines /*\/ expanded to a strict subset of what /*/ expanded to. Example: echo /*"/null" This should print /dev/null, not /*/null. PR: bin/146378 Obtained from: dash
* sh(1): Fix "reserved word" vs "keyword" inconsistency.jilles2010-05-091-9/+9
| | | | | Use "keyword" everywhere, like the output of the 'type' builtin, and only mention "reserved word" once to say it is the same thing.
* sh: Have only one copy of _PATH_STDPATH in the binary.jilles2010-05-081-3/+2
|
* sh: Apply locale vars on builtins, recognize LC_MESSAGES as a locale var.jilles2010-05-053-7/+74
| | | | | | | | | | | | | | | | This allows doing things like LC_ALL=C some_builtin to run a builtin under a different locale, just like is possible with external programs. The immediate reason is that this allows making printf(1) a builtin without breaking things like LC_NUMERIC=C printf '%f\n' 1.2 This change also affects special builtins, as even though the assignment is persistent, the export is only to the builtin (unless the variable was already exported). Note: for this to work for builtins that also exist as external programs such as /bin/test, the setlocale() call must be under #ifndef SHELL. The shell will do the setlocale() calls which may not agree with the environment variables.
* sh: Use stalloc for arith variable names.jilles2010-04-253-24/+10
| | | | | This is simpler than the custom memory tracker I added earlier, and is also needed by the dash arith code I plan to import.
* sh: On startup of the shell, use PWD from the environment if it is valid.jilles2010-04-173-10/+24
| | | | | | | | | | | | | | | Unset PWD if it is incorrect and no value for it can be determined. This preserves the logical current directory across shell invocations. Example (assuming /home is a symlink): $ cd $ pwd /home/foo $ sh $ pwd /home/foo Formerly the second pwd would show the physical path (symlinks resolved).
* sh: Partially revert r206146, allowing double-quotes in arithmetic.jilles2010-04-112-1/+5
| | | | | | | | These do pretty much nothing (except that parentheses are ignored), but people seem to use them and allowing them does not hurt much. Single-quotes seem not to be used and cause silently different behaviour with ksh93 character constants.
* sh: Automatically enable -o emacs in interactive shells with terminals.jilles2010-04-052-3/+7
| | | | | | | This makes sh a bit more friendly in single user mode, make buildenv, chroot and the like, and matches other shells. The -o emacs can be overridden on the command line or in the ENV file.
* sh: Document the expansion changes in the man page.jilles2010-04-041-2/+20
| | | | | | | | Note that the following sentence > Enclosing the full parameter expansion string in double-quotes does not > cause the following four varieties of pattern characters to be quoted, > whereas quoting characters within the braces has this effect. is now true, but used to be incorrect.
* sh: Do tilde expansion in substitutions.jilles2010-04-031-3/+3
| | | | | | | | | | | | | This applies to word in ${v-word}, ${v+word}, ${v=word}, ${v?word} (which inherits quoting from the outside) and in ${v%word}, ${v%%word}, ${v#word}, ${v##word} (which does not inherit any quoting). In all cases tilde expansion is only attempted at the start of word, even if word contains spaces. This agrees with POSIX and other shells. This is the last part of the patch tested in the exp-run. Exp-run done by: erwin (with some other sh(1) changes)
* sh: Allow quoting pattern match characters in ${v%pat} and ${v#pat}.jilles2010-04-031-1/+3
| | | | | | | | Note that this depends on r206145 for allowing pattern match characters to have their special meaning inside a double-quoted expansion like "${v%pat}". PR: bin/117748 Exp-run done by: erwin (with some other sh(1) changes)
* sh: Remove special handling for ' and " in arithmetic.jilles2010-04-032-6/+1
| | | | | | | They will be treated like normal characters, resulting in a runtime arithmetic expression error. Exp-run done by: erwin (with some other sh(1) changes)
* sh: Fix various things about expansions:jilles2010-04-031-73/+208
| | | | | | | | | | | | | | | | | | | | * remove the backslash from \} inside double quotes inside +-=? substitutions, e.g. "${$+\}a}" * maintain separate double-quote state for ${v#...} and ${v%...}; single and double quotes are special inside, even in a double-quoted string or here document * keep track of correct order of substitutions and arithmetic This is different from dash's approach, which does not track individual double quotes in the parser, trying to fix this up during expansion. This treats single quotes inside "${v#...}" incorrectly, however. This is similar to NetBSD's approach (as submitted in PR bin/57554), but recognizes the difference between +-=? and #% substitutions hinted at in POSIX and is more refined for arithmetic expansion and here documents. PR: bin/57554 Exp-run done by: erwin (with some other sh(1) changes)
* sh: Treat unexpected newlines in substitutions as a syntax error.jilles2010-04-031-0/+4
| | | | | | | The old approach was wrong because PS2 was not used and seems unlikely to parse extensions (ksh93's ${ COMMAND} may well fail to parse). Exp-run done by: erwin (with some other sh(1) changes)
* sh: Do not abort on a redirection error on a compound command.jilles2010-03-141-4/+42
| | | | | | | | | | | | | | Redirection errors on subshells already did not abort the shell because the redirection is executed in the subshell. Other shells seem to agree that these redirection errors should not abort the shell. Also ensure that the redirections will be cleaned up properly in cases like command eval '{ shift x; } 2>/dev/null' Example: { echo bad; } </var/empty/x; echo good
* sh: Do not abort on a redirection error if there is no command word.jilles2010-03-131-1/+7
| | | | | | | | | | | Although simple commands without a command word (only assignments and/or redirections) are much like special builtins, POSIX and most shells seem to agree that redirection errors should not abort the shell in this case. Of course, the assignments persist and assignment errors are fatal. To get the old behaviour portably, use the ':' special builtin. To get the new behaviour portably, given that there are no assignments, use the 'true' regular builtin.
* sh: Fix longjmp clobber warnings in parser.c.jilles2010-03-131-166/+162
| | | | | | Make parsebackq a function instead of an emulated nested function. This puts the setjmp usage in a smaller function where it is easier to avoid bad optimizations.
* sh: Make sure to popredir() even if a function caused an error.jilles2010-03-061-1/+3
|
* sh: Make sure to popredir() even if a special builtin caused an error.jilles2010-03-061-2/+3
|
* sh: Improve the command builtin:jilles2010-03-064-43/+90
| | | | | | | | * avoid unnecessary fork * allow executing builtins via command * executing a special builtin via command removes its special properties Obtained from: NetBSD (parts)
* Fix expansion of \W in prompt strings when the working directory is "/".jh2010-02-241-1/+1
| | | | | | | | The prompt string was truncated after \W when the working directory was "/". PR: bin/89410 Submitted by: Dr Balwinder Singh Dheeman MFC after: 1 week
* sh: Do not stat() $MAIL/$MAILPATH in non-interactive shells.jilles2010-02-062-1/+8
| | | | | These may be NFS mounted, and we should not touch them unless we are going to do something useful with the information.
* sh: Send the "not found" message for builtin <cmd> to redirected fd 2.jilles2010-01-031-5/+11
|
* sh: Fix some bugs with backquoted builtins:jilles2010-01-016-21/+23
| | | | | | | | | | | | - correctly handle error output in $(builtin 2>&1), clarify out1/out2 vs output/errout in the code - treat all builtins as regular builtins so errors do not abort the shell and variable assignments do not persist - respect the caller's INTOFF Some bugs still exist: - expansion errors may still abort the shell - some side effects of expansions and builtins persist
* sh(1): document ulimit -w (swapuse rlimit).jilles2009-12-311-2/+5
| | | | MFC after: 1 week
* sh(1): Correct two places where "$@" lacked necessary quotes.jilles2009-12-311-2/+2
| | | | MFC after: 1 week
* sh: Use PATH= assignment in type.jilles2009-12-311-1/+1
| | | | | Example: PATH=/var/empty; PATH=/bin type ls
* sh: Allow command -pv and command -pV (lookup using _PATH_STDPATH).jilles2009-12-313-7/+14
|
* sh: Ensure funcnest is decremented if there was an error in the function.jilles2009-12-301-2/+3
| | | | | | This will be important when things like 'command eval f' will be possible. Currently, the funcnest = 0 assignment in RESET (called when returning to the top level after an error in interactive mode) is really sufficient.
* Fix memory leak when parsing backticks (``).jilles2009-12-301-13/+23
|
* sh: arith: Return only 0 and 1 from && and ||.jilles2009-12-301-2/+2
| | | | This agrees with C, POSIX and other shells.
OpenPOWER on IntegriCloud