Commit Graph

1002 Commits

Author SHA1 Message Date
Jilles Tjoelker
d69e16c977 sh: Add tests for lines that look like heredoc delimiters but are not. 2011-05-14 14:19:30 +00:00
Jilles Tjoelker
07eb7033a6 sh: Add \u/\U support (in $'...') for UTF-8.
Because we have no iconv in base, support for other charsets is not
possible.

Note that \u/\U are processed using the locale that was active when the
shell started. This is necessary to avoid behaviour that depends on the
parse/execute split (for example when placing braces around an entire
script). Therefore, UTF-8 encoding is implemented manually.
2011-05-08 17:40:10 +00:00
Jilles Tjoelker
7cc6b3df80 sh: Add UTF-8 support to pattern matching.
?, [...] patterns match codepoints instead of bytes. They do not match
invalid sequences. [...] patterns must not contain invalid sequences
otherwise they will not match anything. This is so that ${var#?} removes the
first codepoint, not the first byte, without putting UTF-8 knowledge into
the ${var#pattern} code. However, * continues to match any string and an
invalid sequence matches an identical invalid sequence. (This differs from
fnmatch(3).)
2011-05-08 11:32:20 +00:00
Jilles Tjoelker
4c244ed255 sh: Add UTF-8 support to ${#var}.
If the current locale uses UTF-8, ${#var} counts codepoints (more precisely,
bytes b with (b & 0xc0) != 0x80).
2011-05-07 14:32:16 +00:00
Jilles Tjoelker
a62ab0274a sh: Add $'quoting' (C-style escape sequences).
A string between $' and ' may contain backslash escape sequences similar to
the ones in a C string constant (except that a single-quote must be escaped
and a double-quote need not be). Details are in the sh(1) man page.

This construct is useful to include unprintable characters, tabs and
newlines in strings; while this can be done with a command substitution
containing a printf command, that needs ugly workarounds if the result is to
end with a newline as command substitution removes all trailing newlines.

The construct may also be useful in future to describe unprintable
characters without needing to write those characters themselves in 'set -x',
'export -p' and the like.

The implementation attempts to comply to the proposal for the next issue of
the POSIX specification. Because this construct is not in POSIX.1-2008,
using it in scripts intended to be portable is unwise.

Matching the minimal locale support in the rest of sh, the \u and \U
sequences are currently not useful.

Exp-run done by: pav (with some other sh(1) changes)
2011-05-05 20:55:55 +00:00
Jilles Tjoelker
3937fc9c26 sh: Apply set -u to variables in arithmetic.
Note that this only applies to variables that are actually used.
Things like (0 && unsetvar) do not cause an error.

Exp-run done by: pav (with some other sh(1) changes)
2011-05-04 22:12:22 +00:00
Jilles Tjoelker
fc0818fef3 sh: Detect an error for ${#var<GARBAGE>}.
In particular, this makes things like ${#foo[0]} and ${#foo[@]} errors
rather than silent equivalents of ${#foo}.

PR:		bin/151720
Submitted by:	Mark Johnston
Exp-run done by: pav (with some other sh(1) changes)
2011-05-04 21:49:34 +00:00
Jonathan Anderson
ceb42a13a1 Regression tests for Capsicum capability mode.
Ensure that system calls that access global namespaces, e.g. open(2), are not permitted, and that whitelisted sysctls like kern.osreldate are.

Approved by: rwatson
Sponsored by: Google, Inc.
2011-05-04 12:44:46 +00:00
Jilles Tjoelker
03b3a844d0 sh: Set $? to 0 for background commands.
For backgrounded pipelines and subshells, the previous value of $? was being
preserved, which is incorrect.

For backgrounded simple commands containing a command substitution, the
status of the last command substitution was returned instead of 0.

If fork() fails, this is an error.
2011-04-25 20:54:12 +00:00
Jilles Tjoelker
45496405c6 sh: Allow EV_EXIT through function calls, make {...} <redir more consistent.
If EV_EXIT causes an exit, use the exception mechanism to unwind
redirections and local variables. This way, if the final command is a
redirected command, an EXIT trap now executes without the redirections.

Because of these changes, EV_EXIT can now be inherited by the body of a
function, so do so. This means that a function no longer prevents a fork
before an exec being skipped, such as in
  f() { head -1 /etc/passwd; }; echo $(f)

Wrapping a single builtin in a function may still cause an otherwise
unnecessary fork with command substitution, however.

An exit command or -e failure still invokes the EXIT trap with the
original redirections and local variables in place.

Note: this depends on SHELLPROC being gone. A SHELLPROC depended on
keeping the redirections and local variables and only cleaning up the
state to restore them.
2011-04-23 22:28:56 +00:00
Simon L. B. Nielsen
d95c6beaac Expand / correct newsyslog regression tests:
- Test newslog with clasic naming of rotates files to actually test
  the correct number of log files as newsyslog now does the correct
  thing post r220926.
- Add some more newsyslog tests which tests keeping 0, 1, and 2
  logfiles.
2011-04-21 16:40:34 +00:00
Jilles Tjoelker
caa7ccdc54 sh: Do not word split "${#parameter}".
This is only a problem if IFS contains digits, which is unusual but valid.

Because of an incorrect fix for PR bin/12137, "${#parameter}" was treated
as ${#parameter}. The underlying problem was that "${#parameter}"
erroneously added CTLESC bytes before determining the length. This
was properly fixed for PR bin/56147 but the incorrect fix was not backed
out.

Reported by:	Seeker on forums.freebsd.org
MFC after:	2 weeks
2011-04-20 22:24:54 +00:00
Jilles Tjoelker
1e5dccaa9b sh: Add test for bin/12137. 2011-04-15 15:33:24 +00:00
Jilles Tjoelker
9638724dc8 sh: Add test for obscure and ambiguous ${#?}. 2011-04-15 15:26:05 +00:00
Jilles Tjoelker
149cf1e03b sh: Add test for bin/56147. 2011-04-15 15:14:58 +00:00
Jilles Tjoelker
2973057493 Allow strerror(0) and strerror_r(0, ...).
Of course, strerror_r() may still fail with ERANGE.

Although the POSIX specification said this could fail with EINVAL and
doing this likely indicates invalid use of errno, most other
implementations permitted it, various POSIX testsuites require it to
work (matching the older sys_errlist array) and apparently some
applications depend on it.

PR:		standards/151316
MFC after:	1 week
2011-04-05 21:56:05 +00:00
Edward Tomasz Napierala
a8e852babc Add test for acl_is_trivial_np(3). 2011-03-22 17:26:56 +00:00
Jilles Tjoelker
35c641ed21 sh: Fix some parameter expansion variants ${#...}.
These already worked: $# ${#} ${##} ${#-} ${#?}
These now work as well: ${#+word} ${#-word} ${##word} ${#%word}

There is an ambiguity in the standard with ${#?}: it could be the length of
$? or it could be $# giving an error in the (impossible) case that it is not
set. We continue to use the former interpretation as it seems more useful.
2011-03-13 20:02:39 +00:00
Pawel Jakub Dawidek
fb7db28c25 POSIX accepts only ELOOP if O_NOFOLLOW is specified and target is a symlink. 2011-03-13 19:35:13 +00:00
Jilles Tjoelker
18584d14e3 sh: Add some tests for ${#parameter}. 2011-03-13 16:20:38 +00:00
Rebecca Cran
d7d3cbdadf Fix warnings and style(9) issues.
Set WARNS to 6.
2011-03-12 14:47:54 +00:00
Pawel Jakub Dawidek
87c7a11664 Add some missing consts. 2011-03-12 14:09:43 +00:00
Pawel Jakub Dawidek
7ab5d09839 Add support for *at syscalls:
- openat(2)
- unlinkat(2)
- mkdirat(2)
- linkat(2)
- symlinkat(2)
- renameat(2)
- mkfifoat(2)
- mknodat(2)
- fchmodat(2)
- fchownat(2)
- fstatat(2)
2011-03-10 21:00:30 +00:00
Pawel Jakub Dawidek
97b700501b Improve test a bit, now that we have fstat(2) support.
The test was support to check if SUID/SGID bits are removed on first
write, but actually we were checking if they were removed after close.
Now we can check if SUID/SGID bits are gone after first write.

While here add checks to see if when both SUID and SGID bits are set they are
both cleared on first write.
2011-03-10 20:59:02 +00:00
Pawel Jakub Dawidek
7a0452188b Few initial ftruncate(2) tests. One of them covers stand/154873.
PR:	stand/154873
2011-03-09 23:11:30 +00:00
Pawel Jakub Dawidek
7535f6533c Pass descriptor number to write(2), now that it is possible. 2011-03-09 22:50:15 +00:00
Pawel Jakub Dawidek
446727a7a4 Add support for the following syscalls:
- fchmod(2),
- fchown(2),
- fchflags(2),
- fstat(2),
- ftruncate(2),
- fpathconf(2),
- lpathconf(2).
Make write(2) syscall to take descriptor instead of file name.

We implement descriptors by keeping track of open files and allowing to
reference them by the following syscalls. Because pjdfstest already supports
executing multiple syscalls from one command it works pretty well.

For example, the following command:

	pjdfstest open foo "O_CREAT,O_RDWR" 0 : open bar "O_CREAT,O_RDONLY" 640 : fchmod 0 0666 : fchown 0 -1 20 : fchmod 1 0444

is equivalent of (error checking omitted):

	int fd[2];

	fd[0] = open("foo", O_CREAT | O_RDWR, 0);
	fd[1] = open("bar", O_CREAT | O_RDONLY, 0640);
	fchmod(fd[0], 0666);
	fchown(fd[0], -1, 20);
	fchmod(fd[1], 0444);
2011-03-09 22:39:10 +00:00
Jilles Tjoelker
7b8b6c9c46 sh: Test that . /dev/null returns exit status 0 and does not preserve $?.
Preserving $? may cause problems particularly if set -e is in effect.

It may be useful to preserve the old value of $? in the dot script but this
must not be implemented in such a way that it would break this test.
2011-03-07 23:52:23 +00:00
David Schultz
2dc9da4376 Add some tests for cexp() and cexpf(). (I need to clean up all of
these tests some day, but in the mean time, they're a useful sanity
check for future changes.)
2011-03-07 03:15:49 +00:00
Edward Tomasz Napierala
62089c2843 One more fix. Now all ACL tests pass again. 2011-03-04 18:46:19 +00:00
Edward Tomasz Napierala
aa25dc0272 Adapt tools-crossfs.test to the new semantics. 2011-03-04 18:37:26 +00:00
Edward Tomasz Napierala
6b2094d83c Adapt NFSv4 ACL regression test to the fact that the new ZFS uses
new semantics.
2011-03-04 17:10:39 +00:00
Edward Tomasz Napierala
b5b5b80711 Make ACL tests slightly easier to run. 2011-03-04 17:07:02 +00:00
Xin LI
eaea8924ce Accept == as an alias of = which is a popular GNU extension.
This is intentionally undocumented for now since it's not part
of any standard.

MFC after:	1 month
2011-02-27 12:28:06 +00:00
Martin Wilke
dd41c1d72e - Fix QA issues
PR:		misc/146687
Submitted by:	Garrett Cooper <gcooper@FreeBSD.org>
Approved by:	rwatson (mentor)
2011-02-22 05:13:26 +00:00
Jilles Tjoelker
553870e83b sh: Add some tests for omitting whitespace whereever possible. 2011-02-20 17:28:58 +00:00
Jilles Tjoelker
a9942298fe sh: Split off some special behaviour into separate tests.
This allows some other shells to pass the tests for basic behaviour.
2011-02-20 14:18:58 +00:00
Jilles Tjoelker
9d59796db7 sh: Do not use "local" in the test runner as POSIX and ksh93 do not have it. 2011-02-19 13:23:13 +00:00
Jilles Tjoelker
3d9394a391 sh: Make execution/fork1.0 work even if the basename of ${SH} is not "sh". 2011-02-19 13:22:18 +00:00
Jilles Tjoelker
e8d17ee524 sh: Test that the read builtin passes through all byte values
except NUL, newline and backslash.

This also passes on stable/8.
2011-02-18 20:51:13 +00:00
Jilles Tjoelker
cfd69ae791 sh: Unset some more locale vars in two tests that may cause them to break. 2011-02-18 20:37:09 +00:00
Jilles Tjoelker
e9749129ad sh: Detect dividing the smallest integer by -1.
This overflows and on some architectures such as amd64 it generates SIGFPE.
Generate an error on all architectures.
2011-02-12 23:44:05 +00:00
Jilles Tjoelker
f01be3fe53 sh: Add tests for new features in arithmetic. 2011-02-08 23:23:55 +00:00
Jilles Tjoelker
e029e397f3 sh: Weaken some tests to allow /rescue/sh to pass everything.
/rescue/sh has a different _PATH_STDPATH which affects command -p.
2011-02-05 23:00:24 +00:00
Jilles Tjoelker
b15e9aa322 sh: Fix two things about {(...)} <redir:
* In {(...) <redir1;} <redir2, do not drop redir1.
* Maintain the difference between (...) <redir and {(...)} <redir:
  In (...) <redir, the redirection is performed in the child, while in
  {(...)} <redir it should be performed in the parent (like {(...); :;}
  <redir)
2011-02-05 15:02:19 +00:00
Jilles Tjoelker
ef0cb80dd4 sh: Forget all cached command locations on any PATH change.
POSIX requires this and it is simpler than the previous code that remembered
command locations when appending directories to PATH.

In particular,
  PATH=$PATH
is no longer a no-op but discards all cached command locations.
2011-02-05 14:01:46 +00:00
Jilles Tjoelker
604e8224f8 sh: Do not try to execute binary files as scripts.
If execve() returns an [ENOEXEC] error, check if the file is binary before
trying to execute it using sh. A file is considered binary if at least one
of the first 256 bytes is '\0'.

In particular, trying to execute ELF binaries for the wrong architecture now
fails with an "Exec format error" message instead of syntax errors and
potentially strange results.
2011-02-05 12:54:59 +00:00
Jilles Tjoelker
0df2165c11 sh: Add test for shell script without '#!'. 2011-02-02 22:03:18 +00:00
Jilles Tjoelker
b9f696953d sh: Send messages about signals to stderr.
This is required by POSIX and seems to make more sense.

See also r217557.
2011-01-30 22:57:52 +00:00
Jilles Tjoelker
8c3afde82c sh: Add test for EXIT trap in command substitution.
This is not really realistic but is an opposition to $(trap).
2011-01-27 23:08:20 +00:00