| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
| |
Calling dotrap() can do almost anything, including reallocating the
jobtab array. Convert the job pointer to an index before calling
dotrap() and then restore a proper job pointer afterwards.
PR: 290330
Reported by: bdrewery
Reviewed by: bdrewery
Differential Revision: https://reviews.freebsd.org/D53793
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
| |
This change follows a localized approach within getprompt() and avoids
full parser reentry. While this means we don't support advanced
expansions like ${parameter#pattern}, it provides POSIX-compliant basic
parameter expansion without the complexity of making the parser
reentrant. This is sufficient for the vast majority of use cases.
PR: 46441
|
| |
|
|
|
|
|
|
|
| |
This was sometimes exiting while the child fifo was created resulting in
[ENOTEMPTY] from rm. The child fifo isn't needed, just sleep.
PR: 290837
Fixes: e31fb97148f ("read builtin: Empty variables on timeout")
MFC after: 3 days
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
| |
MALLOC_OPTIONS=J -> MALLOC_CONF=junk:true
PR: 287357
Reviewed by: markj
Event: Kitchener-Waterloo Hackathon 202506
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D50910
|
| |
|
|
|
|
|
|
|
|
| |
Some sh tests use ktrace to see whether a particular file, specified in
the environment, was accessed by the shell. After commit 65a4daeaf324,
this test matches the ktrace record generated by execve.
Use ktrace to only log name lookups, to avoid such false matches.
Fixes: 65a4daeaf324 ("ktrace: log execve(2) arguments and environment")
|
| |
|
|
|
|
|
| |
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
|
| |
|
|
| |
Fixes: d0b2dbfa0ecf ("Remove $FreeBSD$: one-line sh pattern")
|
| |
|
|
| |
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
|
| |
|
|
|
|
|
|
| |
This is to avoid loading .shrc which may contain commands that would
result in output different than expected.
Reviewed by: jilles
Differential Revision: https://reviews.freebsd.org/D35876
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
| |
After an unescaped newline, there may be a here-document. Some places in
case and for did not check for one.
Reviewed by: bdrewery
Differential Revision: https://reviews.freebsd.org/D32628
|
| |
|
|
|
|
|
|
| |
This matches how a non-timeout error is handled.
Reviewed by: jilles
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D31876
|
| |
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
| |
This reverts r362646.
PR: 247559
MFC after: 1 week
Notes:
svn path=/head/; revision=362738
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
| |
PR: 238870
Sponsored by: The FreeBSD Foundation
Notes:
svn path=/head/; revision=362646
|
| |
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
| |
Notes:
svn path=/head/; revision=360992
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
| |
Notes:
svn path=/head/; revision=344902
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
| |
PR: 233545
Notes:
svn path=/head/; revision=342741
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
| |
Notes:
svn path=/head/; revision=336320
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
| |
This works correctly, but the test may be helpful when modifying the parser.
Notes:
svn path=/head/; revision=333507
|
| |
|
|
|
|
|
|
| |
Submitted by: Robert Elz
MFC after: 3 days
Notes:
svn path=/head/; revision=333092
|
| |
|
|
|
|
|
|
|
|
| |
- man pages
- bin/sh
Reviewed by: jilles
Notes:
svn path=/head/; revision=327281
|
| |
|
|
|
|
|
| |
Sponsored by: Dell EMC Isilon
Notes:
svn path=/head/; revision=325187
|
| |
|
|
|
|
|
| |
This already works correctly.
Notes:
svn path=/head/; revision=322455
|
| |
|
|
|
|
|
|
| |
PR: 220587
Submitted by: Ryan Moeller
Notes:
svn path=/head/; revision=322438
|
| |
|
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
| |
Reported by: bdrewery
Notes:
svn path=/head/; revision=319575
|
| |
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
| |
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
|
| |
|
|
| |
Notes:
svn path=/head/; revision=317514
|
| |
|
|
| |
Notes:
svn path=/head/; revision=317347
|
| |
|
|
|
|
|
|
|
| |
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
|
| |
|
|
| |
Notes:
svn path=/head/; revision=317038
|