| Commit message (Collapse) | Author | Age |
|
|
|
|
|
|
|
|
| |
There are some remaining stat/readdir calls in dash that may lead
to spurious EOVERFLOW errors on 32-bit platforms. This patch changes
them (as well as open(2)) to use the explicit large file API.
Reported-by: Tatsuki Sugiura <sugi@nemui.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
| |
The seconds part of the times(1) built-in is wrong as it does not
exclude the minutes part of the result. This patch fixes it.
This problem was first noted by Michael Greenberg who also sent
a similar patch.
Reported-by: Michael Greenberg <michael.greenberg@pomona.edu>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
This reverts commit 7bb413255368e94395237d789f522891093c5774.
The commit breaks printf with more than argument.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
| |
The patch to make outc into an inline function created an unnecessary
promotion in echocmd due to its use of char vs. the int used by outc.
This patch changes echocmd to use int instead.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
- Solaris lacks paths.h and the various _PATH_* #defines.
Check for them in configure.ac and fall back on the
usual suspects when they are missing.
- Older Solaris lacks isblank(), and versions that have it
use a macro. Check for the declaration in configure.ac
and fall back on a naive version when missing.
- Older Solaris does not support %jd (intmax_t) in format
strings, but it does support the PRIdMAX macro from inttypes.h.
Do a configure check for PRIdMAX and use it in the code.
If it doesn't exist, define it to "lld" when sizeof(long long)
equals sizeof(intmax_t) as this is more likely to work on
older systems. Otherwise, use "jd" and hope for the best.
- Older Solaris lacks stdint.h, but inttypes.h provides the
same types and works on all platforms I've tried dash on,
so just use it instead.
- Older Solaris doesn't like it when vsnprintf() is passed
a NULL buffer (in violation of the POSIX spec, of course).
Pass a 1-byte dummy buffer instead.
- Solaris lacks tempfile and mktemp programs. Fall back on a
"good-enough" custom function in mkbuiltins.
Signed-off-by: Brian Koropoff <bkoropoff@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
| |
Eric Blake suggested that we should use faccessat so that ACLs
and other corner cases are handled correctly. This patch does
exactly that.
Note that faccessat doesn't handle ACLs when euid != uid, as
this case is currently implemented by glibc instead of the kernel,
using code similar to the existing dash test.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
| |
The previous two changes were broken because t_lex uses global state.
This patch removes that by making t_wp local to t_lex.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
| |
Making these functions non-recursive is straightforward since they
carry no state.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
----- Forwarded message from Gerrit Pape <pape@smarden.org> -----
Subject: Bug#455828: dash: 4-argument test "test \( ! -e \)" yields an error
Date: Fri, 28 Dec 2007 08:53:29 +0000
From: Gerrit Pape <pape@smarden.org>
To: Vincent Lefevre <vincent@vinc17.org>, 455828@bugs.debian.org
On Thu, Dec 27, 2007 at 06:23:20PM +0100, Vincent Lefevre wrote:
> On 2007-12-27 16:00:06 +0000, Gerrit Pape wrote:
> > On Wed, Dec 12, 2007 at 02:18:47AM +0100, Vincent Lefevre wrote:
> > > According to POSIX[*], "test \( ! -e \)" is a 4-argument test and is
> > > here equivalent to "test ! -e". But dash (like ksh93 and bash) yields
> > > an error:
> > >
> > > $ test \( ! -e \) || echo $?
> > > test: 1: closing paren expected
> > > 2
> > > $ test ! -e || echo $?
> > > 1
> >
> > Hi Vincent,
> >
> > the -e switch to test takes an argument, a pathname.
>
> According to POSIX, in both above examples, "-e" is *not* a switch,
> just a string.
>
> test \( ! -e \)
>
> means: return true if the string "-e" is empty, otherwhise return false.
> The error in dash is that it incorrectly thinks that "-e" is a switch in
> this context.
I see, you're right. Thanks, Gerrit.
----- End forwarded message -----
This patch hard-codes the 3,4-argument cases in the way required by
POSIX.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
|
|
|
|
|
| |
This patch adds the function atomax10 and uses it in test(1) so that we
support intmax_t comparisons.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* Speed up (libc=glibc):
deen:debian/src/dash-0.5.3# echo $(((7853+8631+7529+9777+9161+7552)/6))
8417,8250 # this patch
deen:/mnt/work/debian/src/dash-0.5.3# echo $(((9553+7789+9450+9925+7595+9590)/6))
8983 # short
deen:debian/src/dash-0.5.3# echo $(( (9655+7853+9733+7826+9618+10053)/6 ))
9123 # '[' ']'
deen:debian/src/dash-0.5.3#
deen:debian/src/dash-0.5.3# echo $(((9231+9423+9365+9650+8883+8291)/6))
9140 # unpatched
deen:debian/src/dash-0.5.3#
* Size down:
olecom@deen:/mnt/debian/src/dash-0.5.3$ size src/test.o # this patchset
text data bss dec hex filename
4142 0 16 4158 103e src/test.o
olecom@deen:/mnt/debian/src/dash-0.5.3$ size src/test.o
text data bss dec hex filename
4209 0 16 4225 1081 src/test.o
olecom@deen:/mnt/debian/src/dash-0.5.3$
|
|
|
|
| |
Some trailing whitespace was killed or tabified.
|
|
|
|
|
| |
Check getgroups() and fwrite() return code, required to build with
-D_FORTIFY_SOURCE=2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
On Thu, Nov 03, 2005 at 07:16:53PM +0100, Mike Hommey wrote:
> Here is a simple test case:
>
> #!/bin/dash
> echo test\\ test
> echo '\c'
> echo test\\ test
>
> it outputs:
> test\ test
> test\
>
> This is due to mis-usage of a global variable. See attached patch for a
> fix.
Instead of setting rval when \c is detected, this is now set in the
return value of conv_escape_str. This prevents the spillage reported
in http://bugs.debian.org/337294.
|
|
|
|
|
| |
Instead of calling conv_escape_str when we detect a backslash we will call it
unconditionally. This helps get rid of some unnecessary code in echocmd.
|
|
|
|
| |
Add a dummy sysconf implementation that always fails for klibc.
|
|
|
|
|
| |
Let's remove the support for standalone support from test for the same
reason as printf.
|
|
|
|
|
| |
The support for standalone/csh printf only serves to complicate
maintainence.
|
|
|
|
|
|
|
|
|
|
|
| |
This change updates the BSD licence to the three-clause version since
NetBSD has already done so. This makes dash GPL-compatible.
It also adds Christos Zoulas (NetBSD ash maintainer) to the COPYING file.
I've added "copyright by Herbert Xu" to most files.
Finally all CVS IDs and inclusion of sys/cdefs.h have been removed.
The latter is needed for support of klibc.
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|