Age | Commit message (Collapse) | Author | Files | Lines |
|
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
of braces
[ dash commit 7710a926b321879b84bf349b865b1dd4c52083f8 ]
On Thu, Apr 25, 2019 at 01:39:52AM +0000, Michael Orlitzky wrote:
> The POSIX spec says,
>
> The parameter name or symbol can be enclosed in braces, which are
> optional except for positional parameters with more than one digit or
> when parameter is a name and is followed by a character that could be
> interpreted as part of the name.
>
> However, dash seems to diverge from that behavior when we get to $10:
>
> $ cat test.sh
> echo $10
>
> $ dash ./test.sh one two three four five six seven eight nine ten
> ten
>
> $ bash ./test.sh one two three four five six seven eight nine ten
> one0
This patch should fix the problem.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit c4f4ee8ecf85834811c252fc1df3892863572bbd ]
According to POSIX.1-2008 we should remove newlines only at the end of
the substitution. Newlines-only substitions causes dash to remove
newlines before beggining of the substitution. The following code:
cat <<END
1
$(echo "")
2
END
prints "1<newline>2" instead of expected "1<newline><newline>2".
This patch fixes trailing newlines processing in backquote expanding.
Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit b9f8565be338c172c3bd8a96d3fe3e3ab4775120 ]
On Wed, Jul 25, 2018 at 12:38:27PM +0000, project-repo wrote:
> Hi,
> I am working on a project in which I use the honggfuzz fuzzer to fuzz open
> source software and I decided to fuzz dash. In doing so I discovered a
> NULL pointer dereference in src/redir.ch on line 305. Following is a
> backtrace as supplied by the address sanitizer:
>
> AddressSanitizer:DEADLYSIGNAL
> =================================================================
> ==39623==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000010 (pc 0x0000005768ed bp 0x7ffc00273df0 sp 0x7ffc00273c60 T0)
> ==39623==The signal is caused by a READ memory access.
> ==39623==Hint: address points to the zero page.
> #0 0x5768ec in openhere /home/jfe/dash/src/redir.c:305:29
> #1 0x574d92 in openredirect /home/jfe/dash/src/redir.c:230:7
> #2 0x5737fe in redirect /home/jfe/dash/src/redir.c:121:11
> #3 0x576017 in redirectsafe /home/jfe/dash/src/redir.c:424:3
> #4 0x522326 in evalcommand /home/jfe/dash/src/eval.c:828:11
> #5 0x520010 in evaltree /home/jfe/dash/src/eval.c:288:12
> #6 0x5270da in evaltreenr /home/jfe/dash/src/eval.c:332:2
> #7 0x526f04 in evalbackcmd /home/jfe/dash/src/eval.c:640:3
> #8 0x539020 in expbackq /home/jfe/dash/src/expand.c:522:2
> #9 0x5332d7 in argstr /home/jfe/dash/src/expand.c:343:4
> #10 0x5322f7 in expandarg /home/jfe/dash/src/expand.c:196:2
> #11 0x528118 in fill_arglist /home/jfe/dash/src/eval.c:659:3
> #12 0x5213b6 in evalcommand /home/jfe/dash/src/eval.c:769:13
> #13 0x520010 in evaltree /home/jfe/dash/src/eval.c:288:12
> #14 0x554423 in cmdloop /home/jfe/dash/src/main.c:234:8
> #15 0x553bcc in main /home/jfe/dash/src/main.c:176:3
> #16 0x7f201c2b2a86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21a86)
> #17 0x41dfb9 in _start (/home/jfe/dash/src/dash+0x41dfb9)
>
> AddressSanitizer can not provide additional info.
> SUMMARY: AddressSanitizer: SEGV /home/jfe/dash/src/redir.c:305:29 in openhere
> ==39623==ABORTING
>
> This bug can be reproduced by running "dash < min" where min is þhe file
> attached. I was able to reproduce this bug with the current git version
> and the current debian version.
>
> cheers
> project-repo
>
> <<A
> `<<A(`
Thanks for the report! This is caused by the recent change to
save/restore here-docment list around command substitutions. In
doing so we must finish existing here-documents prior to restoring
the old here-document list. This is done for new-style command
substitutions but not for old-style.
This patch fixes it by doing it for both.
Reported-by: project-repo <bugs@feusi.co>
Fixes: 51e2d88d6e51 ("parser: Save/restore here-documents in...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 02a00569ba60e502f876c36d894ba0cc2d0682b3 ]
As it is a subshell can execute code that is only meant for the
parent shell when it executes a longjmp that is caught by something
like evalcommand. This patch fixes it by resetting the handler
when entering a subshell.
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 86a841bb444ed1d9a09afb38cb818a21c04e1beb ]
Due to a double decrement in argstr we may miss field separators
at the end of a word in certain situations.
Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: 3cd538634f71 ("expand: Do not reprocess data when...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit e7a5030483e039971aad59db3fc238c3051bd565 ]
We set commandname in procargs when we don't have to. This results
in a duplicated output of arg0 when an error occurs.
Reported-by: Olivier Duclos <odc@fastmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 48875c1201930d1e71d358eb1cf3eacc166795be ]
The value of REALLY_CLOSED is used to avoid an unnecessary close(2)
call when restoring redirections. However, as it stands it can
remove a close(2) call that's actually needed. This happens when
an enclosed exec(1) command leaves an open file descriptor behind.
This patch fixes this by replacing REALLY_CLOSED with closed_redirs
to track the current status of redirected file descriptors and
leaving redirlist to only handle the previous state of redirected
file descriptors.
Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: ce0f1900d869 ("[REDIR] Fix redirect restore on saved file...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 62cf6955f8abe875752d7163f6f3adbc7e49ebae ]
We unconditionally restore the saved status in exitreset, which
is incorrect as we only want to do it for exitcmd and returncmd.
This patch fixes the problem by introducing EXEND.
Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: da30b4b78769 ("[BUILTIN] Exit without arguments in a trap...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 2bc6caace3b08024955ed57fc993d91067f883a1 ]
The following constructs result in ever-increasing memory usage:
while true; do { true; } </dev/null; done
while true; do ( true; ) </dev/null; done
For comparison, bash displays static memory usage in both cases.
This issue was reported for BusyBox ash which is derived from dash:
https://bugs.busybox.net/show_bug.cgi?id=7748
Signed-off-by: Ron Yorston <rmy@frippery.org>
I have simplified evaltree so that it simply sets the stack mark
unconditionally. This allows us to remove the stack marks in the
functions called by evaltree.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 284b9192ed12a80b35fa7b9b85d75055887b64e9 ]
As sigsetmask is set as deprecated in glibc this patch adds the
pragmas to disable the warning in gcc around our one and only use
of sigsetmask.
It also disables it completely for non-gcc compilers and older
gcc compilers as they may generate a warning too.
Reported-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a500fb1c1bad9865bd1bb5cd084924062feb896e ]
This patch fixes a typo in evalbltin where warnx was used instead
of sh_warnx.
Reported-by: Antonio Ospite <ao2@ao2.it>
Fixes: 8e43729547b5 ("eval: Report I/O error on stdout")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 2c3ba509eb8117894d515e8fffc94aa099f38f8a ]
When we read the first token in list() we use peektoken instead
of readtoken as the following code needs to use the same token
again. However, this is wrong when we're in a here-document as
it will clobber the saved token without resetting the tokpushback
flag.
This patch fixes it by doing the tokpushback after parseheredoc
and setting lasttoken again if parseheredoc was called.
Reported-by: Ron Yorston <rmy@frippery.org>
Fixes: 7c245aa8ed33 ("[PARSER] Simplify EOF/newline handling in...")
Fixes: ee5cbe9fd6bc ("[SHELL] Optimize dash -c "command" to avoid a fork")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Simon Ser <contact@emersion.fr>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 878514712c5d21f675c45d99d2f8a04098ea4a19 ]
When we are doing VSLENGTH expansion, the closing brace is currently
not removed in evalvar. This causes the caller argstr to terminate
prematurely as it would interpret the closing brace as one that
belongs to a parameter expansion at the outer level.
This patch fixes it.
Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: 3cd538634f71 ("expand: Do not reprocess data when...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 70712c93c40a322056dafce7cbb45c727400936b ]
It has been reported that
echo test >&$EMPTY_VARIABLE
causes dash to segfault. This is a symptom of the bigger problem
that dash tries to perform pathname expansion as well as field
splitting on the word after >& and <&. This is wrong and this
patch fixes it to use the same expansions as done on a normal
redirection.
Reported-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit f97aaf80dd44e92f2cabc7e6d92d461f4fe6eddd ]
Gcc gives a warning about some missing parentheses:
-----------------------------------------------------------------------
eval.c: In function ‘evaltree’:
eval.c:282:15: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
if (!status == isor || evalskip)
^~
eval.c:282:7: note: add parentheses around left hand side expression to silence this warning
if (!status == isor || evalskip)
^~~~~~~
( )
-----------------------------------------------------------------------
Add the parentheses to silence the warning.
Signed-off-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 06204f0c9f539fcb8cb532166656e80b81bd689a ]
When "set -e" is enabled traps are not always executed, in particular
the EXIT trap is not executed when the shell exits on an unhandled
error.
Consider the following test script:
#!/bin/dash
set -e
trap 'ret=$?; echo "EXIT: $ret"' EXIT
trap 'exit 2' HUP INT QUIT PIPE TERM
read variable
By pressing Ctrl-C one would expect the EXIT trap to be called, as it is
the case with other shells (bash, zsh), but dash does not do it.
By calling dotrap() before jumping to the exit path when checkexit is
not zero, dash behaves like other shells.
Signed-off-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a29e9a1738a4e7040211842f3f3d90e172fa58ce ]
The commit 3cd538634f71538370f5af239f342aec48b7470b broke parameter
expansion in multiple ways because the EXP_DISCARD flag wasn't set
or tested for various cases:
$ src/dash -c 'var=; echo ${var:+nonempty}'
nonempty
$ src/dash -u -c 'unset foo bar; echo ${foo+${bar}}'
dash: 1: bar: parameter not set
$ src/dash -c 'foo=bar; echo ${foo=BUG}; echo $foo'
barBUG
bar
$
This patch fixes them by introducing a new discard variable that
tracks whether the extra word should be discarded or not when it
is parsed.
Reported-by: Martijn Dekker <martijn@inlv.org>
Fixes: 3cd538634f71 ("expand: Do not reprocess data when...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 413c6dcc3ca3891825ae8239251140882d7c6c6c ]
Exiting dash via a ^D instead of with "exit" causes dash to forget to
print a newline.
sh-3.1$ sh
sh-3.1$ ^D
sh-3.1$ dash
$ sh-3.1$
It is more neat and tidy to send a newline similarly to what bash does,
so it doesn't make the next prompt of the parent shell look ugly.
Suggested by jidanni.
Signed-off-by: Gerrit Pape <pape@smarden.org>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
[reworded the patch description]
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Bug-Debian: http://bugs.debian.org/476422
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 8e43729547b57ab15842dab23215336a353b2ded ]
ENOSPC as a result of an echo builting failing gives no diagnostic.
Just as other shells, dash sets $? to 1, but aside from terminating
the script, this does not inform the user what the problem is:
zsh:
% echo foo > /dev/full
echo: write error: no space left on device
bash:
$ echo foo > /dev/full
bash: echo: write error: No space left on device
dash:
$ echo foo > /dev/full
[nothing]
Print an error to stderr like the other shells.
Suggested by Roger Leigh.
Signed-off-by: Gerrit Pape <pape@smarden.org>
[reworded the patch description with information from the bug]
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Bug-Debian: http://bugs.debian.org/690473
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ad072645af04c31300c84d2840fcf1a8d48588ec ]
Don't use tempfile, as it currently runs tempnam(), which is insecure
and fails under pseudo(1).
Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 78a00a7471c059c9d7055f633c060106596de4fb ]
The minus sign generated from arithmetic expansion is currently
unquoted which causes anomalies when the result is used in where
the quoting matters.
This patch fixes it by explicitly calling memtodest on the result
in cvtnum.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit e9cb50188b1b04b6e5e8e8ccc8874b2abcff8bb1 ]
Currently growstackto will repeatedly call growstackblock until
the requisite size is obtained. This is wasteful. This patch
changes growstackblock to take a minimum size instead.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 42298df5898a62f0df893be3af029d7e981623bd ]
The variable localvar_stop is set iff vlocal is true. gcc doesn't
get this so we get a spurious warning.
This patch fixes this by always calling pushlocalvars with vlocal
and making it only actually do the push if vlocal is non-zero.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 3cd538634f71538370f5af239f342aec48b7470b ]
Currently various paths will reprocess data when performing word
expansion. For example, expari will skip backwards looking for
the start of the arithmetic expansion, while evalvar will skip
unexpanded words manually.
This is cumbersome and error-prone. This patch fixes this by
making word expansions proceed in a linear fashion. This means
changing argstr and the various expansion functions such as expari
and subevalvar to return the next character to be expanded.
This is inspired by similar code from FreeBSD. However, we take
things one step further and completely remove the manual word
skipping in evalvar. This is accomplished by introducing a new
EXP_DISCARD flag that tells argstr to only parse and not produce
any actual expansions.
Incidentally, argstr will now always NUL-terminate the expansion
unless the EXP_WORD flag is set. This is because all but one
caller of argstr wants the result to be NUL-termianted.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
evalvar
[ dash commit c5819fdd6e587aeb0bceaf60e86999a484541a19 ]
When we are trimming an unset variable in evalvar, any embedded
command substitution that should have been skipped are not. This
can cause them to be evaluated later should there be other command
substitutions in the same input word.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit cbca3d6f744e39d812817405f1eeef72480bf89c ]
The function arguments syntax and quotes are both derived from
the expansion flags. As syntax is only used by memtodest we do
not need to maintain it outside of the function at all.
The only place that uses something other than BASESYNTAX or DQSYNTAX
is exptilde. However in that case DQSYNTAX has exactly the same
effect as SQSYNTAX.
This patch merges these two arguments into a single flags. The
macro QUOTES_KEEPNUL has been renamed to EXP_KEEPNUL in order
to keep the namespace separate.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 14dff0f69d37e73cf99c77f5f5f38b2a3c6522f5 ]
Currently if HOME is set to empty tilde expansion will fail, i.e.,
it will remain as a literal tilde. This patch changes it to
return the empty string as required by POSIX.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 03cbaba30d7f6e4f89b6e881b6b909cb45924025 ]
This patch adds the test_access code from NetBSD when faccess is
unavailable. The code has been modified so that root can always
read/write any file.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit e94a964e7dd03d0dd6923d7fc62bc46bd4431189 ]
This patch adds basic vfork support for the case of a simple command.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[bwh: Adjust context for klibc]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 811a36120aef848cd308d56e06bf62e721be853c ]
This patch replaces listsetvar with mklocal/setvareq. As we now
determine special built-in status prior to variable assignment, we
no longer have to do a second pass listsetvar. Instead we will
call setvareq directly instead of mklocal when necessary.
In order to do this mklocal can now take a flag in order to mark
a variable for export.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 8ca5c96f0c45a4e224193820cb2aaf10059bfb07 ]
Previously, dash would continue to perform variable expansions
even if a redirection error occured. This patch changes it so
that it fails immediately.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit cbb71a836874d176809a34e22f6b6e4e3ba8c85b ]
This patch adds assignment built-in support that used to exist
in dash prior to 0.3.8-15. This is because it will soon be part
of POSIX, and the semantics are now much better defined.
Recognition is done at execution time, so even "command -- export"
or "var=export; command $var" should work.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 59e62c9a3c67eef2bf9dc86e5bf0b2c88d6e8571 ]
As regular (including special) built-ins can never be overridden,
we should never remove them from the hash table.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a068bf7aa310e8d36ae11c2aec47af1446a18827 ]
This patch changes the parsing of pathopt. First of all only
%builtin and %func (with arbitrary suffixes) will be recognised.
Any other pathopt will be treated as a normal directory.
Furthermore, pathopt can now be specified before the directory,
rather than after it. In fact, a future version may remove support
for pathopt suffixes.
Wherever the pathopt is placed, an optional % may be placed after
it to terminate the pathopt.
This is so that it is less likely that a genuine directory containing
a % sign is parsed as a pathopt.
Users of padvance outside of exec.c have also been modified:
1) cd(1) will always treat % characters as part of the path.
2) chkmail will continue to accept arbitrary pathopt.
3) find_dot_file will ignore the %builtin pathopt instead of trying
to do a stat in the accompanying directory (which is usually the
current directory).
The patch also removes the clearcmdentry optimisation where we
attempt to only partially flush the table where possible.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ae850b2a23083b489b85dca469110aa7a76d8976 ]
This patch marks the following built-ins as regular, meaning that
they cannot be overriden using PATH search:
hash
pwd
type
ulimit
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 4f7527f8e49276894751a9b100e68bc46568bb85 ]
Many callers of padvance immediately free the allocated string
so this patch moves the stalloc call to the caller. Instead of
returning the allocated string, padvance now returns the length
to allocate (this may be longer than the actual string length,
even including the NUL). For the case where we would previously
return NULL, we now return -1.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a9c4e4c9fc11cf1bd17d08e166405f7ab355a9f3 ]
This patch adds the growstackto helper which repeatedly calls
growstackblock until the requested size is reached.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 15a60c2357f772ccf953772859e8f9fc124442e2 ]
Some uses of fmtstr, particularly the ones without a format string,
can be replaced with stpcpy or stpncpy. This patch does that so
we don't have to introduce unnecessary format strings in order to
silence compiler warnings.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 0e18261c159f0af3d9ea7eae116d201bc1e05dd5 ]
The function fmtstr is meant to return the actual length of output
produced, rather than the untruncated length.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6458796c79e643503d14e18c611cfbf68c4a8cce ]
This patch forces the IFS variable to always be set to its default
value, regardless of the environment.
It also removes the long unused IFS_BROKEN code.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 51e2d88d6e513150a76c007111bbee21bb922c33 ]
This patch changes the parsing of here-documents within command
substitution, both old style and new style. In particular, the
original here-document list is saved upon the beginning of parsing
command substitution and restored when exiting.
This means that here-documents outside of command substitution
can no longer be filled by text within it and vice-versa.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6c691b3e5099de380a9d2f97d5c72f4a978bb794 ]
The gotsigchld flag is always cleared in dowait but not all callers
of dowait will wait for everything. In particular, when jp is set
we only wait until the set job isn't running anymore.
This patch fixes this by only clearing gotsigchld if jp is unset.
It also changes the waitcmd to actually set jp which corresponds
to the behaviour of bash/ksh93/mksh.
The only other caller of dowait that doesn't wait for everything
is the jobless reaper. This is in fact redundant now that we wait
after every simple command. This patch removes it.
Finally as every caller of dowait needs to wait until either the
given job is not running, or until all terminated jobs have been
processed, this patch moves the loop into dowait itself.
Fixes: 03876c0743a5 ("eval: Reap zombies after built-in...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 983085923ae1d45196868b48f576b1a19e03e72b ]
Previously reset was called after exitshell. This was changed
so that it was called before exitshell because certain state needed
to be reset in order for the EXIT trap to work.
However, this caused issues because certain other states (such
as local variables) should not be reset. This patch fixes this
by creating a new function exitreset that is called prior to
exitshell and moving reset back to its original location.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit d17dacd0f0499a8c77d810e211e8ff96b8898c48 ]
Currently exitcmd sets exitstatus and then savestatus if the latter
was previously set. In fact, as exitcmd always raises an exception
and will either end up in the setjmp call in main() or exitshell(),
where exitstatus is always replaced by savestatus if set, we only
need to set savestatus.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a332ebdaa13d3eaf70082e1be214c42645bc186a ]
Currently when shellexec fails on most errors the shell will exit
with exit status 2. This patch changes it to 126 in order to avoid
ambiguities with the exit status from a successful exec.
The errors that result in 127 has also been expanded to include
ENOTDIR, ENAMETOOLONG and ELOOP.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 469c5fd4f57622b1a6571172898ab29430319d4a ]
With the introduction of synstack->syntax, a number of references
to the syntax variable was missed during the conversion. This
causes backslash newlines to be incorrectly removed in single
quote context.
This patch also combines these calls into a new helper function
pgetc_top.
Fixes: ab1cecb40478 ("parser: Add syntax stack for recursive...")
Reported-by: Leah Neukirchen <leah@vuxu.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 9e5cd41d9605e4caaac3aacdc0482f6ee220a298 ]
Because of the nature of SIGCHLD, the process may have already been
waited on and therefore we must be prepared for the case that wait
may block. So ensure that it doesn't by using WNOHANG.
Furthermore, multiple jobs may have exited when gotsigchld is set.
Therefore we need to wait until there are no zombies left.
Lastly, waitforjob needs to be called with interrupts off and
the original patch broke that.
Fixes: 03876c0743a5 ("eval: Reap zombies after built-in...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 3cd57b6ed933c299e4d7c3c1e8390194635bbab8 ]
Dirk Fieldhouse <fieldhouse@gmx.net> wrote:
>
> In POSIX.1-2017 ("simultaneously IEEE Std 1003.1™-2017 and The Open
> Group Technical Standard Base Specifications, Issue 7")
> <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09>,
> we read under '2.9.1 Simple Commands'
>
> "Variable assignments shall be performed as follows:
> ...
> - If the command name is a standard utility implemented as a function
> (see XBD Utility), the effect of variable assignments shall be as if the
> utility was not implemented as a function.
> ...
> - If the command name is a function that is not a standard utility
> implemented as a function, variable assignments shall affect the current
> execution environment during the execution of the function. It is
> unspecified:
>
> * Whether or not the variable assignments persist after the
> completion of the function
>
> * Whether or not the variables gain the export attribute during
> the execution of the function
>
> * Whether or not export attributes gained as a result of the
> variable assignments persist after the completion of the function (if
> variable assignments persist after the completion of the function)"
POSIX used to require the current dash behaviour. However, you're
right that this is no longer the case.
This patch will remove the persistence of the variable assignment.
I have considered the exporting the variables during the function
execution but have decided against it because:
1) It makes the code bigger.
2) dash has never done this in the past.
3) You cannot use this portably anyway.
Reported-by: Dirk Fieldhouse <fieldhouse@gmx.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 48ca00863af909461d1372998bb90549f27abaaf ]
The parsing of parameter expansion inside inner double quotes
breaks because we never look for ENDVAR while innerdq is true.
echo "${x#"${x+''}"''}
This patch fixes it by pushing the syntax stack if innerdq is
true and we enter a new parameter expansion.
This patch also fixes a corner case where a bad substitution error
occurs within arithmetic expansion.
Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
Fixes: ab1cecb40478 (" parser: Add syntax stack for recursive...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6348e861b20d0b90275970af7357ac35ef956f16 ]
dash -c 'echo ${}' should print "Bad subtitution" but instead
fails with "Syntax error: Missing '}'". This is caused by us
reading an extra character beyond the right brace. This patch
fixes it so that this construct only fails during expansion rather
than during parsing.
Fixes: 3df3edd13389 ("[PARSER] Report substition errors at...")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 3311816551591b60ab0e14f94701bb0f2e19a71f ]
On Mon, Mar 26, 2018 at 07:25:20PM +0200, Martijn Dekker wrote:
> Op 26-03-18 om 17:38 schreef Harald van Dijk:
> > And not by dash 0.5.4. Like I wrote, dash 0.5.5 had some bugs that were
> > fixed in 0.5.6, which mostly restored the behaviour to match <0.5.5.
>
> Ah, sorry. dash 0.5.4 and earlier don't compile on my system, so they
> are not included in my conveniently accessible arsenal of test shells.
>
> > As for my patches, that was by accident and doesn't work reliably. When
> > the shell sees no metacharacters, pathname expansion is bypassed, and
> > backslash isn't considered a metacharacter. Which got me to my original
> > example of /de\v: there are no metacharacters in there, so the shell
> > doesn't look to see if it matches anything. Which seems highly
> > desirable: the shell shouldn't need to hit the file system for words not
> > containing metacharacters. The only way then to get consistent behaviour
> > is if the backslash is taken as quoted, so I'm not tempted to argue for
> > the behaviour you're hoping for, sorry. :)
Here is a better example:
a="/*/\nullx" b="/*/\null"; printf "%s\n" $a $b
dash currently prints
/*/\nullx
/*/\null
bash prints
/*/\nullx
/dev/null
You may argue the bash behaviour is inconsistent but it actually
makes sense. What happens is that quote removal only applies to
the original token as seen by the shell. It is never applied to
the result of parameter expansion.
Now you may ask why on earth does the second line say "/dev/null"
instead of "/dev/\null". Well that's because it is not the quote
removal step that removed the backslash, but the pathname expansion.
The fact that the /de\v does not become /dev even though it exists
is just the result of the optimisation to avoid unnecessarily
calling stat(2). I have checked POSIX and I don't see anything
that forbids this behaviour.
So going back to dash yes I think we should adopt the bash behaviour
for pathname expansion and keep the existing case semantics.
This patch does exactly that. Note that this patch does not work
unless you have already applied
https://patchwork.kernel.org/patch/10306507/
because otherwise the optimisation mentioned above does not get
detected correctly and we will end up doing quote removal twice.
This patch also updates expmeta to handle naked backslashes at
the end of the pattern which is now possible.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 46d5a7fcea81b489819f753451c1ad2fe435f148 ]
When evalcommand invokes a command that modifies parsefile and
then bails out without popping the file, we need to ensure the
input file is restored so that the shell can continue to execute.
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 03876c0743a50984b0aae69bba6f5034dc38aec1 ]
Currently dash does not reap dead children after built-in commands
or functions. This means that if you construct a loop consisting
of solely built-in commands and functions, then zombies can hang
around indefinitely.
This patch fixes this by reaping when necessary after each built-in
command and function.
Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit c22e9cc693a6271533740abd9be1bf918a40b0b3 ]
The noclobber code has a typo in it that causes it to fail. This
patch fixes it.
Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6900ff60ef7347a8c1445853a8f4689808e0976e ]
It's been a while since we disabled glob(3) support by default.
It appears to be working now, however, we have to change our
code to detect the no-match case correctly.
In particular, we need to test for GLOB_NOMAGIC | GLOB_NOCHECK
instead of GLOB_MAGCHAR.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 0f3806dd899ace97d5909f195882697ef9dd1eaa ]
The native version of expandmeta allocates a buffer that may be
overrun for two reasons. First of all the size is 1 byte too small
but this is normally hidden because the minimum size is rounded
up to 2048 bytes. Secondly, if the directory level is deep enough,
any buffer can be overrun.
This patch fixes both problems by calling realloc when necessary.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 325a460c7942aa79bb97303e129980db8afd177c ]
Currently echocmd uses print_escape_str to do everything apart
from printing the spaces/newlines separating its arguments. This
patch moves the actual printing into print_escape_str as well
using the format parameter.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 42b730b034eebd0e9da4aa014785a3ee5de436be ]
The commit d6c0e1e2ffbf7913ab69d51cc794d48d41c8fcb1 ("[BUILTIN]
Handle embedded NULs correctly in printf") caused a performance
regression in the echo built-in because every echo call now goes
through the printf %b slow path where the string is always printed
twice to ensure the space padding is correct in the presence of
NUL characters. In fact this regression applies to printf %b as
well.
This is easily fixed by making printf %b take the fast path when
no precision/field width modifiers are present.
This patch also changes the second strchurnul call to strspn which
generates slightly better code.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 36128c90e7bfbcf8313a6ac9a2880191aa47e6a6 ]
Harald van Dijk <harald@gigawatt.nl> wrote:
> On 22/03/2018 22:38, Martijn Dekker wrote:
>> Op 22-03-18 om 20:28 schreef Harald van Dijk:
>>> On 22/03/2018 03:40, Martijn Dekker wrote:
>>>> This patch fixes the bug that, given no positional parameters, unquoted
>>>> $@ and $* incorrectly generate one empty field (they should generate no
>>>> fields). Apparently that was a side effect of the above.
>>>
>>> This seems weird though. If you want to remove the recording of empty
>>> regions because they are pointless, then how does removing them fix a
>>> bug? Doesn't this show that empty regions do have an effect? Perhaps
>>> they're not supposed to have any effect, perhaps it's a specific
>>> combination of empty regions and something else that triggers some bug,
>>> and perhaps that combination can no longer occur with your patch.
>>
>> The latter is my guess, but I haven't had time to investigate it.
>
> Looking into it again:
>
> When IFS is set to an empty string, sepc is set to '\0' in varvalue().
> This then causes *quotedp to be set to true, meaning evalvar()'s quoted
> variable is turned on. quoted is then passed to recordregion() as the
> nulonly parameter.
>
> ifsp->nulonly has a bigger effect than merely selecting whether to use
> $IFS or whether to only split on null bytes: in ifsbreakup(), nulonly
> also causes string termination to be suppressed. That's correct: that
> special treatment is required to preserve empty fields in "$@"
> expansion. But it should *only* be used when $@ is quoted: ifsbreakup()
> takes nulonly from the last IFS region, even if it's empty, so having an
> additional zero-length region with nulonly enabled causes confusion.
>
> Passing quoted by value to varvalue() and not attempting to modify it
> should therefore, and in my quick testing does, also work to fix the
> original $@ bug.
You're right. The proper fix to this is to ensure that nulonly
is not set in varvalue for $*. It should only be set for $@ when
it's inside double quotes.
In fact there is another bug while we're playing with $@/$*.
When IFS is set to a non-whitespace character such as :, $*
outside quotes won't remove empty fields as it should.
This patch fixes both problems.
Reported-by: Martijn Dekker <martijn@inlv.org>
Suggested-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit dad1cb18b60ecce925f4ed234553a43fa6c81447 ]
On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote:
> On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote:
> >
> > Okay, it can be trivially modified to something that does work in other
> > shells (even if it were actually executed), but gets rejected at parse time
> > by dash:
> >
> > if false; then
> > : ${$+
> > }
> > fi
>
> That's just a bug in dash's parser with ${} in general, because
> it bombs out without the if clause too:
>
> : ${$+
> }
This patch fixes the parsing of newlines with parameter substitution.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit f88078247635fd076c935af6413f75395d5159da ]
On Sun, Mar 04, 2018 at 12:44:59PM +0100, Harald van Dijk wrote:
>
> command: set -- a ""; space=" "; printf "<%s>" "$@"$space
> bash: <a><>
> dash 0.5.8: <a>< >
> dash 0.5.9.1: <a>< >
> dash patched: <a><>
This is actually composed of two bugs. First of all our tracking
of quotemark is wrong so anything after "$@" becomes quoted. Once
we fix that then the problem is that the first space character
after "$@" is not recognised as an IFS.
This patch fixes both.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
string in printf"
[ dash commit fcb3864e0e348c206c12b3dae9e734d1efa2029e ]
This reverts commit 7bb413255368e94395237d789f522891093c5774.
The commit breaks printf with more than argument.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit c166b718b496da63c4df7a0972df2fc6cd38256b ]
Currently using backquotes in a here-document EOF mark is broken
because dash tries to do command substitution on it. This patch
fixes it by checking whether we're looking for an EOF mark during
tokenisation.
Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 9ee3343965950bad08e97f43c8c376b89a50b099 ]
The script
x=*
cat <<- EOF
${x#'*'}
EOF
prints * instead of nothing as it should. The problem is that
when we're in sqsyntax context in a here-document, we won't add
CTLESC as we should. This patch fixes it:
Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ab1cecb4047864afb247a6ed691e7f59ce716f2c ]
Without a stack of syntaxes we cannot correctly these two cases
together:
"${a#'$$'}"
"${a#"${b-'$$'}"}"
A recursive parser also helps in some other corner cases such
as nested arithmetic expansion with paratheses.
This patch adds a syntax stack allocated from the stack using
alloca. As a side-effect this allows us to remove the naked
backslashes for patterns within double-quotes, which means that
EXP_QPAT also has to go.
This patch also fixes removes any backslashes that precede right
braces when they are present within a parameter expansion context,
and backslashes that precede double quotes within inner double
quotes inside a parameter expansion in a here-document context.
The idea of a recursive parser is based on a patch by Harald van
Dijk.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6bbc71d84bea101370830dc3272f51c5ec1a7a78 ]
dash has a pgetc_eatbnl function in parser.c which skips any
backslash-newline combinations. It's not used everywhere it could be.
There is also some duplicated backslash-newline handling elsewhere in
parser.c. Replace most of the calls to pgetc() with calls to
pgetc_eatbnl() and remove the duplicated backslash-newline handling.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit fc914153d433b063b9ed11f3ace668c5c866f379 ]
Op 07-03-18 om 15:46 schreef Martijn Dekker:
> Op 06-03-18 om 09:19 schreef Herbert Xu:
>> On Thu, Jun 22, 2017 at 10:30:02AM +0200, Petr Skočík wrote:
>>> would you be willing to pull something like this?
> [...]
>>> I could use greater resolution in `test -nt` / `test -ot`, and st_mtim
>>> field is standardized under POSIX.1-2008 (or so stat(2) says).
>>
>> Sure. But your patch is corrupted.
>
> Fixed patch attached.
>
> But I wouldn't apply it as is. My system does not have st_mtim. So I
> think it needs a configure test and a fallback to the old method.
Here's an attempt to make that happen. See attached.
- M.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
$((x))
[ dash commit 2b3fb53c6940471955631353b8bdb7d5a4677fd1 ]
Op 07-03-18 om 06:26 schreef Herbert Xu:
> Martijn Dekker <martijn@inlv.org> wrote:
>>
>>> Since base is always a constant 0 or a constant 10, never a
>>> user-provided value, the only error that strtoimax will ever report on
>>> glibc systems is ERANGE. Checking only ERANGE therefore preserves the
>>> glibc behaviour, and allows the exact same set of errors to be detected
>>> on non-glibc systems.
>>
>> That makes sense, thanks.
>
> Could you resend your patch with this change please?
OK, see below.
- M.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 81a501b7fbcff8da004251a85a8f948263254aa5 ]
Op 29-03-17 om 20:02 schreef Martijn Dekker:
> Bug: if either the 'nolog' or the 'debug' option is set, trying to
> expand "$-" silently aborts parsing of an entire argument.
>
> $ dash -o nolog -c 'set -fuC; echo "|$- are the options|"; \
> set +o nolog; echo "|$- are the options|"'
> |
> |uCf are the options|
> $ dash -o debug -c 'set -fuC; echo "|$- are the options|"; \
> set +o debug; echo "|$- are the options|"'
> |
> |uCf are the options|
This turned out to be easy to fix. The routine producing the "$-"
expansion failed to skip options for which there is no option letter,
but only a long-form name. In dash, 'nolog' and 'debug' are currently
the only two such options. Patch below.
- Martijn
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 523d24878f5fb20c03210d10a919058a43fb5c31 ]
musl libc defines the optreset BSD extension only in getopt.h. This
fixes the following build failure:
histedit.c: In function 'histcmd':
histedit.c:220:2: error: 'optreset' undeclared (first use in this function)
optreset = 1; optind = 1; /* initialize getopt */
^~~~~~~~
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 556e2f03cc9e6e92ba361171226cd890db53589e ]
[ Ugh; forgot to attach patch - apologies, I need more coffee ]
Dear all,
Attached is a trivial patch that removes the assumption that fnmatch.h
is available - the configure script already checks for fnmatch(3) and
supplies its own implementation if necessary, but fnmatch.h is always
included.
Let me know what you think.
Regards,
Rink
Do not assume we can include fnmatch.h
Signed-off-by: Rink Springer <rink@rink.nu>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 7f31919cba4b17af883db77f99bfa974f0821361 ]
On 27/06/17 16:29, Zando Fardones wrote:
> Hello,
>
> I think I've found a bug when using the here-document redirection in
> an interactive shell. What basically happens is that you can't see the
> command output if you set the "vi" or "emacs" options.
That's not quite what happens: the here-document contents got lost, so
there is no command output to see. Nice find.
The problem is that getprompt() is implicitly called by el_gets(). This
messes with the memory used by the parser to store the here-document's
contents. In the non-emacs/vi case, the prompt is explicitly written by
setprompt(), which wraps the getprompt() call in a
pushstackmark()/popstackmark() pair to restore the state so that parsing
can continue. But when getprompt() is called by el_gets(), it knows
nothing about this.
The whole call to el_gets() can be surrounded by another
pushstackmark()/popstackmark() pair to solve the problem, as attached.
Cheers,
Harald van Dijk
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit f19f3b398a2e947148a646096de94b77c73bb55d ]
Hi,
On 26/05/17 09:04, Youfu Zhang wrote:
> $ PATH=/extra/path:/usr/sbin:/usr/bin:/sbin:/bin \
>> sh -xc 'command -V ls; command -V ls; command -Vp ls; command -vp ls'
> + command -V ls
> ls is /bin/ls
> + command -V ls
> ls is a tracked alias for /bin/ls
> + command -Vp ls
> ls is a tracked alias for (null)
> + command -vp ls
> Segmentation fault (core dumped)
>
> describe_command should respect `path' argument. Looking up in the hash table
> may gives incorrect index in entry.u.index and finally causes incorrect output
> or SIGSEGV.
True, but only when a path is passed in. If the default path is used,
looking up in the hash table is correct, and printing tracked aliases is
intentional.
If it's desirable to drop that feature, then it should be dropped
completely, code shouldn't be left in that can no longer be used. But
it's possible to keep it working: how about this instead?
Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 53dab360a1e0dddcfd83c6cbfc9f720f5e233550 ]
This variable does not contain "sigs" (plural).
It contains either 0 or (one) signal number of a pending signal.
For someone unfamiliar with this code, "pendingsigs" name is confusing -
it hints at being an array or bit mask of pending singnals.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
CC: dash@vger.kernel.org
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ad092191a3f281c2d14089c86757305403a9de64 ]
When there is an unmatched left square bracket in patterns, pmatch
will behave strangely and exhibit undefined behaviour. This patch
(based on Harld van Dijk's original) fixes this by treating it as
a literal left square bracket.
Reported-by: Olof Johansson <olof@ethup.se>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 4cf38c1ccd0c41715633c1b724c30e9c235099d1 ]
The commit 7a784244625d5489c0fc779201c349555dc5f8bc ("[BUILTIN]
Simplify echo command") broke echo -n by making it always terminate
after printing the first argument.
This patch fixes this by only terminating when we have reached
the end of the arguments.
Fixes: 7a784244625d ("[BUILTIN] Simplify echo command")
Reported-by: Luigi Tarenga <luigi.tarenga@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 0e4c9599468ab102e6a612439db6df0248410483 ]
The read built-in does not handle trailing IFS white spaces in
the right way, when there are more fields than variables. Part
of the problem is that this case is handled outside of ifsbreakup.
Harald van Dijk wrote a patch to fix this by moving the magic
into ifsbreakup itself.
This patch further reorganises the ifsbreakup loop by having only
one loop over the whole string.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Tested-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit da534b740e628512e8e0e62729d6a2ef521e5096 ]
The exit status is currently clobbered too early for case statements
and loops. This patch fixes it by making the eval functions return
the current exit status and setting them in one place -- evaltree.
Harald van Dijk pointed out a number of bugs in the original patch.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 203e8395faa9135956e3b2a2b749b6dd96a7e988 ]
When looking for a job using a string descriptor, e.g.
fg %man
the relevant loop in src/jobs.c only ever exits to the err label. With
this patch, when the end condition is reached, we check whether a job
was found, and if so, set things up to exit correctly via gotit.
Multiple matches are already caught using the test in the match block.
Signed-off-by: Stephen Kitt <steve@sk2.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 551215bb2f05b6ed0a639e1a20b88906ddd7ef9b ]
Jonathan Perkin submitted a patch to fix the behaviour of trap
when the first argument is an integer. Currently it is treated
as a command while POSIX requires it to be treated as a signal.
This patch is based on his idea but instead of adding an extra
argument to decode_signal I have added a new decode_signum helper.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 17a5f24e0a8ec22f74399764db30d97ae310f3c6 ]
On 17/11/2015 03:18, Gioele Barabucci wrote:
> Hello,
>
> a bug has been filed in the Debian BTS about dash not resetting the exit
> status after sourcing an empty file with the dot command. [1]
>
> The following test echoes "OK" with bash and "fail" with dash
>
> #!/bin/sh
>
> echo > ./empty
> false
>
> . ./empty && echo "OK" || echo "fail"
>
> A similar bug in dash has been discussed and addressed in 2011 [2], but
> it looks like the solution has been only partial.
>
> The version of dash I tested is the current git master branch, commit
> 2e58422.
>
> [1] https://bugs.debian.org/777262
> [2] http://article.gmane.org/gmane.comp.shells.dash/531
The bug described there was about empty files. While the fix has been
applied and does make dash handle empty files properly, your test
doesn't use an empty file, it uses a file containing a single blank
line. Unfortunately, the single blank line gets parsed by dash as a null
command, null commands don't (and shouldn't) reset the exit status, and
the fix you link to doesn't handle this because it sees a command has
been executed and saves the exit status after executing that command as
the exit status to be used by ".".
I think the easiest way to fix this is to prevent null commands from
affecting status in cmdloop, as attached.
An alternative could be to change the outer if condition to exclude
n == NULL, but I didn't do that because the change of job_warning and
clearing of numeof make sense to me even for null commands. Besides,
when debug tracing is enabled, null commands have a visible effect that
should remain.
Note that this fixes the problem with . but the same problem can be
present in other locations. For example,
false
eval "
" && echo OK || echo Fail
used to print Fail, and needed the same modification in the evalstring
function to make that print OK (included in the attached patch). There
may be other similar bugs lurking.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit cb924afe2e3465ec2f91fab55d31f7e3c26d03f4 ]
Ensure dash can build in a default Solaris 9 or older environment:
- Execute scripts with $SHELL rather than /bin/sh, the latter does not
support e.g. "if ! .." used by mkbuiltins.
- /bin/awk does not support ?: syntax, use explicit statements instead.
- /bin/nl requires no spaces between options and arguments.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 16cde63e05519c770daa69345b8cf37fb31eaa2a ]
If job %0 is (mistakenly) specified, an out-of-bounds access to the
jobtab occurs in function getjob() if num = 0:
jp = jobtab + 0 - 1
Fix this by checking that the job number is larger than 0 before
accessing the jobtab.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
after '*'
[ dash commit 0134f725b7d254ddbc3cc6dd72399edea832559c ]
Dash doesn't notice when a format string has digits following a * width
specifier.
$ dash -c 'printf "%*0s " 1 2 && echo FAIL || echo OK'
%10s FAIL
$ bash -c 'printf "%*0s " 1 2 && echo FAIL || echo OK'
bash: line 0: printf: `0': invalid format character
OK
$ mksh -c 'printf "%*0s " 1 2 && echo FAIL || echo OK'
printf: %*0: invalid conversion specification
OK
With this patch dash complains about the malformed specifications.
$ ./src/dash -c 'printf "%*0s " 1 2 && echo FAIL || echo OK'
./src/dash: 1: printf: %*0: invalid directive
OK
Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779618
Originally-by: Patrick Brown <opensource@whoopdedo.org>
Forwarded-by: Gioele Barabucci <gioele@svario.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 2e5842258bd5b252ffdaa630db09c9a19a9717ca ]
The global variable t_wp_op needs to be reset every time testcmd
is called or it may cause incorrect parsing of the arguments.
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit fe393c0f9ab72de5a7d32aab53e5e8275cad8735 ]
In mkbuiltins LC_COLLATE is set, but since "The value of the LC_ALL
environment variable has precedence over any of the other environment
variables starting with LC_"
(http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html), this
has no effect when LC_ALL is set.
This breaks when having e.g. LC_ALL=en_US.UTF-8 during make, which
causes the test case
dash -c :
to fail, probably due to broken ordering in builtins.c. The patch
corrects that by clearing LC_ALL.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 17db43b5841504b694203952fb0e82246c06a97f ]
The commit ef91d3d6a4c39421fd3a391e02cd82f9f3aee4a8 ([PARSER]
Handle backslash newlines properly after dollar sign) created
cases where we make two consecutive calls to pungetc. As we
don't explicitly support that there are corner cases where you
end up with garbage input leading to undefined behaviour.
This patch adds explicit support for two consecutive calls to
pungetc.
Reported-by: Jilles Tjoelker <jilles@stack.nl>
Reported-by: Juergen Daubert <jue@jue.li>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 51781428ead9a2142795764d0c42abfd9bb47171 ]
Currently we maintain a copy of the input state outside of parsefile.
This is redundant and makes reentrancy difficult. This patch kills
the duplicate global states and now everyone simply uses parsefile.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit d0e170e595a024aa5e4ec53a30f833f07f8cb849 ]
It hasn't been possible to build HETIO for over ten years. So
let's just kill it.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit dee20c64b4d2625bbe6e7329404e749d5b22b2f3 ]
The function preadbuffer should be static as it's only used in
input.c.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit bc4d989af4a4069f70f19fbe41a7d7ad61965ff8 ]
The commit 3c06acdac0b1ba0e0acdda513a57ee6e31385dce ([EXPAND]
Split unquoted $@/$* correctly when IFS is set but empty) broke
the case where $@ is in quotes and EXP_FULL is false.
In that case we should still emit IFS as field splitting is not
performed.
Reported-by: Juergen Daubert <jue@jue.li>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 35ff4d5b5a44aaf6fd98edef221dcc3ddcb8dda4 ]
Encontered this on ancient gcc-2.95.3 environment;
src/builtins.def.in -> src/builtins.def generation emitted
^ $
lines (likely by /* */), which where NOT ignored by
src/mkbuiltins and generating bogus builtins.c.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit f6d4def4e27b13fab174e948b94cd10550d3e10e ]
POSIX.1-2008 §4.4 "File Access Permission" sayeth:
If execute permission is requested, access shall be granted
if execute permission is granted to at least one user by the
file permission bits or by an alternate access control
mechanism; otherwise, access shall be denied.
For historical reasons, POSIX unfortunately also allows access() and
faccessat() to return success for X_OK if the current process is
privileged, even when the above condition is not fulfilled and actual
execution would fail. On the affected platforms, "test -x <path>" as
root started returning true on nonexecutable files when dash switched
from its own emulation to the true faccessat in v0.5.7~54
(2010-04-02).
Work around this by checking the permissions bits when mode == X_OK
and geteuid() == 0 on such platforms.
Unfortunately the behavior seems to vary from one kernel version to
another, so we cannot just check the behavior at compile time and rely
on that. A survey of some affected kernels:
- NetBSD's kernel moved to the sane semantics in 1997
- OpenBSD's kernel made the same change in version 4.4, three years
ago
- FreeBSD 9's kernel fixes this but hasn't been released yet
It seems safe to only apply the workaround on systems using the
FreeBSD kernel for now, and to push for standardization on the
expected access()/faccessat() semantics so we can drop the workaround
altogether in a few years.
To try it on other platforms, use "./configure --enable-test-workaround".
Reported-by: Christoph Egger <christoph@debian.org>
Analysis-by: Petr Salinger <Petr.Salinger@seznam.cz>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit cbd6165076cbbf18e68a292f80c1d454fdbedc22 ]
Currently we only check special variable names that follow directly
after $ or ${. So errors such as ${#&} are not caught. This patch
fixes that by moving the is_special check to just before we print out
the special variable name.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 7c245aa8ed33ba5db30eef9369d67036a05b0371 ]
This patch simplifies the EOF and new handling in the list parser.
In particular, it eliminates a case where we may leave here-documents
unfinished upon EOF.
It also removes special EOF/newline handling from parsecmd.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a31c812b02d7fc331f8a0c5aedbbf12b4025c1db ]
Doing a pungetc on an EOF is a noop and is only useful when we
don't know what character we're putting back. This patch removes
an unnecessary pungetc when we know it's EOF.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 12ad48bb31b003eb6d3106478b7760a031969a36 ]
This patch adds a nextopt call in dotcmd in order to handle --.
Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 7a784244625d5489c0fc779201c349555dc5f8bc ]
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a68498993413cd15f9b852ca32afd368e1792b51 ]
This patch removes the duplicate octal handling for %b by reusing
the existing code in conv_escape.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit bc8321eabffa23293d16d6758034203a8c7bffda ]
This patch replaces uses of warnx where we abort with error since
the effect is the same. The exit status however changes from 1 to
2. Non-fatal errors where we continue are unchanged.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 33b1ccbdab76baf9acad6f57d7e7a18e74c02cca ]
This patch removes getintmax and moves its functionality into
getuintmax in order to reduce code duplication.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[bwh: Adjust context for klibc]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
printf
[ dash commit 7bb413255368e94395237d789f522891093c5774 ]
Currently we try to preserve the format string which is stored in
argv after temporarily modifying it. This is unnecessary as it's
only ever used once. This patch gets rid of it.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 0f2b7ee05547fa06b9abb0643b0e3ca514050ab6 ]
MEM_OUT is only used by forkless backtick processing which we do
not currently support.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 53151f00720d5cd2df8cf196f4523d4f5b831598 ]
The branch in outmem where the string fits in the buffer is the
common case and is now marked as likely.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit c4d12c3f6424e801ccddda8894aad04d24333f82 ]
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit d6c0e1e2ffbf7913ab69d51cc794d48d41c8fcb1 ]
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=379227
On Sat, Jul 22, 2006 at 12:48:38PM +0200, A Mennucc wrote:
> Package: dash
> Version: 0.5.3-3
> Severity: normal
>
> hi
>
> here are the examples
>
> $ bash -c 'echo -n -e "A\0102C\00D\0E" | hexdump -c'
> 0000000 A B C \0 D \0 E
> 0000007
>
> $ /bin/echo -n -e "A\0102C\00D\0E" | hexdump -c
> 0000000 A B C \0 D \0 E
> 0000007
>
> $ zsh -c 'echo -n -e "A\0102C\00D\0E" | hexdump -c'
> 0000000 A B C \0 D \0 E
> 0000007
>
> $ dash -c 'echo -n "A\0102C\00D\0E" | hexdump -c'
> 0000000 A B C
> 0000003
>
> and also
>
> $ dash -c 'echo -n "ABC\0DEFGH" | hexdump -c'
> 0000000 A B C
> 0000003
>
> As you see, dash 's builtin echo truncates the output at the first \0
>
> a.
>
> -- System Information:
> Debian Release: testing/unstable
> APT prefers unstable
> APT policy: (500, 'unstable'), (500, 'testing')
> Architecture: i386 (i686)
> Shell: /bin/sh linked to /bin/bash
> Kernel: Linux 2.6.16-1-k7
> Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8)
>
> Versions of packages dash depends on:
> ii libc6 2.3.6-15 GNU C Library: Shared libraries
>
> dash recommends no packages.
>
> -- debconf information:
> * dash/sh: false
>
> --
> Andrea Mennucc
> "E' un mondo difficile. Che vita intensa!" (Tonino Carotone)
This patch fixes handling of embedded NULs using an approach similar
to the one taken by NetBSD. In particular, we first determine the
length of the output string, and then use a sequence of Xs of the
same length as input to the underlying C printf to determine the
amount of leading and trailing padding. Finally we replace the
Xs with the actual string before writing it out.
In order to print out the temporary string containing Xs and padding,
a new helper xasprintf is added. Unlike asprintf though, our
xasprintf prints to the ash stack rather than using straight malloc
memory.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit c77265b4ea89359c164346e400914bb24a3716d1 ]
This patch adds the format string characters a, A and F to the
supported set of the built-in printf command. They're already
supported by the underlying printf function.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[bwh: Adjust context for klibc]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 586463c3cf247dbead8553da7284a346b2faf1fb ]
The Cygwin platform supports DOS style drive-letter paths such
as "C:\\dir", even though the preferred form is a POSIX-style
"/cygdrive/c/dir". This can be seen by doing things such as
chdir("c:") (which succeeds) followed by getcwd(NULL, 0) (which
returns the normalized "/cygdrive/c"). However, dash was trying
to perform local manipulations on the argument to 'cd' prior to
calling into libc, in order to update the state of $PWD and
friends; these manipulations were assuming that the user meant
to change to a relative subdirectory of the current location,
as in './c:', instead of honoring the drive letter. None of
the other dash builtins take a filename and manipulate it to
affect shell state (some, like 'test', take a file name, but as
stat("c:") works just fine, there is no need to normalize).
This patch has no impact outside of cygwin; on cygwin, it takes
advantage of a native function call to canonicalize any
incoming name into preferred form before updating shell state.
Pre-patch:
$ dash -c 'cd c: && echo $PWD'
dash: 1: cd: can't cd to c:
Post-patch:
$ dash -c 'cd c: && echo $PWD'
/cygdrive/c
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ab657e36b68f4a7e9ddb0f36c455c98d1c069a2c ]
This patch makes a small optimisation by using the same value for
quoted between evalvar and varvalue by eliminating nulonly and
passing along quoted instead.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 8ecad23eae02bbdf36fe5dc8e53deb67fb894357 ]
Currently VSLENGTH and VSTRIM* are field-split even within quotes.
This is obviously wrong. This patch fixes that.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 3c06acdac0b1ba0e0acdda513a57ee6e31385dce ]
Currently we do not field-split $@/$* when it isn't quoted and IFS
is set but empty. This is obviously wrong. This patch fixes this.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit f20dcdd0948d7ebb7d462a0288ea218468ad4f6c ]
There is no need to setvarint to set the initial value of OPTIND
of one. This patch switchs to setvareq which also lets us avoid
an unnecessary memory allocation.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
outside traps
[ dash commit 70c16dd30d4cf824aa895e9f6c095fec741c65a8 ]
POSIX now requires that return without arguments in a trap should
return the last command status prior to executing traps. This
patch implements this behaviour.
Incidentally this also changes the behaviour of return without
arguments in a loop conditional to use the last exit status in
the body as opposed to the last command in the conditional when
there is one.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit f14b4626eb5c1c2fda137e7d1520c5f1cb7e85c4 ]
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=332954
When return is used in a loop conditional the exit status will
be lost because we always set the exit status at the end of the
loop to that of the last command executed in the body.
This is counterintuitive and contrary to what most other shells do.
This patch fixes this by always preserving the exit status of
return when it is used in a loop conditional.
The patch was originally written by Gerrit Pape <pape@smarden.org>.
Reported-by: Stephane Chazelas <stephane_chazelas@yahoo.fr>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 598d300ffa0b9542a88feae900ccdd29e35374cf ]
The functions evalloop and evalfor share the logic on checking
and updating skipcount. This patch moves that into the helper
function skiploop.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ebfdd97a10e34a5e70eadfc21ebfc033ef93a563 ]
As it is if you do a multi-level break inside a function it'll
actually include loops outside of the function call. This is
counterintuitive.
This patch changes this by saving and resetting loopnest when
entering a function.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
outside traps
[ dash commit da30b4b787695fbf77e5d941ff350a66ca572bcb ]
POSIX now requires that exit without arguments in a trap should
return the last command status prior to executing traps. This
patch implements this behaviour.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 0d1fb088a4a16569260de4266d4bd359491c6bcd ]
All originators of EXERROR have been setting the exitstatus for
a while now. So it is no longer appropriate to set it explicitly
in evalcommand.
In fact doing so may cause the original exitstatus to be lost.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit b4ce4120f87d89476b2d6ab31df43900d2f5ce89 ]
Currently the exit status when we receive SIGINT is set in evalcommand
which means that it doesn't always get set. For example, if you press
CTRL-C at the prompt of an interactive dash, the exit status is not
set to 130 as it is in many other Bourne shells.
This patch fixes this by moving the setting of the exit status into
onint which also simplifies evalcommand.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit d28c13e7119a605ef152a4310e9415dc7ae9b8f3 ]
As it is if dotrap is called with evalskip set to a nonzero value,
it'll try to execute any set traps. The result is that the first
command in the first set trap will be executed while the rest of
the trap will be silently ignored due to evalskip. This is highly
counterintuitive, even though both bash and ksh exhibit a similar
behaviour.
This patch fixes it by skipping trap processing if evalskip is set
on entry. It also adds a dotrap call to the top of evaltree to
ensure that
while continue; do
continue;
done
has a chance of running traps.
Finally the pendingsigs check is moved into dotrap for compactness.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6c3f73bc536082fec38bd36e6c8a121033c68835 ]
The function dotrap calls evalstring using the stored trap string.
If evalstring then unsets that exact trap string then we will end
up using freed memory.
This patch fixes it by making evalstring always duplicate the string
before using it.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 6df87cf1d4b7c0c490ab1803b863de10579df92e ]
This patch adds the nlprompt/nlnoprompt helpers to isolate code
dealing with newlines and prompting.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ef91d3d6a4c39421fd3a391e02cd82f9f3aee4a8 ]
On Tue, Aug 26, 2014 at 12:34:42PM +0000, Eric Blake wrote:
> On 08/26/2014 06:15 AM, Oleg Bulatov wrote:
> > Hi!
> >
> > While playing with sh generators I found that dash and bash have different
> > interpretations for <slash><newline> sequence.
> >
> > $ dash -c 'EDIT=xxx; echo $EDIT\
> >> OR'
> > xxxOR
>
> Buggy.
>
> > $ bash -c 'EDIT=xxx; echo $EDIT\
> > OR'
> > /usr/bin/vim
>
> Correct behavior.
>
> >
> > $ dash -c 'echo "$\
> > (pwd)"'
> > $(pwd)
> >
> > Is it undefined behaviour in POSIX?
>
> No, it's well-defined, and dash is buggy. POSIX says:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_03
>
> "the shell shall break its input into tokens by applying the first
> applicable rule below to the next character in its input"
>
> Rule 4 covers backslash handling, while rule 5 covers locating the end
> of a word to be subject to $ expansion. Therefore, rule 4 should happen
> first. Rule 4 defers to the section on quoting, with the caveat that
> <newline> joining is the only substitution that happens immediately as
> part of the parsing:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02
>
> "If a <newline> follows the <backslash>, the shell shall interpret this
> as line continuation. The <backslash> and <newline> shall be removed
> before splitting the input into tokens. Since the escaped <newline> is
> removed entirely from the input and is not replaced by any white space,
> it cannot serve as a token separator."
>
> So the fact that dash is treating the elided backslash-newline as a
> token separator, and parsing your input as if ${EDIT}OR instead of
> ${EDITOR} is a bug in dash.
I agree. This patch should resolve this problem and similar ones
affecting blackslash newlines after we encounter a dollar sign.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 339b9c0781cca7afb0964c6a655cda8ad9cf9fc2 ]
pgetc_macro is identical to pgetc except that it's a macro and
pgetc isn't. Since there is very little performance difference
on modern systems it's time to kill pgetc_macro.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 4f7e4c8201e580b9d31c09d8a484741072033c01 ]
This patch adds a special case in testcmd for the 4-argument
expression beginning with a !. Without this ! ! = ! is deemed
a syntax error, which breaks POSIX.
Note that this special case does not extend down into subexpressions
so if ! ! = ! is used inside parentheses then a syntax error will
still occur as before.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 4c44561d9f97331bb23f900f47a69305091f3ab3 ]
On 29/07/13 23:44, Luigi Tarenga wrote:
> hi list,
> while writing a script to execute parallel ssh command on many host I found
> a strange behavior of dash. I can replicate it with a very simple script but
> didn't find any documentation about dash or POSIX that can explain it.
>
> tested on centos 6.4 (dash 0.5.5.1) and wih dash compiled from source (0.5.7)
> the following script reports error:
>
> #!/bin/dash
>
> sleep 3 &
> sleep 3 &
> sleep 3 &
> sleep 3 &
>
> #/bin/true
> jobs -l
>
> wait %1
> wait %2
> wait %3
> wait %4
>
> [vortex@lizard ~]$ ./dash-0.5.7/src/dash test.sh
> [4] + 4569 Running
> [3] - 4568 Running
> [2] 4567 Running
> [1] 4566 Running
> prova: 14: wait: No such job: %4
> [vortex@lizard ~]$ echo $?
> 2
Yes, this looks like a bug to me. The number of allocated jobs is always
kept as a multiple of four, and the first check in considering whether
the job number is valid is "if it's greater than or equal to the number
of allocated job, it's invalid". That doesn't look right. That would
only be right if jobs were zero-based, but they aren't. If it's exactly
equal to the number of available jobs, it can still be valid. It works
when adding /bin/true, because four more more jobs end up allocated
internally.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 842050da1c14d7dbe365cd750032fcd8eaaa1db2 ]
Exclude /usr/local from command -p PATH.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 29ee27dda68a63ce8b9dccdf2c86f75a4d754b5c ]
This patch moves the pathval call into the describe_command
function and also eliminates an unnecessary branch when DEBUG
is off.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 65ae84b3d67425e16b85273e566d06ae942dcce9 ]
On 10/07/13 20:18, Craig Loomis wrote:
> Dash (0.5.7 and git master) does not implement 'command -p'
> according to the standard, and opens an intriguing security hole to
> anyone trying this scheme.
>
> When using 'command -v' to simply print the path to an executable,
> '-p' has no effect:
You're right. dash has never supported combining -p with -v, but back in
2005 this was seemingly accidentally changed from reporting a syntax
error to silently ignoring the -p option, only about a month after dash
moved to git.
Making sure that -p is respected even when -v is used is easy enough,
see attached patch. Tested even with explicit PATH overrides:
PATH=/path/to/some/other/dash command -pv dash
correctly outputs /bin/dash on my system.
> the path that 'command -p cmd' uses is a compiled-in constant
> from dash's src/var.c:defpathvar, which starts with
> "/usr/local/sbin:/usr/local/bin". To me, that is both completely
> unexpected and pretty scary -- /usr/local/bin is (very) often less
> well secured or checked than, say, /bin:
Agreed. However, IMO, it does make sense for defpathvar to start with
/usr/local/*: it has two separate functions, it also serves as the
default path (hence the name) when dash is started with no PATH set at
all. I think fixing this should be done in a way so that command -p does
not use defpathvar, not by changing defpathvar. bash uses the same
confstr function for this that getconf uses, and it shouldn't be too
much work to make dash use that too. If no one else comes up with a
working patch or a better approach, I'll try to get that working.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit b34499f5c851d1a70db95b56bd02eff0329d4a1a ]
When nexpr gets an unexpected EOI, this may cause crashes further
up the call chain because we've advanced t_wp too far. Fix it by
checking for EOI in nexpr and only advancing t_wp if we've got more
arguments.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a14c418aee9d4ccd7cf888024e318b300173099f ]
On Sat, Mar 23, 2013 at 01:46:20AM +0000, Chris F.A. Johnson wrote:
>
> According to both the dash man page and the POSIX spec, "When the
> shell is invoked, OPTIND is initialized to 1."
>
> However, it actually takes the value of the environment variable
> if it exists:
>
> $ OPTIND=4 dash -c 'echo "$OPTIND"'
> 4
> $ OPTIND=4 bash -c 'echo "$OPTIND"'
> 1
> $ OPTIND=4 ksh -c 'echo "$OPTIND"'
> 1
> $ OPTIND=4 ksh93 -c 'echo "$OPTIND"'
> 1
This patch fixes this by initialising OPTIND after importing the
environment.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 14f70561a50fc8eba75b818a4705fed44da2ba2e ]
Signed-off-by: Peter Rosin <peda@lysator.liu.se>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 5464ae7d9e226586b79527cb445d892177b70271 ]
On 12/03/2012 05:59 PM, Harald van Dijk wrote:
> On 12/03/2012 08:42 AM, Roy wrote:
>> MSYS libc does not support %j[dXx] format, only %ll[dXx] is supported.
>>
>> diff --git a/src/bltin/printf.c b/src/bltin/printf.c
>> index 893295c..12ce660 100644
>> --- a/src/bltin/printf.c
>> +++ b/src/bltin/printf.c
>> @@ -319,11 +319,12 @@ mklong(const char *str, const char *ch)
>> char *copy;
>> size_t len;
>>
>> - len = ch - str + 3;
>> + len = ch - str + 4;
>> STARTSTACKSTR(copy);
>> copy = makestrspace(len, copy);
>> - memcpy(copy, str, len - 3);
>> - copy[len - 3] = 'j';
>> + memcpy(copy, str, len - 4);
>> + copy[len - 4] = 'l';
>> + copy[len - 3] = 'l';
>> copy[len - 2] = *ch;
>> copy[len - 1] = '\0';
>> return (copy);
>
> The calling code uses the result to print intmax_t and uintmax_t values.
> Printing intmax_t values with %lld is wrong, this will only work if
> intmax_t is really a typedef for long long (which may be true on your
> system, but is not required by the standard).
>
> The other patch that Jonathan linked to should work just fine.
Here's a slightly tweaked version of that patch. Regardless of whether
PRIdMAX is defined as "jd" or as "lld", the use of memcpy here, first
copying "jd"/"lld" and the null byte, and only changing the 'd' after
that, surprisingly results in slightly shorter object code than the
original byte-by-byte approach, even though memcpy is fully inlined.
Perhaps that could be a reason for applying this, even if the original
reason for it, making the code work on not-quite-conforming systems,
isn't good enough to get it in dash.
Tested with normal glibc, and with glibc hacked to not provide PRIdMAX.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit a7c21a6f4cb42d967854cae954efd4ee66bdea9c ]
On Tue, Aug 28, 2012 at 01:27:24PM +0000, Todor Vlaev wrote:
>
> While playing around with parameter expansion I noticed that the
> following didn't work in dash (dash 0.5.5.1-7.4ubuntu1) as compared
> to bash even though I believe it should be POSIX-compliant:
>
> my_str=swan; last_char="${my_str#${my_str%?}}"; echo ${last_char}
>
> If the double quotes are removed, the last character is printed correctly.
>
> At a quick glance through the commits after the 0.5.5.1 release I saw
> the following bug fix. Could it be related?
>
> 0d7d66039b614b642c775432fd64aa8c11f9a64d
> [EXPAND] Fix quoted pattern patch breakage
We need to propagate EXP_QPAT in subevalvar as otherwise a nested
parameter expansion within subevalvar may be expanded incorrectly.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
These functions are included in POSIX.1-2008, and current upstream
dash now uses stpncpy() without providing a fallback definition.
Also add tests for these functions.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit ee5cbe9fd6bc02f31b4d955606288de36c3d4eab ]
On Sun, Apr 10, 2011 at 07:36:49AM +0000, Jonathan Nieder wrote:
> From: Jilles Tjoelker <jilles@stack.nl>
> Date: Sat, 13 Jun 2009 16:17:45 -0500
>
> This change only affects strings passed to -c, when the -s option is
> not used.
>
> Use the EV_EXIT flag to inform the eval machinery that the string
> being passed is the entirety of input. This way, a fork may be
> omitted in many special cases.
>
> If there are empty lines after the last command, the evalcmd will not
> see the end early enough and forks will not be omitted. The same thing
> seems to happen in bash.
>
> Example:
> sh -c 'ps lT'
> No longer shows a shell process waiting for ps to finish.
>
> [jn: ported from FreeBSD SVN r194128. Bugs are mine.]
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Instead of detecting EOF using the input layer, I'm going to
use the parser instead. In either case, we always have to read
ahead in order to complete the parsing of the previous node.
Therefore we always know whether there is more to come, except
in the case where we see a newline/semicolon or similar.
For the purposes of sh -c, this should be sufficient.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[bwh: Update usr/dash/Kbuild for mktokens and parser.h changes, and
README.dash to reflect that we now have this change]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
This effectively reverts commit 984d40b0fc4c "[klibc] Make building
dash O= friendly". Later upstream versions of mktokens create two
files, so there will be no reasonable way to redirect its output.
The if_changed macro assumes that the rebuild command does not change
the current directory, which is why out-of-tree builds broke here
prior to commit 984d40b0fc4c. Since we do need to change the current
directory, do it in a subshell which won't affect the following
commands generated by if_changed.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
This reverts commit 5125a8b74971fc22fdc74cfc9dc8e04a4f5c0e4b.
The problem that it solves was fixed differently upstream.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
This is preparation for applying upstream changes.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Since we mangle file paths and don't use autotools, the upstream
.gitignore doesn't work for us.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
There are rather more than we admitted to here.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Add an awk command in the pipeline to:
* Insert "dash:" in each commit message subject as well as "[klibc]"
* Insert the hash of the original commit at the top of each message body
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
filterdiff can add and remove path prefixes and exclude files.
Consolidate the multiple steps into a single filterdiff command.
This results in the mailbox file containing the patches with their
final paths (though still without sign-off and whitespace cleanup).
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
It's going to be easier to operate on a mailbox than a lot of single
patches.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 1379c310a3e822a577b06e2997f0793b402ae926 ]
Building with clang results in some warnings about the use of GNU
old-style field designators:
-----------------------------------------------------------------------
output.c:86:2: warning: use of GNU old-style field designator extension [-Wgnu-designator]
nextc: 0, end: 0, buf: 0, bufsize: OUTBUFSIZ, fd: 1, flags: 0
^~~~~~
.nextc =
...
-----------------------------------------------------------------------
Fix the issue bu using C99 initializers instead.
This should be safe and should not introduce any compatibility problems
as it is done already in other parts of the codebase, like
src/expand.c:ccmatch() and src/parser.c::readtoken1().
Signed-off-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
[ dash commit 604bd2b57a08817da8d757c5eb265dbe11ef3d39 ]
Building with clang results in some warnings about integer values being
added to strings:
-----------------------------------------------------------------------
eval.c:1138:13: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
p = " %s" + (1 - sep);
~~~~~~^~~~~~~~~~~
eval.c:1138:13: note: use array indexing to silence this warning
p = " %s" + (1 - sep);
^
& [ ]
1 warning generated.
...
jobs.c:1424:16: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
str = "\"}" + !(quoted & 1);
~~~~~~^~~~~~~~~~~~~~~
jobs.c:1424:16: note: use array indexing to silence this warning
str = "\"}" + !(quoted & 1);
^
& [ ]
1 warning generated.
-----------------------------------------------------------------------
While the code itself is fine and the warnings are indeed harmless,
fixing them also makes the semantic more explicit: what it is actually
being increased is the address which points to the start of the string
in order to skip the initial character when some conditions are met.
Signed-off-by: Antonio Ospite <ao2@ao2.it>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The stack should be made non-executable, as a security hardening
measure. This is irrelevant for most of the klibc utilities, but
ipconfig deals with network input that might be untrusted. Since
Linux 5.6-rc1 the kernel now also warns (once) if a program has an
executable stack.
As this is necessarily a process-wide attribute at run-time, the
stack ends up being executable unless every object file linked into the
program is flagged as not needing it. gas doesn't set the flag by
default, so we need to explicitly tell it to do so.
ia64 will also need a change to its linker script to retain the
.note.GNU-stack section, but I have no way of testing ia64 so I'm going
to leave that to later.
Reported-by: Christophe Leroy <christophe.leroy@c-s.fr>
References: https://lists.zytor.com/archives/klibc/2020-February/004271.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
ipconfig should accept any ip=/nfsaddrs= parameter that the kernel
accepts.
The kernel now supports a 10th field for an NTP server address, but
only copies it into procfs. We must accept but ignore it.
The kernel also ignores additional fields, and might define meanings
to them in future. We must accept and ignore them.
References: https://bugs.debian.org/931416
References: https://bugzilla.kernel.org/show_bug.cgi?id=205805
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Support for static DNS server addresses was implemented in commit
b86cd0ef3f22, but README.ipconfig did not mention this.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Since Linux 3.1, the loop driver creates a /dev/loop-control device
node which supports ioctls to allocate and free devices.
When the loop driver is modular, udev creates this in advance, and
opening it causes the driver to be loaded. (The same is not true for
/dev/loop*.)
Using the LOOP_CTL_GET_FREE ioctl also allows creating more than the
default number of loop devices, and is more efficient than checking
a range of possible device names.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The LOOP_{GET,SET}_STATUS64 ioctls were added in Linux 2.5.68, and
klibc is not intended to support old kernel versions.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
For some reason the kernel's definition of struct loop_info64 defines
string fields as arrays of __u8 (unsigned char) instead of char. Add
the necessary casts to avoid compiler warnings.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
linux/loop.h header is exported by linux, for userspace to
consume. This would prevent issues with struct sizes
incompatibilities.
References: https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/1850184
Signed-off-by: Michael Hudson-Doyle <michael.hudson@ubuntu.com>
Signed-off-by: Adam Conrad <adconrad@ubuntu.com>
Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
[bwh: We were using dev_t instead of __kernel_old_dev_t, which doesn't
match on some architectures. Instead of fixing our definition first,
switch directly to the kernel's UAPI header.]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
This is obsolete since Linux 2.6.28, and it's now causing problems for
people using compressed modules because we don't recognise the ext4
module with a .gz or .xz extension.
Reported-by: Greg Edwards <gedwards@ddn.com>
References: https://bugs.debian.org/932926
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
|
|
The current default of timeo=7 (0.7 seconds) is too short, especially
on slow networks. We should not override the kernel client's default
unless explicitly requested.
This option is passed to the kernel through struct nfs_mount_data
rather than as a string, so we have to provide some value. The kernel
client currently treats either 0 or UINT_MAX as requesting the default.
nfs-utils passes 0, so do the same here.
Reported-by: Alkis Georgopoulos <alkisg@gmail.com>
References: https://lists.zytor.com/archives/klibc/2019-September/004233.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
sigsuspend.c includes <klibc/havesyscall.h>, which is a generated
file. In a parallel make, sigsuspend.o might currently be built
before havesyscall.h, and to avoid this we need t add an explicit
dependency.
Given that they are built from different makefiles, I don't think a
direct dependency will work. Instead, add syscalls/klib.list as a
dependency for sigsuspend.o so that it indirectly depends on
everything that's built from syscalls/.
Reported-by: Matthias Klose <doko@ubuntu.com>
Reported-by: Thorsten Glaser <tg@mirbsd.de>
References: https://bugs.launchpad.net/ubuntu/+source/klibc/+bug/1843743
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
"ar s" without a sub-command like "r" fails in binutils 2.32, at least
in the Debian package. Revert to running ranlib where we are only
updating the index and not members.
References: https://bugs.debian.org/941921
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Whilst ip= command is documented to support dns0:dns1 options as
arguments 7 and 8, the -d parser in ipconfig does not. This breaks
bringing up static ip configuration with dns nameservers set in the
ip= command.
Testcase:
$ ip link add name dummy0 type dummy
$ sudo /usr/lib/klibc/bin/ipconfig -d 10.245.237.7::10.245.237.1:255.255.255.0:ottawa:dummy0:none:8.8.8.8:8.8.4.4
IP-Config: dummy0 hardware address 76:39:ca:27:9b:90 mtu 1500
IP-Config: dummy0 guessed broadcast address 10.245.237.255
IP-Config: dummy0 complete:
address: 10.245.237.7 broadcast: 10.245.237.255 netmask: 255.255.255.0
gateway: 10.245.237.1 dns0 : 8.8.8.8 dns1 : 8.8.4.4
host : ottawa
rootserver: 0.0.0.0 rootpath:
filename :
Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
systemd supports switching back to the initramfs during shutdown in
order to make it easier to clean up the root file system. This is
desirable in order to allow us to remove keys from RAM before rebooting,
making it harder to obtain confidential information by rebooting into an
environment that scrapes RAM contents.
Signed-off-by: Matthew Garrett <mjg59@google.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Linux commit 746c9398f5ac ("arch: move common mmap flags to
linux/mman.h") moved a few mmap flags, particularly MAP_PRIVATE, from
asm/mman.h to linux/mman.h. This broke klibc's build, which uses
MAP_PRIVATE.
linux/mman.h includes asm/mman.h, so this commit merely includes
linux/mman.h instead of asm/mman.h.
Signed-off-by: Barret Rhoden <brho@google.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
klcc should strip its output if the -s option is used, regardless of
whether klibc is stripped. Use the standard $(STRIP) instead of
$(KLIBCSTRIP) as the strip command.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Since Linux 4.14, the "new" system call ABI (CONFIG_AEABI) is enabled
by default when building for ARMv6/v7 processors. The old system call
ABI can be enabled in parallel (CONFIG_OABI_COMPAT) but is disabled by
default.
When building a kernel for ARMv4/v5 processors, the default is to
enable only the old system call ABI. However, the two distributions
I'm aware of that support these processors, Arch and Debian, configure
the kernel to support only the new system call ABI.
Therefore I think that it is better to assume the "new" system call
ABI by default.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
* Tests are passing for arm-thumb, parisc and sh
* There are some test failures on alpha and ia64, but the shared
library works on ia64
* arm26 and v850 have been removed for Linux so we have no expectation
of ever supporting them
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
* Explicitly say where to set the cross-compilation variables
* Explain how to do an out-of-tree build
* Document all the configuration variables in defconfig
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Recommend installing the kernel UAPI headers under the klibc source
directory. This reduces the second build step to just "make" (for
most native builds).
Explain the alternative options in a subsection of README.klibc.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
We need installed UAPI headers, so check slightly further.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The current text talks about a build process, but then lists many
things that are either optional or not related to the build process.
Turn the list items (and the rest of the text) into multiple sections
with headings.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
When updating URLs in commit d4267b09846f I accidentally changed the
URL for the mailing list from the Mailman list information page to the
Pipermail archive page.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
|
|
Currently it's necessary to specify both KBUILD_SRC and srctree to
make everything work properly in an out-of-tree build. It should
only be necessary to specify KBUILD_SRC. Initialise srctree
accordingly.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Kbuild expands every -I in the compiler options so that in an
out-of-tree build both the source directory and corresponding
object directory are on the include path.
We currently use $(KLIBCCPPFLAGS) when compiling divide.c, which is
not expanded, so in an out-of-tree buld the compiler does not find
headers in the source tree. Use the flags macro to expand
$(KLIBCCPPFLAGS).
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Kbuild expands every -I in the compiler options so that in an
out-of-tree build both the source directory and corresponding
object directory are on the include path.
We currently pass $(KLIBCCPPFLAGS) to makeerrlist.pl, which is not
expanded, so in an out-of-tree buld it only looks in the object
directories and does not find linux/errno.h. Use the flags macro to
expand $(KLIBCCPPFLAGS).
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
When CONFIG_KLIBC_ZLIB is not set, related functions
shall not be called otherwise build failure is encountered:
KLIBCLD usr/kinit/static/kinit
usr/kinit/ramdisk_load.o: In function `load_ramdisk_compressed':
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:68: undefined reference to `inflateInit2_'
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:116: undefined reference to `inflate'
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:128: undefined reference to `inflateEnd'
/root/ldb_base/ofl/packages/klibc/usr/kinit/ramdisk_load.c:132: undefined reference to `inflateEnd'
make[2]: *** [usr/kinit/shared/kinit] Error 1
When CONFIG_KLIBC_ZLIB is not set, this patch redefines
load_ramdisk_compressed() as a simple function printing an error
message and returning -1
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
We need to build with -mno-pic to disable all uses of GP, as well as use
a custom linker script to avoid collisions between klibc.so's and the
executable's segments.
Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The caller does not pass any arguments, so we need to set the system
call number ourselves.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
In Linux 2.6.30 the definition of struct flock stopped using
off_t (which we define) in favour of __kernel_off_t. This
meant we started using a 32-bit struct flock with 64-bit fcntl
numbers.
Disable the kernel's definition of struct flock and define
it ourselves with 64-bit offsets.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Several get*id() system calls are paired up on alpha, returning one ID
in v0 (usual return register) and another ID in a4. The "dual1"
system call wrapper is used when we want the second ID from a4.
This system call wrapper had a fatal bug: it moves v0 to a4, but it
needs to do the opposite.
Also, in case of error, it stored the error flag (a3) to errno rather
than the error code (v0). Rearrange the code so we only change v0
at the bottom of the function, and store the original value of v0 to
errno before that.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Build all programs with full debug information (-ggdb). We still
strip it away before installing by default.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
We previously changed mips and x86 to link the shared library with
the -Ttext-segment option to avoid address collisions with extra
sections automatically added by the linker (commits 048bfb0df170,
2a705525e081, 34163a2c7d1c).
Adding a build ID to support separate debug info causes a similar
problem on other architectures. Use -Ttext-segment on all
architectures.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Support for a device offset as part of the string written to
/sys/power/resume never got into a mainline kernel.
However, since Linux 4.17 there is a separate resume_offset attribute
that we can use to set the offset before attempting to resume.
Change resume() to write the resume_offset attribute instead.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The .deb and RPM packaging tools can automatically split
debugging symbols into a separate package. This requires
that binaries and shared libaries are initially installed
unstripped, and that they are given build IDs.
If CONFIG_DEBUG_INFO is defined:
* Add --build-id=sha1 to the linker options
* Don't strip binaries after linking them
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Most binaries are installed with the same name regardless of
whether they use a static or shared library. The two exceptions
to this are kinit and sh, which are installed with the suffix
".shared" if they use a shared library.
Build these binaries in subdirectories, so that the static and shared
versions have the same (unsuffixed) name.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The shared library build has never worked on ia64, and Debian has a
longstanding patch that changes the install targets to install static
binaries for ia64. This can be generalised to checking whether
KLIBCSHAREDFLAGS is defined, as without that we can't expect to build
a working shared library.
* Include the necessary files in scripts/Kbuild.install so that
KLIBCSHAREDFLAGS is defined at install time.
* Install static binaries instead of shared if KLIBCSHAREDFLAGS is
not defined.
* Only install the shared library if KLIBCSHAREDFLAGS is defined.
* Only build the shared library and binaries if KLIBCSHAREDFLAGS is
defined.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
|
|
It was still mentioned in README.m32r and SYSCALLS.def.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Several URLs are no longer valid; in particular kernel.org no longer
provides FTP service.
Unencrypted HTTP and git transports are also insecure, and we can use
HTTP-S for everything now.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
maketar.sh depends on the long-dead cogito tools, and makerpm.sh
depends on maketar.sh. But apparently no-one needs them, so delete
them.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
On 64-bit architectures F_{GETLK,SETLK{,W}}64 are *not* aliases for
the non-64 fcntl numbers and are not implemented at all. Only use
them in 32-bit configurations.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Unless we use the "-nostdinc" option, gcc will implicitly include
<bits/stdc-predef.h>, which is usually provided by glibc. This is
part of $(KLIBCCPPFLAGS) which we generally include in compiler
command lines. Add it to alpha's special rules for compiling the
division subroutines.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
klibc targets the latest kernel version, and the m32r kernel port
was removed in Linux 4.17. Remove our support for it.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Since the UAPI/KAPI header split in Linux 3.7, we have needed
KLIBCKERNELSRC to point to the installed UAPI headers. Invoking
"make headers_install" in this directory doesn't work.
The previously proposed fix was to invoke make in the parent
directory. But since we require the headers to be installed
already, we can copy the install tree instead. Make sure to
dereference any symbolic links while doing this.
Reported-by: Thomas Meyer <thomas@m3y3r.de>
Reported-by: Luis R. Rodriguez <mcgrof@kernel.org>
Link: https://www.zytor.com/pipermail/klibc/2019-January/004033.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Since the UAPI/KAPI header split in Linux 3.7, we have needed
KLIBCKERNELSRC to point to the installed UAPI headers. The "sample
invocation" has been updated to reflect this but the rest of the help
text has not.
Link: https://www.zytor.com/pipermail/klibc/2019-January/004032.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Since the UAPI/KAPI header split in Linux 3.7, we have needed
KLIBCKERNELSRC to point to the installed UAPI headers. This makes
KLIBCKERNELOBJ and the extra header directories based on it completely
redundant.
Link: https://www.zytor.com/pipermail/klibc/2019-January/004031.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
The error message for a missing $(KLIBCKERNELSRC) won't appear
unless it's specified as a target or something depends on it.
Make the klcc and klibc targets depend on it.
Link: https://www.zytor.com/pipermail/klibc/2019-January/004030.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
We link all executables as non-relocatable, so it makes no sense to
generate PIE code. In addition, PIE code on i386 requires a working
GOT which we don't generate.
Link: https://www.zytor.com/pipermail/klibc/2019-January/004028.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Building klibc for i386 with binutils 2.31 adds an extra
.note.gnu.property section to klibc.so, the address of which is not
affected by the -Ttext option. Loading a klibc executable then
fails with the following kernel log message:
9409 (sh.shared): Uhuuh, elf segment at 0000000000600000 requested but the memory is mapped already
I don't exactly see why this is happening, but it is triggered by the
new section and the collision can be avoided by passing -Ttext-segment
instead of -Ttext, similarly to x86_64.
Link: https://www.zytor.com/pipermail/klibc/2019-January/004027.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Building klibc for x86_64 with binutils 2.31 adds an extra
.note.gnu.property section to klibc.so, the address of which is not
affected by the -Ttext option. Loading a klibc executable then
fails with the following kernel log message:
9409 (sh.shared): Uhuuh, elf segment at 0000000000200000 requested but the memory is mapped already
I don't exactly see why this is happening, but it is triggered by the
new section and the collision can be avoided by passing -Ttext-segment
instead of -Ttext. A similar change was applied to MIPS recently.
Link: https://www.zytor.com/pipermail/klibc/2019-January/004024.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|
|
Some distributions default to PIE for their compilers, which on sparc is passed
on to the assembler. Since the behaviour of %hi/%lo changes under PIC to become
GOT offsets, the current assembly files need adapting to not try to use a GOT
offset as an absolute address.
References: https://bugs.debian.org/885852
Link: https://www.zytor.com/pipermail/klibc/2018-July/004001.html
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
|