summary refs log tree commit diff
path: root/src/bltin (follow)
Commit message (Collapse)AuthorAge
* [BUILTIN] Remove getintmax in printfHerbert Xu2014-10-27
| | | | | | | 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>
* [BUILTIN] Remove unnecessary restoration of format string in printfHerbert Xu2014-10-27
| | | | | | | | 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>
* [BUILTIN] Handle embedded NULs correctly in printfHerbert Xu2014-10-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [BUILTIN] Add printf support for format string a, A, and FHerbert Xu2014-10-27
| | | | | | | | 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>
* [BUILTIN] Correctly handle test ! ! = !Herbert Xu2014-09-28
| | | | | | | | | | | | 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>
* [BUILTIN] Fixed argument parsing crash in testHerbert Xu2013-08-23
| | | | | | | | | 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>
* [BUILTIN] Use PRIdMAX instead of %j in printfHarald van Dijk2013-08-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [BUILTIN] Eliminate unnecessary promotion in echocmdHerbert Xu2011-07-07
| | | | | | | | 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>
* [SHELL] Port to SolarisBrian Koropoff2011-03-15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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>
* [BUILTIN] Use faccessat if availableHerbert Xu2010-04-02
| | | | | | | | | | | | 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>
* [BUILTIN] Made t_lex reentrantHerbert Xu2008-07-13
| | | | | | | 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>
* [BUILTIN] Made aexpr/oexpr non-recursiveHerbert Xu2008-07-13
| | | | | | | Making these functions non-recursive is straightforward since they carry no state. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
* [BUILTIN] Fixed 3,4-argument cases for test per POSIXHerbert Xu2008-07-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ----- 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>
* [BUILTIN] Use intmax_t arithmetic in testHerbert Xu2007-10-06
| | | | | This patch adds the function atomax10 and uses it in test(1) so that we support intmax_t comparisons.
* [BUILTIN] test: little size and speed optimizationsOleg Verych2007-09-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | * 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$
* [BUILTIN] test: White space fixesOleg Verych2007-09-22
| | | | Some trailing whitespace was killed or tabified.
* [SYSTEM] Check return code for getgroups and fwriteAlexey Gladkov2006-10-13
| | | | | Check getgroups() and fwrite() return code, required to build with -D_FORTIFY_SOURCE=2.
* [BUILTIN] Fix \c spillage across echo commandsHerbert Xu2005-11-14
| | | | | | | | | | | | | | | | | | | | | 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.
* [BUILTIN] Always call conv_escape_str in echocmdHerbert Xu2005-11-13
| | | | | 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.
* [SYSTEM] Added dummy sysconf implementationHerbert Xu2005-10-29
| | | | Add a dummy sysconf implementation that always fails for klibc.
* [BUILTIN] Removed standalone/csh support from testHerbert Xu2005-10-29
| | | | | Let's remove the support for standalone support from test for the same reason as printf.
* [BUILTIN] Removed standalone/csh support from printfHerbert Xu2005-10-29
| | | | | The support for standalone/csh printf only serves to complicate maintainence.
* Copyright/licence updates and remove all traces of sys/cdefs.hHerbert Xu2005-10-29
| | | | | | | | | | | 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.
* Invert return value of test_eaccess and rename it to test_st_mode.herbert2005-09-26
|
* Eliminate duplicate stat in test_eaccess.herbert2005-09-26
|
* Optimised FILGZ test.herbert2005-09-26
|
* Enclose abort insode ifdef DEBUG.herbert2005-09-26
|
* Renamed error to sh_error.herbert2005-09-26
|
* Initial import.Herbert Xu2005-09-26