2972 Commits

Author SHA1 Message Date
pfg
84d7d30782 MFC r300322, 300340:
ed(1): Cleanups for the DES mode.

- Use arc4random_buf(3).
- Prevent a segmentation fault when ed receives a signal
  while being in getpass(). [1]

Obtained from:	OpenBSD [1] (CVS Rev. 1.15)
2016-06-03 03:20:54 +00:00
truckman
c119be2737 MFC r300692
Close the input FILE * in read_file() and the output FILE * in write_file()
if read_stream() or write_stream() fails to avoid leaking the FILE.

Reported by:	Coverity
CID:		977702
Reviewed by:	pfg
Differential Revision:	https://reviews.freebsd.org/D6554
2016-06-01 17:47:34 +00:00
truckman
281ac18e42 MFC r300649
Fix Coverity CID 1019054 (String not null terminated) in setfacl.

Increase the size of buf[] by one to allow room for a NUL character
at the end.

Reported by:	Coverity
CID:		1019054
2016-06-01 17:35:03 +00:00
truckman
efd2996ff9 MFC r300648
Fix CID 1011370 (Resource leak) in ps.

There is no need to to call strdup() on the value returned by fmt().
The latter calls fmt_argv() which always returns a dynamically
allocated string, and calling strdup() on that leaks the memory
allocated by fmt_argv().  Wave some const magic on ki_args and
ki_env to make the direct assignment happy.  This requires a tweak
to the asprintf() case to avoid a const vs. non-const mismatch.

Reported by:	Coverity
CID:		1011370
2016-06-01 17:33:02 +00:00
truckman
ed265b2890 MFC r300643
Close from_fd if malloc() fails to avoid a file descriptor leak.

Reported by:	Coverity
CID:		1007203
2016-06-01 17:30:50 +00:00
truckman
10d7f27879 MFC r300642
Match the descriptions of the \H and \h prompt string sequences to reality.
They were swapped.

X-Confirmed by:	jilles
2016-06-01 17:29:15 +00:00
truckman
841ce9904c MFC r300442
Hopefully fix Coverity CID 1008328 (Out-of-bounds write) in /bin/sh.

Replace the magic constant 127 in the loop interation count with
"PROMPTLEN - 1".

gethostname() is not guaranteed to NUL terminate the destination
string if it is too short. Decrease the length passed to gethostname()
by one, and add a NUL at the end of the buffer to make sure the
following loop to find the end of the name properly terminates.

The default: case is the likely cause of Coverity CID 1008328.  If
i is 126 at the top of the loop interation where the default case
is triggered, i will be incremented to 127 by the default case,
then incremented to 128 at the top of the loop before being compared
to 127 (PROMPTLENT - 1) and terminating the loop. Then the NUL
termination code after the loop will write to ps[128].  Fix by
checking for overflow before incrementing the index and storing the
second character in the buffer.

These fixes are not guaranteed to satisfy Coverity. The code that
increments i in the 'h'/'H' and 'w'/'W' cases may be beyond its
capability to analyze, but the code appears to be safe.

Reported by:	Coverity
CID:		1008328
Reviewed by:	jilles, cem
Differential Revision:	https://reviews.freebsd.org/D6482
2016-06-01 17:09:50 +00:00
vangyzen
0c387e6a51 MFC r299035: sh: Handle empty hostname and $PWD when building prompt
If the hostname is empty and \h is used in $PS1,
the remainder of the prompt following \h will be empty.
Likewise for $PWD and \w.  Fix it.
2016-05-11 22:11:37 +00:00
pfg
d58ddf1ae8 MFC r298640:
ed(1): switch two statements so we check the index before dereferencing.
2016-04-29 03:12:14 +00:00
thomas
ba53aa0560 MFC r295749:
Reorganize the handling all-zeroes terminal block in sparse mode

PR: 189284
(original PR whose fix introduced this bug)

PR: 207092
2016-04-19 07:34:31 +00:00
mp
c433aab6ad MFC 297673:
Revert r296969 by removing SAVESIGVEC and switching to fork instead. This
fixes usage with system libraries which maintain their own signal state.

PR:	208132
2016-04-10 18:12:04 +00:00
jilles
4c6d087886 MFC r277645: cp,mv,touch: Set timestamps with nanosecond precision.
This uses utimensat().
2016-04-10 15:02:29 +00:00
jilles
8699198909 MFC r259017: test: Avoid looking up again the type of a known binary
operator.
2016-04-09 21:55:58 +00:00
jilles
f631ef3d78 MFC r258799: test: Simplify the code by unifying op_num and op_type.
The global variable t_wp_op is no longer needed.
2016-04-09 21:49:57 +00:00
jilles
0b7191c4ed MFC r297360: sh: Fix use-after-free if a trap replaces itself.
The mergeinfo for this commit was accidentally added to the previous commit.
2016-04-09 14:24:17 +00:00
jilles
1a49b5f5b0 MFC r278818: sh: Add stsavestr(), like savestr() but allocates using
stalloc().
2016-04-09 14:09:14 +00:00
ume
ed9af0cb98 MFC r295147:
Make dynamic link of libiconv from ports work again.
  The symbols of libiconv from ports were changed to
  have prefixed.
  Since we have iconv in our libc these days, we don't
  need it on 10.X and later.  However, 9.X still need
  this.
2016-04-05 14:41:34 +00:00
mp
c2cc321146 MFC 296416:
Signal handling within tcsh vfork code path will conflict with some system
libraries (such as libthr) which maintain their own signal state. This
change adds the tcsh SAVESIGVEC option to save and restore the sigvecs for
the signals the child modifies before it execs.

Reviewed by:	kib, rwatson
Reported by:	kib
2016-03-17 00:32:29 +00:00
bdrewery
dc83b58bbe MFC r289677:
Fix a ton of speelling errors
2016-01-07 00:40:51 +00:00
pfg
923d09189e MFC r292877:
pax: prevent possible buffer overflow

Or at least quiet down some static analyzers about it.

CID:	978835
Obtained from:	OpenBSD
2016-01-06 16:32:39 +00:00
jilles
8eba600011 MFC r292517: sh/mknodes: Close files and check for errors when writing.
This is a build tool only and does not affect run time.

PR:		204951
2015-12-27 17:53:39 +00:00
pfg
1ee182fa5f MFC r292454, r292455
ed(1): Prevent possible string overflows

Use strlcpy to guarantee NULL termination.

With hint from:	imp, cem, ngie
CID:		1007252
2015-12-26 18:37:01 +00:00
jilles
ce8728e0fa MFC r292360: sh: Fix use-after-free when attempting to modify a read-only
variable.

Reported by:	bapt
2015-12-23 18:24:40 +00:00
ngie
f5aa9d7c17 MFC r276669,r276723:
r276669:

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

Sponsored by: EMC / Isilon Storage Division

r276723:

Install d_align.{in,out} for the :align test

Pointyhat to: me
2015-12-15 18:09:03 +00:00
bdrewery
a92d8ba124 MFC r291942:
Add missing CLEANFILES.
2015-12-14 20:29:31 +00:00
ngie
3bc7f4d78d MFC r291919:
Enable bin/ls testcases disabled previously because of issues with how
kyua 0.11's version of report-junit was rendering non-printable characters

Upgrade to kyua 0.12 to obtain a fixed version of the command

Output verified with python 2.7.10's xml.dom.minidom module

Sponsored by: EMC / Isilon Storage Division
2015-12-10 07:11:46 +00:00
bdrewery
2dfe4da949 MFC r289393:
Add more SUBDIR_PARALLEL.
2015-12-04 18:14:31 +00:00
bdrewery
1c5b4d7b40 MFC r284105,r284106,r284163:
r284105:
    Cleanup some indentation issues.
  r284106:
    Implement '-s' to copy as symlink, similar to the current -l link(2)
    handling.
  r284163:
    Cleanup some style(9) issues.

Relnotes:	yes
2015-12-04 17:36:35 +00:00
ngie
90fda359a4 MFC r269902,r270101:
r269902:

Convert bin/sh/tests to ATF

The new code uses a "test discovery mechanism" to determine
what tests are available for execution

The test shell can be specified via:

  kyua test -v test_suites.FreeBSD.bin.sh.test_shell=/path/to/test/sh

Sponsored by: EMC / Isilon Storage Division
Approved by: jmmv (mentor)
Reviewed by: jilles (maintainer)

r270101 (by jilles):

sh: Don't hardcode relative paths in the tests stderr files.

These paths have had to be adjusted to changes in the testsuite runner
several times, so modify the tests to remove the need for such adjustment.

A cp in functional_test.sh is now unneeded, but this matters little in
performance.
2015-12-01 18:27:38 +00:00
ngie
252de13015 MFC r289195:
Integrate the tests from lib/libarchive, usr.bin/cpio, and usr.bin/tar in to
the FreeBSD test suite

functional_test.sh was ported from bin/sh/tests/functional_test.sh, as a
small wrapper around libarchive_test, bsdcpio_test, and bsdtar_test provided
by upstream.

A handful of testcases in lib/libarchive/tests have been disabled as they
were failing when run with kyua test (see BROKEN_TESTS in
lib/libarchive/tests/Makefile)

As a sidenote: this removes the check/test targets from the Makefiles as they
don't match the pattern used in the rest of the FreeBSD test suite.

Sponsored by: EMC / Isilon Storage Division

Conflicts:
	lib/libarchive/test
	usr.bin/cpio/test
2015-11-15 23:54:34 +00:00
bapt
7d9f736886 MFC r290480
Protecting against rm -rf / is now POSIXLY_CORRECT per posix 1003.1
edition 2013. No need anymore to disable the protection if one set
the POXILY_CORRECT environment variable.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D4092
2015-11-10 07:17:38 +00:00
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