Commit Graph

2941 Commits

Author SHA1 Message Date
ngie
bf233cc247 MFC r289487:
Integrate contrib/netbsd-tests/bin/dd into the FreeBSD test suite as
bin/dd/tests

Ensure fdescfs is mounted on /dev/fd/ for the length testcase as it's used
in validating the characters read from /dev/zero

Sponsored by: EMC / Isilon Storage Division
2015-11-09 06:50:42 +00:00
ngie
74ca3bfeb1 MFC r289488:
Clean up trailing whitespace
2015-10-26 00:05:02 +00:00
ngie
692c6b0c3a MFC r288330,r288423,r288678,r288905,r288906,r288907,r289102:
r288330:

Add initial testcases for bin/ls

Sponsored by: EMC / Isilon Storage Division

r288423:

Skip the B_flag testcase to stop blowing up freebsd-current@ with
"test failure emails" because kyua report-jenkins doesn't properly
escape non-printable chars

r288678:

Merge additional testcases and improvements to bin/ls/ls_tests from
^/user/ngie/more-tests.

- Additional testcases added:
-- ls -D
-- ls -F
-- ls -H
-- ls -L
-- ls -R
-- ls -S
-- ls -T
-- ls -b
-- ls -d
-- ls -f
-- ls -g
-- ls -h
-- ls -i
-- ls -k
-- ls -l
-- ls -m
-- ls -n
-- ls -o
-- ls -p
-- ls -q/ls -w
-- ls -r
-- ls -s
-- ls -t
-- ls -u
-- ls -y
- Socket file creation is limited to the ls -F testcase, greatly speeding up
  the test process
- The ls -C testcase was made more robust by limiting the number of columns
  via COLUMNS and by dynamically formulating the columns/lines.
- Add `atf_test_case` before all testcase `head` functions.

Sponsored by: EMC / Isilon Storage Division

r288905:

Add some more syncs to quiesce the filesystem after creating the
files to see if this fixes deterministic Jenkin failures

r288906:

Explicitly set BLOCKSIZE to 512 in the environment

r288907:

Call sync consistently using atf_check

Remove superfluous sync's

r289102:

Remove all of the syncs

They're unnecessary as shown by further testing on my VM

Requested by: jhb
2015-10-25 23:03:04 +00:00
jilles
aff97c8f1f MFC r288430: wordexp: Rewrite to make WRDE_NOCMD reliable.
Shell syntax is too complicated to detect command substitution and unquoted
operators reliably without implementing much of sh's parser. Therefore, have
sh do this detection.

While changing sh's support anyway, also read input from a pipe instead of
arguments to avoid {ARG_MAX} limits and improve privacy, and output count
and length using 16 instead of 8 digits.

The basic concept is:
execl("/bin/sh", "sh", "-c", "freebsd_wordexp ${1:+\"$1\"} -f "$2",
    "", flags & WRDE_NOCMD ? "-p" : "", <pipe with words>);

The WRDE_BADCHAR error is still implemented in libc. POSIX requires us to
fail strings containing unquoted braces with code WRDE_BADCHAR. Since this
is normally not a syntax error in sh, there is still a need for checking
code in libc, we_check().

The new we_check() is an optimistic check that all the characters
  <newline> | & ; < > ( ) { }
are quoted. To avoid duplicating too much sh logic, such characters are
permitted when quoting characters are seen, even if the quoting characters
may themselves be quoted. This code reports all WRDE_BADCHAR errors; bad
characters that get past it and are a syntax error in sh return WRDE_SYNTAX.

Although many implementations of WRDE_NOCMD erroneously allow some command
substitutions (and ours even documented this), there appears to be code that
relies on its security (codesearch.debian.net shows quite a few uses).
Passing untrusted data to wordexp() still exposes a denial of service
possibility and a fairly large attack surface.

This is also a MFC of r286830 to reduce conflicts. I changed the code
somewhat to avoid changes from r286941; in particular, WRDE_BADVAL can still
only be returned if WRDE_UNDEF was passed.

Relnotes:	yes
Security:	fixes command execution with wordexp(untrusted, WRDE_NOCMD)
2015-10-25 17:17:50 +00:00
delphij
8d98cd2211 MFC r287237: Respect locale settings. 2015-09-14 17:57:01 +00:00
delphij
bdd5bccf11 MFC r287236:
Use exit() instead of return in main().  The difference in practice
is subtle: C standard requires the language runtime to make return
of int from main() behave like calling exit(), and in FreeBSD we do:

	exit(main(argc, argv, env))

In lib/csu/${ARCH}/crt1.c, so the real difference is using exit()
explicitly would use an additional stack frame.

Note however, if there is a on stack pointer is the last reference
of an allocated memory block, returning from the function would,
technically, result in a memory leak because we lost the last
reference to the memory block, and calling exit() from C runtime
could potentionally overwrite that stack frame that used to belong
to the main() function.

In practice, this is normally Okay because eventually the kernel
would tear down the whole address space that belongs to the process
in the _exit(2) system call, but the difference could confuse
compilers (which may want to do stack overflow checks) and static
analyzers.

Replacing return with exit() in main() allows compilers/static
analyzers to correctly omit or generate the right warnings when
they do not treat main() specifically.  With the current version
of clang on FreeBSD/amd64, use of exit() would result in slightly
smaller code being generated and eliminated a false positive
warning of memory leak.
2015-09-14 17:40:57 +00:00
jilles
bc3c6d9c81 MFC r268436,273243,278806,280920,286971: sh: Add various tests.
These new tests from head pass with unmodified stable/10 sh.
2015-09-13 14:24:12 +00:00
jilles
4c6f14a861 MFC r287148: sh: Fix out of bounds read when there is no ] after a [:class:].
The initial check for a matching ] was incorrect if a ] may be consumed by a
[:class:]. The subsequent loop assumed that there must be a ].

Remove the initial check and make the loop cope with a missing ].

Found with afl-fuzz.
2015-09-13 13:58:46 +00:00
jilles
4918e13c30 MFC r278826,279330: sh: Various cleanups to expand.c:
* Remove some gotos.
* Remove unused parameter.
* Remove duplicate code.

This MFC is to avoid conflicts in the MFC of r287148.
2015-09-13 13:52:54 +00:00
jilles
71d275cef1 MFC r272575: sh: Eliminate some gotos.
This MFC is to avoid conflicts in the MFC of r287148.
2015-09-13 13:43:08 +00:00
jilles
e646354b48 MFC r287081: sh: Don't create bad parse result when postponing a bad
substitution error.

An invalid substitution like ${var@} does not cause a parse error but is
stored in the intermediate representation, to be written as part of the
error message. If there is a CTL* byte in the stored part, this confuses
some code such as the code to skip an unused alternative such as in
${var-alternative}.

To keep things simple, do not store CTL* bytes.

Found with afl-fuzz.
2015-09-13 13:31:51 +00:00
jamie
9e4b124ba9 MFC r287012:
Make pkill/pgrep -j ARG take jname, not just jid.

PR:		201588
Submitted by:	Daniel Shahaf <danielsh at apache.org>
2015-08-29 02:41:59 +00:00
jilles
403ac3fe2a MFC r284916: mv: Improve message when moving two or more files to
non-directory.

The message text is from cp, which has had a nicer message for this since
2007 (PR bin/50656).

As with cp, the exit status changes from 64 to 1.

PR:		201083
2015-08-22 21:35:35 +00:00
jilles
aa479658a0 MFC r284779: sh: Fix some arithmetic undefined behaviour.
Fix shifts of possibly negative numbers found with ubsan and avoid signed
integer overflow when hashing an extremely long command name.
2015-08-15 19:58:00 +00:00
des
5daf218e81 MFH (r277531): don't include newvers in freebsd-version 2015-07-02 11:46:40 +00:00
des
fdde4f4cd7 MFH (r275659): fix dependency on newvers.sh 2015-06-30 15:32:57 +00:00
delphij
56a4d3de60 MFC r283257:
Eliminate unneeded includes.
2015-06-05 00:39:34 +00:00
smh
3236725806 MFC r282208:
Standardise chmod, chflags, chown and chgrp recursive symlink processing

Relnotes:	Yes
Sponsored by:	Multiplay
2015-06-01 09:04:57 +00:00
rodrigc
26d3f673f7 Merge: 278618 278633 278636 278653 278742 278776 279121
Multiple fixes for pgrep and pkill tests.

PR: 19109
2015-05-23 09:48:59 +00:00
delphij
f14ca7e990 MFC r282608:
date(1): Make -r behave like GNU's version when the option can not be
interpreted as a number, which checks the file's modification time and
use that as the date/time value.

This improves compatibility with GNU coreutils's version of date(1).
2015-05-21 18:59:11 +00:00
jilles
c595c29b97 MFC r282482: cp: Remove fts sorting.
In an attempt to improve performance, cp reordered directories first
(although the comment says directories last). This is not effective with new
UFS layout policies.

The sorting reorders multiple arguments passed to cp, which may be
undesirable.

Additionally, the comparison function does not induce a total order. Per
POSIX, this causes undefined behaviour in qsort().

NetBSD removed the sorting in 2009.

On filesystems that return directory entries in hash/btree order, sorting by
d_fileno before statting improves performance on large directories. However,
this can only be implemented in fts(3).

PR:		53475
Reviewed by:	bde (in 2004)
2015-05-14 10:46:20 +00:00
tijl
b709ec868a MFC r275805:
Fix incorrect type of "invalids" argument in __iconv() prototype.

MFC r281550,281591:

Remove the const qualifier from iconv(3) to comply with POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/iconv.html

Adjust all code that calls iconv.

PR:		199099
2015-04-30 16:08:47 +00:00
eadler
07d63652f3 MFC r280206:
Implement pax -O option to permit limiting a PAX archive to a single volume.

-O Force the archive to be one volume.  If a volume ends prematurely, pax will
not prompt for a new volume.

PR:		198481
2015-04-17 18:33:59 +00:00
dim
cb046ee5e6 MFC r280357:
Build expr with -fwrapv, since it relies on signed integer wrapping
having defined behavior.

Reported by:	rodrigc
2015-04-06 14:45:40 +00:00
jilles
051c616980 MFC r278848: symlink(7): Mention chflagsat() (can take AT_SYMLINK_NOFOLLOW). 2015-03-10 22:23:56 +00:00
jilles
0bf8cb7b51 MFC r276359: symlink(7): Note that stat(1) does not follow symlinks by
default.
2015-02-08 22:46:29 +00:00
ngie
15c31aa79c MFC r277358:
r277358 (by ngie):

  Integrate contrib/netbsd-tests/bin/expr into the build/kyua as bin/expr/tests

  Sponsored by: EMC / Isilon Storage Division
2015-01-26 11:49:06 +00:00
jilles
6f128b2d1a MFC r274254: sh(1): Mention portability issue with shifting zero positional
parameters.

Per Austin Group issue #459, shifting zero positional parameters may or may
not be considered an operand error (which causes the shell to exit in most
cases).
2015-01-04 19:02:50 +00:00
jilles
973fc27d21 MFC r271936: sh(1): Clarify that assignments before commands do not affect
expansions.

PR:		193759
2015-01-04 18:58:51 +00:00
ngie
0971283da1 MFC r272777,r272779,r272780,r272781,r272782,r272783,r272784,r272787,r272788:
r272777:

  Integrate usr.sbin/nmtree/tests from NetBSD into atf/kyua

  In collaboration with: pho
  Sponsored by: EMC / Isilon Storage Division

r272779:

  Integrate usr.sbin/basename/tests from NetBSD into atf/kyua

  In collaboration with: pho
  Sponsored by: EMC / Isilon Storage Division

r272780:

  Integrate usr.bin/cmp/tests from NetBSD into atf/kyua

  In collaboration with: sjg
  Sponsored by: EMC / Isilon Storage Division

r272781:

  Integrate usr.bin/dirname/tests from NetBSD into atf/kyua

  In collaboration with: pho, sjg
  Sponsored by: EMC / Isilon Storage Division

r272782:

  Integrate bin/sleep/tests from NetBSD into atf/kyua

  Sponsored by: EMC / Isilon Storage Division

r272783:

  Integrate usr.bin/cut/tests from NetBSD into atf/kyua

  Sponsored by: EMC / Isilon Storage Division

r272784:

  Integrate usr.bin/grep/tests from NetBSD into atf/kyua

  Sponsored by: EMC / Isilon Storage Division

r272787:

  Integrate usr.bin/diff/tests from NetBSD into atf/kyua at gnu/usr.bin/diff/tests

  Sponsored by: EMC / Isilon Storage Division

r272788:

  Integrate usr.bin/gzip/tests from NetBSD into atf/kyua

  Sponsored by: EMC / Isilon Storage Division
2015-01-01 02:04:44 +00:00
jilles
52bfb3cdd3 MFC r276037: sh: Remove EXP_REDIR.
EXP_REDIR was supposed to generate pathnames in redirection if exactly one
file matches, as permitted but not required by POSIX in interactive mode. It
is unlikely this will be implemented.

No functional change is intended.
2014-12-29 15:33:20 +00:00
jilles
eae2f34920 MFC r274854: sh: Use DQSYNTAX only while expanding, not SQSYNTAX.
Quoting during expansion only cares about CCTL, which is the same for
DQSYNTAX and SQSYNTAX.
2014-12-29 15:15:27 +00:00
jilles
ca31dd6023 MFC r273920: sh: Fix corruption of CTL* bytes in positional parameters in
redirection.

EXP_REDIR was not being checked for while expanding positional parameters in
redirection, so CTL* bytes were not being prefixed where they should be.
2014-12-29 15:11:07 +00:00
kib
38f7dd4bb8 MFC r275745:
Add facility to stop all userspace processes.

MFC r275753:
Fix gcc build.

MFC r275820:
Add missed break.
2014-12-27 00:55:14 +00:00
jilles
df71c47219 MFC r268576: sh: Correctly handle positional parameters beyond INT_MAX on
64-bit systems.

Currently, there can be no more than INT_MAX positional parameters. Make
sure to treat all higher ones as unset to avoid incorrect results and
crashes.

On 64-bit systems, our atoi() takes the low 32 bits of the strtol() and
sign-extends them.

On 32-bit systems, the call to atoi() returned INT_MAX for too high values
and there is not enough address space for so many positional parameters, so
there was no issue.

PR:		195918
2014-12-14 18:30:30 +00:00
rodrigc
42bcc4fbac MFC r272305
Fix pkill unit test.
2014-10-05 02:52:54 +00:00
gjb
5f63f50572 MFC r268376 (imp):
rm -rf can fail sometimes with an error from fts_read. Make it
  honor fflag to ignore fts_read errors, but stop deleting from
  that directory because no further progress can be made.

  When building a kernel with a high -j value on a high core count
  machine, during the cleanobj phase we can wind up doing multiple
  rm -rf at the same time for modules that have subdirectories. This
  exposed this race (sometimes) as fts_read can return an error if
  the directory is removed by another rm -rf. Since the intent of
  the -f flag was to ignore errors, even if this was a bug in
  fts_read, we should ignore the error like we've been instructed
  to do.

Approved by:	re (kib)
Sponsored by:	The FreeBSD Foundation
2014-10-01 16:18:40 +00:00
ngie
0d7257f533 MFC r269903:
Port date/bin/tests to ATF

 Phabric: D545
 Approved by: jmmv (mentor)
 Submitted by: keramida (earlier version)
 Sponsored by: Google, Inc
 Sponsored by: EMC / Isilon Storage Division
2014-08-29 02:21:02 +00:00
pfg
564b330f17 MFC r270256:
Always check the limits of array index variables before using them.

Obtained from:	DragonFlyBSD
2014-08-28 18:11:05 +00:00
kib
afeea342d6 MFC r269656:
Implement and use proc_realparent(9).

MFC r270024 (by markj):
Correct the order of arguments passed to LIST_INSERT_AFTER().

For merge, the p_treeflag member of struct proc was moved to the end
of the structure, to keep KBI intact.
2014-08-21 10:46:19 +00:00
jilles
5d7615994f MFC r268429: Don't install locale1.0 if MK_NLS == no.
The test locale1.0 depends on locale support; it is meaningless without a
working LC_MESSAGES.

I added an OptionalObsoleteFiles.inc entry.

PR:		181151
Submitted by:	Garrett Cooper (original version)
Sponsored by:	EMC / Isilon Storage Division
2014-08-20 19:39:07 +00:00
asomers
5482ed4923 MFC r269977
Skip pgrep-j and pkill-j if jail or jls is not installed.

Even though jail is part of the base system, it can be disabled by src.conf
settings. Therefore, it should be listed as a required program for tests that
use it.
2014-08-18 20:21:12 +00:00
pluknet
42ff249abc MFC r267196:
Add support for inspecting process flags set in p_flag2.
2014-06-26 08:55:06 +00:00
thomas
e767419662 MFC rev. 265593:
(dd_out): Fix handling of all-zeroes block at end of input with
conv=sparse.

PR:		bin/189174
PR:		bin/189284
Reviewed by:	kib
2014-05-21 07:21:36 +00:00
bdrewery
a0f7dc4feb MFC r265229,r265239:
Add -J to filter by matching jail IDs and names.
2014-05-17 02:32:47 +00:00
dumbbell
ee189cb17a date(1): Add "-R" flag to use RFC 2822 date and time output format [MFC]
As stated in the man page, this is equivalent to use "%a, %d %b %Y %T %z"
as the output format while LC_TIME is set to the "C" locale.

This is compatible with date(1) from the GNU core utilities.

This is an MFC of r264968 and r264970.
2014-05-03 13:19:11 +00:00
jmmv
1e4589b921 MFC various moves of tools/regressions/ tests to the new infrastructure.
- r263220 Migrate tools/regression/sbin/ to the new tests layout.
- r263222 Add Makefile missed in r263220.
- r263226 Migrate tools/regression/{usr.bin/lastcomm,usr.sbin}/ to the new tests layout.
- r263227 Migrate most of tools/regression/usr.bin/ to the new tests layout.
- r263345 Expand tabs that sneaked in into spaces.
- r263346 Migrate tools/regression/usr.bin/make/ to the new tests layout.
- r263348 Add Makefiles missed in r263346.
- r263351 Migrate tools/regression/usr.bin/pkill/ to the new tests layout.
- r263388 Mark multi_test as requiring /usr/share/dict/words.
- r263814 Fix path to the run.pl script to let these tests run.
- r264742 Prevent building tests when bootstrapping make.

This is 'make tinderbox' clean.
2014-04-27 01:15:10 +00:00
delphij
4882a37127 MFC r264059+264067:
Implement GNU's extension of 'status' operand.  The GNU syntax is
borrowed where syntax status=noxfer means no transfer statistics
and status=none means no status information at all.

This feature is useful because the statistics information can
sometimes be annoying, and redirecting stderr to /dev/null would
mean error messages also gets silenced.

Obtained from:	OpenBSD
2014-04-17 00:31:20 +00:00
jilles
07966b660e MFC r263847: sh: Fix memory leak with an assignment before a regular builtin 2014-04-15 18:29:05 +00:00
jilles
7ba0eb2fc1 MFC r263846: sh: Fix memory leak when trying to set a read only variable. 2014-04-15 18:24:24 +00:00