Commit Graph

3356 Commits

Author SHA1 Message Date
Jilles Tjoelker
439948cdf6 sh: Get rid of global variable argbackq. 2017-03-16 21:53:55 +00:00
Jilles Tjoelker
8999a290ab sh: Fix executing wrong command with ${unsetvar#$(cmdsubst)}$(cmdsubst).
The parsed internal representation of words consists of a byte string with a
list of nodes (commands in command substitution). Each unescaped CTLBACKQ or
CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list.

If param in ${param#%##%%word} is not set, the word is not expanded (in a
deviation of POSIX shared with other ash variants and ksh93). Erroneously,
the pointer in the list of commands (argbackq) was not advanced. This caused
the wrong command to be executed later if the outer word contained another
command substitution.

Example:
  echo "${unsetvar#$(echo a)}$(echo b)"
wrote "a" but should write "b".

MFC after:	1 week
2017-03-10 16:04:00 +00:00
Bryan Drewery
d11bfd6fb8 Rename some tests to end in _test.
Requested by:	ngie
MFC after:	2 weeks
X-MFC-With:	r314886
2017-03-09 04:20:00 +00:00
Bryan Drewery
0be7e2c09c Remove unneeded -x from tests.
Reported by:	ngie
MFC after:	2 weeks
X-MFC-With:	r314886
2017-03-09 04:19:52 +00:00
Bryan Drewery
b06b52baac pwait: Add a -t flag to specify a timeout before exiting, and tests.
The exit status will be 124, as the timeout(1) utility uses.

Reviewed by:	jilles
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D9697
2017-03-07 22:16:55 +00:00
Rodney W. Grimes
ce9f2d31b3 Convert absolute links to relative links.
Style.Makefile(9) has been ignored to produce minimal diffs.

Approved by:	grehan (mentor)
MFC after:	1 week
2017-03-07 05:10:38 +00:00
Conrad Meyer
ef1d40da16 ps(1): Fix -w + UNLIMITED handling
A follow-up fix for r314685.

Because the -w flag is parsed after ps(1) infers termwidth from COLUMNS and
stdout, and UNLIMITED happens to be the zero value, the single -w flag in
combination with a non-terminal stdout or COLUMNS=0 could result in output
truncated at 131 characters.  (Despite the output being unlimited without
-w.)

Obviously, adding more -w shouldn't truncate output lines.

The committed patch is from bdrewery@, and I've reviewed and tested it.

Submitted by:	bdrewery@
Reported by:	bdrewery@
Sponsored by:	Dell EMC Isilon
2017-03-07 04:51:35 +00:00
Bryan Drewery
27ca6260e0 Don't kill pid -1 on overflow from strtol(3).
Store the result in a proper long and then compare to the proper pid_t
for overflow, so that no MD assumptions are made.

Reviewed by:	jilles
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D9887
2017-03-05 21:56:04 +00:00
Jilles Tjoelker
586fd24857 sh: Fix crash if a -T trap is taken during command substitution.
Code like  t=$(stat -f %m "$file")  segfaulted if -T was active and a trap
was taken while the shell was waiting for the child process to finish.

What happened was that the dotrap() call in waitforjob() was hit. This
re-entered command execution (including expand.c) at a point not expected by
expbackq(), and global state (unallocated stack string and argbackq) was
corrupted.

To fix this, change expbackq() to prepare for command execution to be
re-entered.

Reported by:	bdrewery
MFC after:	1 week
2017-03-04 22:58:34 +00:00
Conrad Meyer
9c4241c3d7 ps(1): Only detect terminal width if stdout is a tty
If stdout isn't a tty, use unlimited width output rather than truncating to
79 characters.  This is helpful for shell scripts or e.g., 'ps | grep foo'.

This hardcoded width has some history: In The Beginning of History[0], the
width of ps was hardcoded as 80 bytes.  In 1985, Bloom@ added detection
using TIOCGWINSZ on stdin.[1]  In 1986, Kirk merged a change to check
stdout's window size instead.  In 1990, the fallback checks to stderr and
stdin's TIOCGWINSZ were added by Marc@, with the commit message "new
version."[2]

OS X Darwin has a very similar modification to ps(1), which simply sets
UNLIMITED for all non-tty outputs.[3]  I've chosen to respect COLUMNS
instead of behaving identically to Darwin here, but I don't feel strongly
about that.  We could match OS X for parity if that is desired.

[0]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?annotate=1065
[1]: https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=18105&r2=18106
[2]:
https://svnweb.freebsd.org/csrg/bin/ps/ps.c?r1=40675&r2=40674&pathrev=40675
[3]:
https://opensource.apple.com/source/adv_cmds/adv_cmds-168/ps/ps.c.auto.html

PR:		217159
Reported by:	Deepak Nagaraj <n.deepak at gmail.com>
2017-03-04 22:38:10 +00:00
Enji Cooper
caf42d8126 bin: normalize paths using SRCTOP-relative paths or :H when possible
This simplifies make logic/output

MFC after:	1 month
Sponsored by:	Dell EMC Isilon
2017-03-04 11:31:08 +00:00
Jilles Tjoelker
549bbb4fa1 sh: Add some already working tests that exercise new code paths. 2017-03-03 22:46:20 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Konstantin Belousov
cdf44896bb Use uintmax_t to print st_nlink.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2017-02-16 06:32:39 +00:00
Baptiste Daroussin
33bf6c45fb Remove empty Li
Reported by:	make manlint
MFC after:	2 days
2017-02-11 23:09:50 +00:00
Baptiste Daroussin
ce08d4900c Remove space at and of line
Reported by:	make manlint
MFC after:	2 days
2017-02-11 23:06:53 +00:00
Allan Jude
39f8282b48 Remove bdes(1)
The use of DES for anything is discouraged, especially with a static IV of 0

If you still need bdes(1) to decrypt Kirk's video lectures, see
security/bdes in ports.

This commit brought to you by the FOSDEM DevSummit and the
"remove unneeded dependancies on openssl in base" working group

Reviewed by:	bapt, brnrd
Relnotes:	yes
Sponsored by:	FOSDEM DevSummit
Differential Revision:	https://reviews.freebsd.org/D9424
2017-02-06 08:27:19 +00:00
Baptiste Daroussin
b4b4b5304b Revert crap accidentally committed 2017-01-28 16:31:23 +00:00
Baptiste Daroussin
814aaaa7da Revert r312923 a better approach will be taken later 2017-01-28 16:30:14 +00:00
Conrad Meyer
a758566cb8 chmod: Add SIGINFO handler
PR:		191884
Submitted by:	Dan McGregor <dan.mcgregor at usask.ca>
Reviewed by:	mjg@ (earlier version)
2017-01-08 06:50:53 +00:00
Konstantin Belousov
1c32456953 Use type-independent formats for printing nlink_t and ino_t.
Extracted from:	ino64 work by gleb, mckusick
Discussed with:	mckusick
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2017-01-06 16:59:33 +00:00
Pedro F. Giffuni
8ad81aaea6 pax(1): Fix a bug with archives smaller than 512 bytes.
The problem here is that the archive is too short (< 512 bytes). The
buffer routines, try to read at least 512 bytes, even when we try to
determine what format file we have, which is wrong.

Obtained from:	NetBSD (CVS rev 1.26)
MFC after:	5 days
2016-12-21 15:26:59 +00:00
Alan Somers
f698b621da Fix ls_tests:o_flag with ZFS TMPDIR
Unlike UFS or TMPFS, ZFS sets uarch automatically whenever a file is
updated. The test must explicitly clear uarch to be portable across
filesystems. Also, it doesn't need to run as root.

PR:		215179
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D8741
2016-12-15 16:13:52 +00:00
Brooks Davis
facc3cb0ff Use nmount(2) rather than the obsolete mount(2).
Reviewed by:	cem
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8513
2016-12-14 21:30:44 +00:00
Pedro F. Giffuni
f50fae318d ed(1): drop redundant parenthesis.
These were Left-over from the cleanup in r309936.
2016-12-14 21:14:43 +00:00
Brooks Davis
9dad1250d7 Mount filesystems without executable permissions since they should never
be used.

Reviewed by:	cem
MFC after:	1 week
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D8513
2016-12-14 21:13:10 +00:00
Brooks Davis
176d3efd2b Put the undocumented df feature of mounting filesystems from device nodes
under an ifdef.  Leave enabled.

Reviewed by:	cem
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D8513
2016-12-14 21:11:42 +00:00
Pedro F. Giffuni
8bd856de21 ed(1): Simplify some checks.
The return type for both fread(3) and fwrite(3) cannot be negative, this
renders some checks invalid and variable 'ct' unnecessary.
Also bump 'len' to size_t to avoid signed/unsigned comparison warnings.
2016-12-12 20:25:59 +00:00
Bartek Rutkowski
94161f30b7 Fix regression when stdin/out/err fds are are overridden by shell.
Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reported by:	ngie
Approved by:	ngie
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	https://reviews.freebsd.org/D8543
2016-12-12 18:56:40 +00:00
Pedro F. Giffuni
27150ef8bc ed(1): Prevent possible overflows during allocation.
Make sure the parameters used for malloc(3) can hold size_t sizes.
This should help ed(1) handle bigger data in the future.

MFC after:	2 weeks
2016-12-12 03:46:40 +00:00
Bartek Rutkowski
2a65657fc8 Capsicum support for dd(1)
Adds Capsicum sandboxing to dd utility.

Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reviewed by:	allanjude, emaste, oshogbo
Approved by:	oshogbo
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	https://reviews.freebsd.org/D8543
2016-12-09 14:51:05 +00:00
Eric van Gyzen
3d32d4a7c9 Export the whole thread name in kinfo_proc
kinfo_proc::ki_tdname is three characters shorter than
thread::td_name.  Add a ki_moretdname field for these three
extra characters.  Add the new field to kinfo_proc32, as well.
Update all in-tree consumers to read the new field and assemble
the full name, except for lldb's HostThreadFreeBSD.cpp, which
I will handle separately.  Bump __FreeBSD_version.

Reviewed by:	kib
MFC after:	1 week
Relnotes:	yes
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D8722
2016-12-07 15:04:22 +00:00
Xin LI
4dceaf94fa style(9).
MFC after:	2 weeks
2016-11-28 07:21:09 +00:00
Xin LI
305de00ec4 Plug a potential memory leak.
MFC after:	2 weeks
2016-11-28 07:19:45 +00:00
Adrian Chadd
29aee14890 [dd] Revert the capsicum bits for now until it gets fixed.
dd is a bootstrap tool and that header isn't installed as part of the
bootstrap environment for previous releases (eg freebsd-10.)

We'll figure it out in post and then re-commit it.
2016-11-19 18:19:21 +00:00
Ruslan Bukin
6193edf4c5 Restore dd changes included accidentally in r308857. 2016-11-19 17:51:02 +00:00
Ruslan Bukin
9a8f61fb5b Bring in support for Ingenic XBurst JZ4780 and
X1000 systems on chips.

Imgtec CI20 and Ingenic CANNA boards supported.

Submitted by:	Alexander Kabaev <kan@FreeBSD.org>
Reviewed by:	Ruslan Bukin <br@FreeBSD.org>
Sponsored by:	DARPA, AFRL
2016-11-19 17:46:18 +00:00
Bartek Rutkowski
947b83c090 Capsicum support for dd(1)
Adds Capsicum sandboxing to dd utility.

Submitted by:	Pawel Biernacki <pawel.biernacki@gmail.com>
Reviewed by:	allanjude, emaste, oshogbo
Approved by:	oshogbo
Sponsored by:	Mysterious Code Ltd.
Differential Revision:	https://reviews.freebsd.org/D8543
2016-11-18 21:09:57 +00:00
Bryan Drewery
490a8aa9a1 DIRDEPS_BUILD: Update dependencies.
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
2016-11-13 00:11:30 +00:00
Marcelo Araujo
e7d88f5e13 Fix missing '-' for the flags -s and -d on both manpage and usage.
Reported by:	garga, bde
2016-11-09 04:42:09 +00:00
Marcelo Araujo
31500ce90d Add -d flag that prints domain only.
PR:		212875
Submitted by:	Ben RUBSON <ben.rubson@gmail.com>
Reviewed by:	pi
2016-11-08 11:36:33 +00:00
Conrad Meyer
cd1693d3f9 Capsicumize some trivial stdio programs
Trivially capsicumize some simple programs that just interact with
stdio.  This list of programs uses 'pledge("stdio")' in OpenBSD.

No objection from:	allanjude, emaste, oshogbo
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D8307
2016-11-08 05:31:01 +00:00
Dag-Erling Smørgrav
e98bb55f0b Use what(1) instead of strings(1). It's simpler and always available.
PR:		213665
Submitted by:	Pawel Worach <pawel.worach@gmail.com>
MFC after:	1 week
2016-11-04 17:02:42 +00:00
Jilles Tjoelker
3c47cee5c8 sh: Add simple test for 'set -C' (noclobber).
To ensure fast test runs, race conditions are not tested.
2016-11-02 22:33:37 +00:00
Ruslan Bukin
51acc171d1 Increase timeouts so tests have more chances to succeed
on MIPS64EB in QEMU.

Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
2016-10-19 12:23:02 +00:00
Ruslan Bukin
6bfde4a6fb Increase timeout so low-end platforms have a chance to complete test
procedures.

This fixes operation in QEMU/MIPS64.

Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
2016-10-17 10:21:53 +00:00
Jilles Tjoelker
7cca93e61a sh: Do not import IFS's value from the environment.
Per Austin group issue #884, always set IFS to $' \t\n'. As before, IFS will
be exported iff it was in the environment.

Most shells (e.g. bash, ksh93 and mksh) already did this. This change
improves predictability, in that scripts can simply rely on the default
value.

However, the effect on security is little, since applications should not be
calling the shell with attacker-controlled environment variable names in the
first place and other security-sensitive variables such as PATH should be
and are imported by the shell.

When using a new sh with an old (before 10.2) libc wordexp(), IFS is no
longer passed on. Otherwise, wordexp() continues to pass along IFS from the
environment per its documentation.

Discussed with:	pfg
Relnotes:	yes
2016-10-08 13:40:12 +00:00
Sevan Janiyan
2bb154d973 Add history section for test(1)
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/test.c

PR:		211789
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:47:02 +00:00
Sevan Janiyan
3578fc3e0c Add history section for stty(1)
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V3/man/man1/stty.1

PR:		211788
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:37:46 +00:00
Sevan Janiyan
25907b311b Add history section of pwd(1)
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V5/usr/source/s2/pwd.c

PR:		211787
Approved by:	bcr (mentor)
MFC after:	5 days
Differential Revision:	https://reviews.freebsd.org/D8104
2016-10-05 19:31:29 +00:00