summary refs log tree commit diff
path: root/src/bltin/test.c (follow)
Commit message (Collapse)AuthorAge
* shell: Always use explicit large file APIHerbert Xu2020-05-15
| | | | | | | | | 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>
* builtin: Use test_access from NetBSD when faccessat is unavailableHerbert Xu2018-05-28
| | | | | | | | 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>
* builtin: Greater resolution in test -nt / test -otMartijn Dekker2018-03-22
| | | | | | | | | | | | | | | | | | | | | | | 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>
* builtin: Reset t_wp_op in testcmdHerbert Xu2015-08-13
| | | | | | | | 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>
* [BUILTIN] Fix "test -x" as root on FreeBSD 8Jonathan Nieder2014-11-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* [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>
* [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] 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.
* 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
|
* Initial import.Herbert Xu2005-09-26