summaryrefslogtreecommitdiffstats
path: root/bin/sh
Commit message (Collapse)AuthorAgeFilesLines
* Explicitly add unmarked bin/ binaries to the runtime package.gjb2016-02-091-0/+1
| | | | | | | | Note: tcsh(1) has a MK_TCSH=no test, so this should be a separate package, which requires pre-install/post-install scripts, to be added later. Sponsored by: The FreeBSD Foundation
* Fix build.gjb2016-02-037-7/+0
| | | | Sponsored by: The FreeBSD Foundation
* MFHgjb2016-02-022-13/+41
|\ | | | | | | Sponsored by: The FreeBSD Foundation
| * sh: Don't allocate a redirtab if there are no redirections.jilles2016-01-301-7/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Builtins (including variable assignments without command word), function calls and redirected compound commands need to restore file descriptors to their original state after execution. This is handled by allocating a redirtab structure. These mallocs and frees show up heavily in pmcstat. Only allocate a redirtab if there are actually redirections and maintain a count of how many levels of REDIR_PUSH there are without redirtabs. A simple loop without external programs like sh -c 'i=0; w=$(printf %0100d 7); while [ "$i" -lt 1000000 ]; do i=$((i+1)); done' is over 25% faster on an amd64 bhyve VM.
| * sh(1): Document 'cd -'.jilles2016-01-301-6/+19
| | | | | | | | | | This reflects the changes in r294649 and can therefore not be MFCed by itself.
* | First pass to fix the 'tests' packages.gjb2016-02-028-0/+32
|/ | | | Sponsored by: The FreeBSD Foundation
* sh: Constify internal representation in expand.c.jilles2016-01-241-22/+28
| | | | | | | Forbid (temporary or permanent) modifications of the strings in NARG nodes during expansion. Tilde expansion now needs to copy the username for the terminating '\0'.
* sh: Remove a global variable from cd.c.jilles2016-01-241-14/+15
|
* sh: Use OLDPWD shell variable for 'cd -'.jilles2016-01-231-10/+9
| | | | | | | | Per POSIX, 'cd -' should use the OLDPWD shell variable, not internal state. This variable is normally exported. Also, if OLDPWD is not set, fail 'cd -' instead of changing to the current directory.
* sh: Clean a readonly local, even if the variable does not exist outside.jilles2016-01-223-0/+12
| | | | | If a local variable has been made read-only, this should not prevent its removal when the function returns.
* sh: Add already working test for local-readonly interaction.jilles2016-01-222-0/+11
|
* sh: Simplify some code related to positional parameters.jilles2016-01-192-17/+13
|
* sh: Update associated state when restoring locals while leaving a function.jilles2016-01-104-2/+29
| | | | | | | | Some variables like PATH call a function when modified. Make sure to call this also when leaving a function where such a variable was made local. Make sure to restore local variables before shellparam, so getopts state is not clobbered.
* sh: Reduce size of options table.jilles2016-01-074-71/+71
|
* sh: Add a test for 'cd -'.jilles2016-01-073-0/+11
| | | | | | Redirect 'cd -' output to /dev/null since POSIX requires it to write the new directory name even if not interactive, but we currently only write it if interactive.
* sh: Ensure OPTIND=1 in subshell without forking does not affect outer env.jilles2016-01-073-0/+19
| | | | | | | | | | | | Command substitutions containing a single simple command and here-document expansion are performed in a subshell environment, but may not fork. Any modified state of the shell environment should be restored afterward. The state that OPTIND=1 had been done was not saved and restored here. Note that the other parts of shellparam need not be saved and restored, since they are not modified in these situations (a fork is done before such modifications).
* sh: Link tests/builtins/getopts9.0 to the build.jilles2016-01-031-0/+1
| | | | This was forgotten in r273700.
* sh: Reduce size of builtins table.jilles2016-01-032-15/+12
|
* sh: Remove redundant CTLQUOTEMARK checks.jilles2015-12-311-18/+2
| | | | | | | | With the new expand.c code, the intermediate representation passed to the pathname generation code only contains CTLESC, not CTLQUOTEMARK. CTLQUOTEMARK now only occurs in the text of NARG nodes (output of the parser).
* sh: Reindent expandmeta().jilles2015-12-311-21/+21
|
* sh: Perform pathname generation during the first expansion phases.jilles2015-12-312-52/+57
| | | | | | | | This avoids the need to add and remove CTLESC bytes if pathname generation will not be performed (set -f). Side effect: the order of operations is slightly different: pathname generation in ${$+* $(CMD)} will not see filesystem changes from CMD.
* sh: Perform IFS splitting during the first expansion phases.jilles2015-12-311-362/+253
| | | | | | | | | This simplifies the code and should be faster in some cases. Side effect: the order of operations is different so that the value of IFS used when IFS is modified during expansion (${IFS:=...}, ${IFS=...} or $((...IFS=...))) may be different. Note that this order is highly unportable between shells.
* sh: Split subevalvar() in #/##/%/%% and =/? parts.jilles2015-12-291-28/+45
|
* sh: Add tests for #/##/%/%% on $* and $@.jilles2015-12-262-0/+62
| | | | | Although POSIX leaves things like ${*#X} unspecified, it occasionally occurs in practice. Add some tests that seem to work sensibly.
* sh/mknodes: Close files and check for errors when writing.jilles2015-12-201-5/+15
| | | | | | | This is a build tool only and does not affect run time. PR: 204951 MFC after: 1 week
* sh: Fix use-after-free when attempting to modify a read-only variable.jilles2015-12-161-1/+1
| | | | | Reported by: bapt MFC after: 1 week
* sh: Add limited test for ${#@} and ${#*}.jilles2015-12-062-0/+19
| | | | | POSIX leaves the result of expanding ${#@} and ${#*} unspecified, but ensure it is numeric.
* sh: Link tests/parameters/positional8.0 to the build.jilles2015-12-051-0/+1
| | | | This was forgotten in r291025.
* sh: Remove global state from nodes.c.jilles2015-11-242-38/+46
| | | | No functional change is intended.
* sh: Fix ""$@, which should not use the special case for "$@".jilles2015-11-182-1/+33
| | | | | "$@" should expand to no words if there are no positional parameters, but ""$@ should always expand to at least an empty word.
* sh: Avoid copying argv for simple commands.jilles2015-11-013-11/+11
| | | | | Add dummy entries before and after so arglist's array is directly usable as argv.
* Add more SUBDIR_PARALLEL.bdrewery2015-10-151-0/+2
| | | | | MFC after: 3 weeks Sponsored by: EMC / Isilon Storage Division
* Refactor the test/ Makefiles after recent changes to bsd.test.mk (r289158) andngie2015-10-121-2/+0
| | | | | | | | | | | | netbsd-tests.test.mk (r289151) - Eliminate explicit OBJTOP/SRCTOP setting - Convert all ad hoc NetBSD test integration over to netbsd-tests.test.mk - Remove unnecessary TESTSDIR setting - Use SRCTOP where possible for clarity MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Divison
* sh: Make struct arglist an array instead of a linked list.jilles2015-10-116-215/+136
| | | | | | | | | | | This simplifies the code (e.g. allowing use of qsort(3) instead of a hand-rolled mergesort) and should have better cache properties. The waste of unused args arrays after resizes is approximately the same as the savings from getting rid of the next pointers. At the same time, remove a piece of global state and move some duplicated code into a function.
* wordexp: Rewrite to make WRDE_NOCMD reliable.jilles2015-09-304-0/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Shell syntax is too complicated to detect command substitution and unquoted operators reliably without implementing much of sh's parser. Therefore, have sh do this detection. While changing sh's support anyway, also read input from a pipe instead of arguments to avoid {ARG_MAX} limits and improve privacy, and output count and length using 16 instead of 8 digits. The basic concept is: execl("/bin/sh", "sh", "-c", "freebsd_wordexp ${1:+\"$1\"} -f "$2", "", flags & WRDE_NOCMD ? "-p" : "", <pipe with words>); The WRDE_BADCHAR error is still implemented in libc. POSIX requires us to fail strings containing unquoted braces with code WRDE_BADCHAR. Since this is normally not a syntax error in sh, there is still a need for checking code in libc, we_check(). The new we_check() is an optimistic check that all the characters <newline> | & ; < > ( ) { } are quoted. To avoid duplicating too much sh logic, such characters are permitted when quoting characters are seen, even if the quoting characters may themselves be quoted. This code reports all WRDE_BADCHAR errors; bad characters that get past it and are a syntax error in sh return WRDE_SYNTAX. Although many implementations of WRDE_NOCMD erroneously allow some command substitutions (and ours even documented this), there appears to be code that relies on its security (codesearch.debian.net shows quite a few uses). Passing untrusted data to wordexp() still exposes a denial of service possibility and a fairly large attack surface. Reviewed by: wblock (man page only) MFC after: 2 weeks Relnotes: yes Security: fixes command execution with wordexp(untrusted, WRDE_NOCMD)
* sh: Allow empty << EOF markers.jilles2015-09-023-2/+30
|
* sh: Fix read with escaped IFS characters at the end.jilles2015-08-303-12/+28
| | | | | Characters escaped with a backslash must be treated as if they were not in IFS. This includes stripping trailing IFS characters.
* sh: Add set -o nolog.jilles2015-08-294-5/+15
| | | | | | | | | | POSIX requires this to prevent entering function definitions in history but this implementation does nothing except retain the option's value. In ksh88, function definitions were usually entered in the history file, even when they came from ~/.profile and the $ENV file, to allow displaying their definitions. This is also the first option that does not have a letter.
* sh: Fix out of bounds read when there is no ] after a [:class:].jilles2015-08-253-12/+17
| | | | | | | | | | | The initial check for a matching ] was incorrect if a ] may be consumed by a [:class:]. The subsequent loop assumed that there must be a ]. Remove the initial check and make the loop cope with a missing ]. Found with afl-fuzz. MFC after: 1 week
* sh: Don't create bad parse result when postponing a bad substitution error.jilles2015-08-234-2/+13
| | | | | | | | | | | | | | An invalid substitution like ${var@} does not cause a parse error but is stored in the intermediate representation, to be written as part of the error message. If there is a CTL* byte in the stored part, this confuses some code such as the code to skip an unused alternative such as in ${var-alternative}. To keep things simple, do not store CTL* bytes. Found with afl-fuzz. MFC after: 1 week
* sh: Avoid negative character values from $'\Uffffffff' etc.jilles2015-08-203-5/+15
| | | | | | | | | The negative value was not expected and generated the low 8 bits as a byte, which may be an invalid character encoding. The final shift in creating the negative value was undefined as well. Make the temporary variable unsigned to fix this.
* sh: Add test for $'\u' without any digits.jilles2015-08-202-0/+8
| | | | | It is likely that $'\uXXXX' and $'\UXXXXXXXX' will allow fewer digits in future. However, no digits at all should still be disallowed.
* sh: Backslash-newline should not affect field splitting in read builtin.jilles2015-08-163-2/+21
| | | | This was originally broken in r212339 in 2010.
* sh: When setting option via long name, don't go via letter.jilles2015-08-141-13/+20
| | | | | Looking up the letter makes no sense and prevents adding options that only have a long name, no letter.
* sh(1): libedit has supported multibyte encodings for a while.jilles2015-07-111-4/+2
|
* sh: Fix some arithmetic undefined behaviour.jilles2015-06-242-4/+3
| | | | | | | Fix shifts of possibly negative numbers found with ubsan and avoid signed integer overflow when hashing an extremely long command name. MFC after: 1 week
* Add META_MODE support.sjg2015-06-131-0/+114
|\ | | | | | | | | | | | | | | | | | | | | Off by default, build behaves normally. WITH_META_MODE we get auto objdir creation, the ability to start build from anywhere in the tree. Still need to add real targets under targets/ to build packages. Differential Revision: D2796 Reviewed by: brooks imp
| * dirdeps.mk now sets DEP_RELDIRsjg2015-06-081-2/+0
| |
| * Merge sync of headsjg2015-05-2740-192/+294
| |\ | |/ |/|
| * Merge from head@274682sjg2014-11-1956-419/+845
| |\
OpenPOWER on IntegriCloud