aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests
Commit message (Collapse)AuthorAgeFilesLines
* sh/tests: Add a second kind of binary scripts without #!Jilles Tjoelker2021-01-032-0/+11
| | | | | | | | One of the reasons for git commit e0f5c1387df23c8c4811f5b24a7ef6ecac51a71a was to make "actually portable executables" work. Add a test that is more like those. MFC after: 1 week
* sh: Write absolute path in command -vV and typeJilles Tjoelker2020-09-014-0/+42
| | | | | | | | | | | | POSIX is pretty clear that command -v, command -V and type shall write absolute pathnames. Therefore, we need to prepend the current directory's name to relative pathnames. This can happen either when PATH contains a relative pathname or when the operand contains a slash but is not an absolute pathname. Notes: svn path=/head/; revision=365037
* sh: Keep ignored SIGINT/SIGQUIT after set in a background jobJilles Tjoelker2020-08-282-0/+17
| | | | | | | | | | | | | | | | | | If job control is not enabled, a background job (... &) ignores SIGINT and SIGQUIT, but this can be reverted using the trap builtin in the same shell environment. Using the set builtin to change options would also revert SIGINT and SIGQUIT to their previous dispositions. This broke due to r317298. Calling setsignal() reverts the effect of ignoresig(). Reported by: bdrewery MFC after: 1 week Notes: svn path=/head/; revision=364919
* sh/tests: Re-enable bin.sh.execution.functional_test.bg12.0Jilles Tjoelker2020-06-281-15/+1
| | | | | | | | | | This reverts r362646. PR: 247559 MFC after: 1 week Notes: svn path=/head/; revision=362738
* sh/tests: Fix flaky execution/bg12.0Jilles Tjoelker2020-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | When job control is not enabled, the shell ignores SIGINT while waiting for a foreground process unless that process exits on SIGINT. In this case, the foreground process is sleep and it does not exit on SIGINT because the signal is only sent to the shell. Depending on order of events, this could cause the SIGINT to be unexpectedly ignored. On lightly loaded bare metal, the chance of this happening tends to be less than 0.01% but with higher loads and/or virtualization it becomes more likely. Starting the sleep in background and using the wait builtin ensures SIGINT will not be ignored. PR: 247559 Reported by: lwhsu MFC after: 1 week Notes: svn path=/head/; revision=362737
* Temporarily skip flakey bin.sh.execution.functional_test.bg12 in CILi-Wen Hsu2020-06-261-1/+15
| | | | | | | | PR: 238870 Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=362646
* sh/tests: Add tests for SIGINT in non-jobc background commandsJilles Tjoelker2020-06-143-0/+30
| | | | | | | | | | If job control is not enabled, background commands shall ignore SIGINT and SIGQUIT, and it shall be possible to override that ignore in the same shell. MFC after: 1 week Notes: svn path=/head/; revision=362182
* sh: Allow more scripts without #!Jilles Tjoelker2020-05-302-0/+9
| | | | | | | | | | | | | | | | | | | Austin Group bugs #1226 and #1250 changed the requirements for shell scripts without #! (POSIX does not specify #!; this is about the shell execution when execve(2) returns an [ENOEXEC] error). POSIX says we shall allow execution if the initial part intended to be parsed by the shell consists of characters and does not contain the NUL character. This allows concatenating a shell script (ending with exec or exit) and a binary payload. In order to reject common binary files such as PNG images, check that there is a lowercase letter or expansion before the last newline before the NUL character, in addition to the check for the newline character suggested by POSIX. Notes: svn path=/head/; revision=361647
* sh: Fix double INTON with vforkJilles Tjoelker2020-05-162-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | The shell maintains a count of the number of times SIGINT processing has been disabled via INTOFF, so SIGINT processing resumes when all disables have enabled again (INTON). If an error occurs in a vfork() child, the processing of the error enables SIGINT processing again, and the INTON in vforkexecshell() causes the count to become negative. As a result, a later INTOFF may not actually disable SIGINT processing. This might cause memory corruption if a SIGINT arrives at an inopportune time. As of r360452, it causes the shell to abort when it would unsafely allocate or free memory in certain ways. Note that various places such as errors in non-special builtins unconditionally reset the count to 0, so the problem might still not always be visible. PR: 246497 Reported by: jbeich MFC after: 2 weeks Notes: svn path=/head/; revision=361112
* sh/tests: Test some obscure cases with aliasing keywordsJilles Tjoelker2020-05-125-0/+21
| | | | Notes: svn path=/head/; revision=360992
* sh: Test that executing various binary files is rejectedJilles Tjoelker2019-12-305-0/+64
| | | | | | | | | | | | | | | If executing a file fails with an [ENOEXEC] error, the shell executes the file as a shell script, except that this execution may instead result in an error message if the file is binary. Per a recent Austin Group interpretation, we will need to change this to allow a concatenation of a shell script and a binary payload. See Austin Group bugs #1226 and #1250. MFC after: 1 week Notes: svn path=/head/; revision=356208
* sh/tests: Improve failure messages of expansion/arith15.0Jilles Tjoelker2019-03-071-3/+3
| | | | Notes: svn path=/head/; revision=344902
* sh: Add set -o pipefailJilles Tjoelker2019-02-248-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pipefail option allows checking the exit status of all commands in a pipeline more easily, at a limited cost of complexity in sh itself. It works similarly to the option in bash, ksh93 and mksh. Like ksh93 and unlike bash and mksh, the state of the option is saved when a pipeline is started. Therefore, even in the case of commands like A | B & a later change of the option does not change the exit status, the same way (A | B) & works. Since SIGPIPE is not handled specially, more work in the script is required for a proper exit status for pipelines containing commands such as head that may terminate successfully without reading all input. This can be something like ( cmd1 r=$? if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then exit 0 else exit "$r" fi ) | head PR: 224270 Relnotes: yes Notes: svn path=/head/; revision=344502
* sh: Restore $((x)) error checking after fix for $((-9223372036854775808))Jilles Tjoelker2019-02-103-0/+31
| | | | | | | | | | | | | | | | | | SVN r342880 was designed to fix $((-9223372036854775808)) and things like $((0x8000000000000000)) but also broke error detection for values of variables without dollar sign ($((x))). For compatibility, overflow in plain literals continues to be ignored and the value is clamped to the boundary (except 9223372036854775808 which is changed to -9223372036854775808). Reviewed by: se (although he would like error checking to be removed) MFC after: 2 weeks X-MFC-with: r342880 Differential Revision: https://reviews.freebsd.org/D18926 Notes: svn path=/head/; revision=343981
* Fix an edge case when parsing large numbers which resulted in inconsistentDag-Erling Smørgrav2019-01-092-0/+21
| | | | | | | | | | | results between an expression that refers to a variable by name and the same expression that includes the same variable by value. Submitted by: se@ MFC after: 1 week Notes: svn path=/head/; revision=342880
* sh: Add test for exported but unset variablesJilles Tjoelker2019-01-032-0/+6
| | | | | | | PR: 233545 Notes: svn path=/head/; revision=342741
* sh: Fix ${param?} default error messageJilles Tjoelker2018-11-282-0/+12
| | | | | | | | | | | | | | | If word in ${param?word} is missing, the shell shall write a default error message. So expanding ${param?} when param is not set should write an error message like sh: param: parameter not set This was broken by r316417. PR: 233585 Notes: svn path=/head/; revision=341164
* sh: Use 126 and 127 exit status for failures opening a scriptJilles Tjoelker2018-11-272-0/+6
| | | | | | | | | | This affects scripts named on the command line, named with a '.' special builtin and found via the PATH %func autoloading mechanism. PR: 231986 Notes: svn path=/head/; revision=341097
* sh: Don't treat % specially in CDPATHJilles Tjoelker2018-07-152-0/+25
| | | | Notes: svn path=/head/; revision=336320
* sh: Allow unquoted newlines in word in ${param+word} etc.Jilles Tjoelker2018-05-204-0/+25
| | | | | | | | | | | | | | | | | | | POSIX requires accepting unquoted newlines in word in parameter expansions like ${param+word}, ${param#word}, although the Bourne shell did not support it, it is not commonly used and might make it harder to find a missing closing brace. It was also strange that something like foo="${bar# }" was rejected. Reported by: Martijn Dekker via Robert Elz Notes: svn path=/head/; revision=333927
* sh: Test that backslash-newline within single-quotes is not specialJilles Tjoelker2018-05-112-0/+6
| | | | | | | This works correctly, but the test may be helpful when modifying the parser. Notes: svn path=/head/; revision=333507
* sh: Don't have [ match any [[:class:]]Jilles Tjoelker2018-04-292-0/+6
| | | | | | | | Submitted by: Robert Elz MFC after: 3 days Notes: svn path=/head/; revision=333092
* Fix a few speelling errorsEitan Adler2017-12-281-1/+1
| | | | | | | | | | - man pages - bin/sh Reviewed by: jilles Notes: svn path=/head/; revision=327281
* DIRDEPS_BUILD: Connect new directories.Bryan Drewery2017-10-311-0/+11
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325187
* sh: Add test for sh -c with missing command string.Jilles Tjoelker2017-08-132-0/+4
| | | | | | | This already works correctly. Notes: svn path=/head/; revision=322455
* sh: Add tests for sh -c that already pass.Jilles Tjoelker2017-08-126-0/+41
| | | | | | | | PR: 220587 Submitted by: Ryan Moeller Notes: svn path=/head/; revision=322438
* sh: Ignore error when cd writes the directory actually switched to.Jilles Tjoelker2017-06-252-0/+7
| | | | | | | | | | | | If CDPATH is used non-trivially or the operand is "-", cd writes the directory actually switched to. (We currently do this only in interactive shells, but POSIX requires this in non-interactive shells as well.) As mentioned in Austin group bug #1045, cd shall not return an error while leaving the current directory changed. Therefore, ignore any write error. Notes: svn path=/head/; revision=320340
* sh: Fix INTOFF leak when a redirection on a compound command fails.Jilles Tjoelker2017-06-042-0/+6
| | | | | | | Reported by: bdrewery Notes: svn path=/head/; revision=319575
* sh: Fix '-' from quoted arithmetic in case/glob pattern range.Jilles Tjoelker2017-05-142-0/+11
| | | | | | | | | | | It does not make much sense to generate the '-' in a pattern bracket expression using arithmetic expansion, but it does not make sense to forbid it either. Try to avoid reprocessing the string if it is unnecessary. Notes: svn path=/head/; revision=318269
* sh: Add test for arithmetic expansion in [x-y] pattern range.Jilles Tjoelker2017-05-132-0/+11
| | | | | | | | | | | It does not make much sense to generate the '-' in a pattern bracket expression using arithmetic expansion, but it does not make sense to forbid it either. This test already passes. Notes: svn path=/head/; revision=318258
* sh: Fix INTOFF leak after a builtin with different locale settings.Jilles Tjoelker2017-05-072-0/+6
| | | | | | | | | | | After executing a builtin with different locale settings such as LC_ALL=C true SIGINT handling was left disabled indefinitely. MFC after: 1 week Notes: svn path=/head/; revision=317912
* sh: Add some tests for command substitution final newline stripping.Jilles Tjoelker2017-04-273-0/+15
| | | | Notes: svn path=/head/; revision=317514
* sh: Add tests for NUL byte in command substitution output.Jilles Tjoelker2017-04-232-0/+25
| | | | Notes: svn path=/head/; revision=317347
* sh: Fix use after free when resetting an in-use alias.Jilles Tjoelker2017-04-162-0/+9
| | | | | | | | | The special case of modifying an existing alias does not work correctly if the alias is currently in use. Instead, handle this case by unaliasing the old alias (if any) and then creating a new alias. Notes: svn path=/head/; revision=317039
* sh: Link the new test to the build.Jilles Tjoelker2017-04-161-0/+1
| | | | Notes: svn path=/head/; revision=317038
* sh: Fix unalias -a while an alias is currently in use.Jilles Tjoelker2017-04-161-0/+7
| | | | | | | | It is a rare situation to modify aliases while an alias is currently in use, but this is handled for plain unalias. Handle it for unalias -a as well. Notes: svn path=/head/; revision=317037
* sh: Add test for unaliasing an alias that is currently in use.Jilles Tjoelker2017-04-082-0/+8
| | | | | | | This already works correctly. Notes: svn path=/head/; revision=316646
* sh: Fix executing wrong command with ${unsetvar#$(cmdsubst)}$(cmdsubst).Jilles Tjoelker2017-03-102-0/+6
| | | | | | | | | | | | | | | | | | | | | The parsed internal representation of words consists of a byte string with a list of nodes (commands in command substitution). Each unescaped CTLBACKQ or CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list. If param in ${param#%##%%word} is not set, the word is not expanded (in a deviation of POSIX shared with other ash variants and ksh93). Erroneously, the pointer in the list of commands (argbackq) was not advanced. This caused the wrong command to be executed later if the outer word contained another command substitution. Example: echo "${unsetvar#$(echo a)}$(echo b)" wrote "a" but should write "b". MFC after: 1 week Notes: svn path=/head/; revision=315005
* sh: Fix crash if a -T trap is taken during command substitution.Jilles Tjoelker2017-03-043-0/+14
| | | | | | | | | | | | | | | | | | | Code like t=$(stat -f %m "$file") segfaulted if -T was active and a trap was taken while the shell was waiting for the child process to finish. What happened was that the dotrap() call in waitforjob() was hit. This re-entered command execution (including expand.c) at a point not expected by expbackq(), and global state (unallocated stack string and argbackq) was corrupted. To fix this, change expbackq() to prepare for command execution to be re-entered. Reported by: bdrewery MFC after: 1 week Notes: svn path=/head/; revision=314686
* sh: Add some already working tests that exercise new code paths.Jilles Tjoelker2017-03-034-0/+20
| | | | Notes: svn path=/head/; revision=314637
* sh: Add simple test for 'set -C' (noclobber).Jilles Tjoelker2016-11-022-0/+13
| | | | | | | To ensure fast test runs, race conditions are not tested. Notes: svn path=/head/; revision=308229
* sh: Do not import IFS's value from the environment.Jilles Tjoelker2016-10-082-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | Per Austin group issue #884, always set IFS to $' \t\n'. As before, IFS will be exported iff it was in the environment. Most shells (e.g. bash, ksh93 and mksh) already did this. This change improves predictability, in that scripts can simply rely on the default value. However, the effect on security is little, since applications should not be calling the shell with attacker-controlled environment variable names in the first place and other security-sensitive variables such as PATH should be and are imported by the shell. When using a new sh with an old (before 10.2) libc wordexp(), IFS is no longer passed on. Otherwise, wordexp() continues to pass along IFS from the environment per its documentation. Discussed with: pfg Relnotes: yes Notes: svn path=/head/; revision=306843
* sh: Add some tests for non-standard features of the echo builtin.Jilles Tjoelker2016-09-024-0/+21
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=305305
* Path generation was not according to collateAndrey A. Chernov2016-07-164-0/+38
| | | | | | | Approved by: jilles Notes: svn path=/head/; revision=302937
* Back out non-collating [a-z] ranges.Andrey A. Chernov2016-07-141-1/+6
| | | | | | | | | | | Instead of changing the whole course to another POSIX-permitted way for consistency and uniformity I decide to completely ignore missing regex fucntionality and focus on fixing bugs in what we have now, too many small obstacles we have choicing other way, counting ports. Corresponding libc changes are backed out in r302824. Notes: svn path=/head/; revision=302829
* After removing collation for [a-z] ranges in r302512, do it here too.Andrey A. Chernov2016-07-131-6/+1
| | | | | | | Approved by: jilles Notes: svn path=/head/; revision=302712
* Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installedEnji Cooper2016-05-048-474/+449
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | after r298107 Summary of changes: - Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that namespacing is kept with FILES appropriately, and that this shouldn't need to be repeated if the namespace changes -- only the definition of PACKAGE needs to be changed - Allow PACKAGE to be overridden by callers instead of forcing it to always be `tests`. In the event we get to the point where things can be split up enough in the base system, it would make more sense to group the tests with the blocks they're a part of, e.g. byacc with byacc-tests, etc - Remove PACKAGE definitions where possible, i.e. where FILES wasn't used previously. - Remove unnecessary TESTSPACKAGE definitions; this has been elided into bsd.tests.mk - Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES; ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk. - Fix installation of files under data/ subdirectories in lib/libc/tests/hash and lib/libc/tests/net/getaddrinfo - Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup) Document the proposed changes in share/examples/tests/tests/... via examples so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of replacing FILES. share/mk/bsd.README didn't seem like the appropriate method of communicating that info. MFC after: never probably X-MFC with: r298107 PR: 209114 Relnotes: yes Tested with: buildworld, installworld, checkworld; buildworld, packageworld Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=299094
* MFHGlen Barber2016-04-113-7/+7
|\ | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=297824
| * sh: Fix some unquoted variables in tests.Jilles Tjoelker2016-04-093-7/+7
| | | | | | | | | | | | | | | | The builtins/getopts1.0 test failed if a single-character file existed in the current directory. Notes: svn path=/head/; revision=297752
* | MFHGlen Barber2016-04-042-0/+11
|\| | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=297567