aboutsummaryrefslogtreecommitdiff
path: root/bin/sh/tests/builtins/Makefile
Commit message (Collapse)AuthorAgeFilesLines
* sh: Don't assume EINTR means SIGALRMDag-Erling Smørgrav2025-11-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | While waiting for input in the read builtin, if select() is interrupted but there is no pending signal, we act like we timed out, and return the same status as if we had been interrupted by SIGALRM, instead of looping until we actually do time out. * Replace the single select() call with a ppoll() loop. * Improve validation of the timeout value. We now accept things like "1h30m15s", which we used to silently truncate to "1h". The flip side is that we no longer accept things like "1hour" or "5sec". * Modify the existing `read -t 0` test case to verify that read returns immediately when there is input and fails immediately when there isn't. * Add a second test case which performs the same tests with a non-zero timeout value. PR: 290844 MFC after: 1 week Fixes: c4539460e3a4 ("sh: Improve error handling in read builtin:") Reviewed by: jilles, bdrewery Differential Revision: https://reviews.freebsd.org/D53761
* sh: Fix a double free in a rare scenario with pipesJilles Tjoelker2025-11-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The command sh -c 'sleep 3 | sleep 2 & sleep 3 & kill %1; wait %1' crashes (with appropriate sanitization such as putting MALLOC_CONF=abort:true,junk:true in the environment or compiling with -fsanitize=address). What happens here is that waitcmdloop() calls dowait() with a NULL job pointer, instructing dowait() to freejob() if it's a non-interactive shell and $! was not and cannot be referenced for it. However, waitcmdloop() then uses fields possibly freed by freejob() and calls freejob() again. This only occurs if the job being waited for is identified via % syntax ($! has never been referenced for it), it is a pipeline with two or more elements and another background job has been started before the wait command. That seems special enough for a bug to remain. Test scripts written by Jilles would almost always use $! and not % syntax. We can instead make waitcmdloop() pass its job pointer to dowait(), fixing up things for that (waitcmdloop() will have to call deljob() if it does not call freejob()). The crash from https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=290330#c2 appears to be the same bug. PR: 290330 Reported by: bdrewery Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D53773
* sh(1): Do not interpret chdir to "" as equivalent to chdir with no argumentXin LI2025-07-021-0/+1
| | | | | | | | | | | | | | | | | | | | A script that does the following: cd "${dir}" || exit 1 would incorrectly remain in the current directory when `${dir}` is an empty string under the current implementation. This behavior, while historical, is potentially dangerous, as it is likely not what the script author intended. Change the command to treat an empty string as an error and emit a diagnostic message to standard error, as required by IEEE Std 1003.1-2024. PR: standards/287440 Test Plan: kyua test bin/sh Relnotes: yes Differential Revision: https://reviews.freebsd.org/D50974
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* sh: accept fc options grouped behind one '-'Piotr Pawel Stefaniak2022-08-201-0/+1
| | | | | | | | | | | | | | | As per Utility Syntax Guidelines, accept both forms: -l -n and -ln. To do that, anticipate the source string for the next option that will be parsed by nextopt(). It's not always *argptr, sometimes it is nextopt_optptr. To simplify the check for not_fcnumber, slightly modify nextopt() to always nullify nextopt_optptr in cases where it would have been set to point to a NUL character. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D35836
* read builtin: Empty variables on timeoutBryan Drewery2021-09-241-0/+2
| | | | | | | | This matches how a non-timeout error is handled. Reviewed by: jilles MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D31876
* sh: Write absolute path in command -vV and typeJilles Tjoelker2020-09-011-0/+3
| | | | | | | | | | | | 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: Don't treat % specially in CDPATHJilles Tjoelker2018-07-151-0/+1
| | | | Notes: svn path=/head/; revision=336320
* sh: Don't have [ match any [[:class:]]Jilles Tjoelker2018-04-291-0/+1
| | | | | | | | Submitted by: Robert Elz MFC after: 3 days Notes: svn path=/head/; revision=333092
* sh: Ignore error when cd writes the directory actually switched to.Jilles Tjoelker2017-06-251-0/+1
| | | | | | | | | | | | 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 '-' from quoted arithmetic in case/glob pattern range.Jilles Tjoelker2017-05-141-0/+1
| | | | | | | | | | | 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-131-0/+1
| | | | | | | | | | | 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-071-0/+1
| | | | | | | | | | | 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 non-standard features of the echo builtin.Jilles Tjoelker2016-09-021-0/+3
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=305305
* Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installedEnji Cooper2016-05-041-168/+165
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-041-0/+1
|\ | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=297567
| * sh: Fix use-after-free if a trap replaces itself.Jilles Tjoelker2016-03-281-0/+1
| | | | | | | | | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=297360
* | MFHGlen Barber2016-03-101-0/+1
|\| | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=296625
| * sh: Add test for 'set -o nolog'.Jilles Tjoelker2016-03-091-0/+1
| | | | | | | | | | | | | | | | The option does not do anything so check that the output of 'set +o' is different. Notes: svn path=/head/; revision=296578
* | Fix build.Glen Barber2016-02-031-1/+0
| | | | | | | | | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295215
* | First pass to fix the 'tests' packages.Glen Barber2016-02-021-0/+4
|/ | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/projects/release-pkg/; revision=295171
* sh: Clean a readonly local, even if the variable does not exist outside.Jilles Tjoelker2016-01-221-0/+1
| | | | | | | | If a local variable has been made read-only, this should not prevent its removal when the function returns. Notes: svn path=/head/; revision=294593
* sh: Add already working test for local-readonly interaction.Jilles Tjoelker2016-01-221-0/+1
| | | | Notes: svn path=/head/; revision=294582
* sh: Update associated state when restoring locals while leaving a function.Jilles Tjoelker2016-01-101-0/+1
| | | | | | | | | | | 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. Notes: svn path=/head/; revision=293635
* sh: Add a test for 'cd -'.Jilles Tjoelker2016-01-071-0/+1
| | | | | | | | | 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. Notes: svn path=/head/; revision=293371
* sh: Ensure OPTIND=1 in subshell without forking does not affect outer env.Jilles Tjoelker2016-01-071-0/+1
| | | | | | | | | | | | | | | 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). Notes: svn path=/head/; revision=293359
* sh: Link tests/builtins/getopts9.0 to the build.Jilles Tjoelker2016-01-031-0/+1
| | | | | | | This was forgotten in r273700. Notes: svn path=/head/; revision=293120
* sh: Fix read with escaped IFS characters at the end.Jilles Tjoelker2015-08-301-0/+1
| | | | | | | | Characters escaped with a backslash must be treated as if they were not in IFS. This includes stripping trailing IFS characters. Notes: svn path=/head/; revision=287308
* sh: Fix out of bounds read when there is no ] after a [:class:].Jilles Tjoelker2015-08-251-0/+1
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=287148
* sh: Backslash-newline should not affect field splitting in read builtin.Jilles Tjoelker2015-08-161-0/+1
| | | | | | | This was originally broken in r212339 in 2010. Notes: svn path=/head/; revision=286826
* sh: Fix the trap builtin to be POSIX-compliant for 'trap exit SIG' and 'trap ↵Bryan Drewery2015-04-181-0/+2
| | | | | | | | | | | | | | | | | | | | n n...'. The parser considered 'trap exit INT' to reset the default for both EXIT and INT. This beahvior is not POSIX compliant. This was avoided if a value was specified for 'exit', but then disallows exiting with the signal received. A possible workaround is using ' exit'. However POSIX does allow this type of behavior if the parameters are all integers. Fix the handling for this and clarify its support in the manpage since it is specifically allowed by POSIX. Differential Revision: https://reviews.freebsd.org/D2325 Reviewed by: jilles MFC after: 2 weeks Notes: svn path=/head/; revision=281718
* sh: Fix break/continue/return in multiline eval.Jilles Tjoelker2014-10-121-0/+2
| | | | | | | | Example: eval $'return\necho bad' Notes: svn path=/head/; revision=272983
* sh: Fix LINENO and prompt after $'\0 and newline.Jilles Tjoelker2014-10-031-0/+1
| | | | Notes: svn path=/head/; revision=272482
* Convert bin/sh/tests to ATFEnji Cooper2014-08-131-3/+7
| | | | | | | | | | | | | | | | The new code uses a "test discovery mechanism" to determine what tests are available for execution The test shell can be specified via: kyua test -v test_suites.FreeBSD.bin.sh.test_shell=/path/to/test/sh Sponsored by: EMC / Isilon Storage Division Approved by: jmmv (mentor) Reviewed by: jilles (maintainer) Notes: svn path=/head/; revision=269902
* sh: Allow arbitrarily large numbers in break and continue.Jilles Tjoelker2014-07-201-0/+1
| | | | | | | The argument is capped to loopnest, so strtol()'s [ERANGE] can be ignored. Notes: svn path=/head/; revision=268927
* Don't install locale1.0 if MK_NLS == no.Jilles Tjoelker2014-07-081-0/+2
| | | | | | | | | | | | | | | The test locale1.0 depends on locale support; it is meaningless without a working LC_MESSAGES. I added an OptionalObsoleteFiles.inc entry. PR: 181151 Submitted by: Garrett Cooper (original version) MFC after: 1 week Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=268429
* sh: In getopts, unset OPTARG where POSIX says we should.Jilles Tjoelker2014-05-101-0/+1
| | | | Notes: svn path=/head/; revision=265849
* sh: Add new tests to the Makefile.Jilles Tjoelker2014-05-101-0/+2
| | | | Notes: svn path=/head/; revision=265846
* sh: Add some tests for normal use of getopts.Jilles Tjoelker2014-05-071-0/+3
| | | | Notes: svn path=/head/; revision=265616
* sh: Allow kill %job on jobs started without job control.Jilles Tjoelker2014-03-151-1/+1
| | | | | | | | | | | When killing a %job started without job control, kill all processes in it. As with process groups and zombies, if any process in the job can be killed or has already terminated, the command is successful. This also fixes occasional failures of the builtins/kill1.0 test. Notes: svn path=/head/; revision=263206
* sh: Successfully do nothing when killing a terminated job.Jilles Tjoelker2014-03-081-0/+1
| | | | | | | | | If a job has terminated but is still known, silently do nothing when using the kill builtin with the job specifier. Formerly, the shell called kill() with the process group ID that might have been reused. Notes: svn path=/head/; revision=262931
* sh: Do not corrupt internal representation if LINENO inner expansion fails.Jilles Tjoelker2014-02-271-0/+1
| | | | | | | | | Example: f() { : ${LINENO+$((1/0))}; } and call this function twice. Notes: svn path=/head/; revision=262565
* Migrate tools/regression/bin/ tests to the new layout.Julio Merino2013-12-111-0/+147
This change is a proof of concept on how to easily integrate existing tests from the tools/regression/ hierarchy into the /usr/tests/ test suite and on how to adapt them to the new layout for src. To achieve these goals, this change: - Moves tests from tools/regression/bin/<tool>/ to bin/<tool>/tests/. - Renames the previous regress.sh files to legacy_test.sh. - Adds Makefiles to build and install the tests and all their supporting data files into /usr/tests/bin/. - Plugs the legacy_test test programs into the test suite using the new TAP backend for Kyua (appearing in 0.8) so that the code of the test programs does not have to change. - Registers the new directories in the BSD.test.dist mtree file. Reviewed by: freebsd-testing Approved by: rpaulo (mentor) Notes: svn path=/head/; revision=259210