Commit Graph

3120 Commits

Author SHA1 Message Date
Jilles Tjoelker
92fe71faae sh: Allow empty << EOF markers. 2015-09-02 19:49:55 +00:00
Jilles Tjoelker
f0688a48d2 sh: Fix read with escaped IFS characters at the end.
Characters escaped with a backslash must be treated as if they were not in
IFS. This includes stripping trailing IFS characters.
2015-08-30 17:24:22 +00:00
Jilles Tjoelker
62c3711632 sh: Add set -o nolog.
POSIX requires this to prevent entering function definitions in history but
this implementation does nothing except retain the option's value. In ksh88,
function definitions were usually entered in the history file, even when
they came from ~/.profile and the $ENV file, to allow displaying their
definitions.

This is also the first option that does not have a letter.
2015-08-29 19:41:47 +00:00
Xin LI
b81cd10773 Respect locale settings.
MFC after:	2 weeks
2015-08-28 00:49:30 +00:00
Xin LI
d518359452 Use exit() instead of return in main().
MFC after:	2 weeks
2015-08-28 00:44:58 +00:00
Jilles Tjoelker
4a4867d667 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.

MFC after:	1 week
2015-08-25 21:55:15 +00:00
Marcel Moolenaar
d1a0d267b7 Upgrade libxo to 0.4.5.
Local changes incorporated by 0.4.5: r284340
Local changes retained: r276260, r282117

Obtained from:	https://github.com/Juniper/libxo
2015-08-24 16:26:20 +00:00
Jilles Tjoelker
d0b0ac182d 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.

MFC after:	1 week
2015-08-23 20:44:53 +00:00
Jamie Gritton
c4f0631f19 Make pkill/pgrep -j ARG take jname, not just jid.
PR:		201588
Submitted by:	Daniel Shahaf <danielsh at apache.org>
MFC after:	3 days
2015-08-22 05:04:36 +00:00
Jilles Tjoelker
5e03b81fd4 sh: Avoid negative character values from $'\Uffffffff' etc.
The negative value was not expected and generated the low 8 bits as a byte,
which may be an invalid character encoding.

The final shift in creating the negative value was undefined as well.

Make the temporary variable unsigned to fix this.
2015-08-20 22:05:55 +00:00
Jilles Tjoelker
f84460dded sh: Add test for $'\u' without any digits.
It is likely that $'\uXXXX' and $'\UXXXXXXXX' will allow fewer digits in
future. However, no digits at all should still be disallowed.
2015-08-20 21:31:36 +00:00
Jilles Tjoelker
4b6578dc8c sh: Backslash-newline should not affect field splitting in read builtin.
This was originally broken in r212339 in 2010.
2015-08-16 12:57:17 +00:00
Jilles Tjoelker
58bbcdb183 sh: When setting option via long name, don't go via letter.
Looking up the letter makes no sense and prevents adding options that only
have a long name, no letter.
2015-08-14 21:44:15 +00:00
Allan Jude
e9eed90c39 Cast uid and gid to the correct type for display to solve segfault in ls(1) on 32bit arches
Correctly escape literal % for display

This fixes segfaults in 32bit arches caused by r285734

Reviewed by:	ngie
Approved by:	dim
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D3191
2015-07-24 20:20:59 +00:00
Allan Jude
ddaf675fc8 Remove an excess space accidently introduced in the output in ls(1) by r285734
Spotted by:	dim
Approved by:	eadler (mentor)
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D3152
2015-07-22 19:58:21 +00:00
Allan Jude
e5542be424 Fix some issues with the application of libxo to ls(1)
* Add whitespace trimming to some fields (username, group, size, inode, blocks) to avoid whitespace in JSON strings
* fix -m mode, was invalid JSON (repeated keys), and was missing outer array container
* in -n mode, numeric uids and gids were returned as strings

Approved by:	eadler (mentor)
Sponsored by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D2854
2015-07-21 05:03:59 +00:00
David E. O'Brien
e6588b178c Mention the dd-like recoverdisk(1) to help folks find this great BSD command. 2015-07-16 23:38:12 +00:00
Joel Dahl
169a18552e mdoc: minor Xr fixes 2015-07-14 19:45:35 +00:00
Baptiste Daroussin
6f7c45c9d5 Prevent potential integer overflow
PR:		192971
Submitted by:	David Carlier <david.carlier@hardenedbsd.org>
2015-07-13 05:59:41 +00:00
Baptiste Daroussin
d4bf4151a5 Prevent potential integer overflow
PR:		192971
Submitted by:	David Carlier <david.carlier@hardenedbsd.org>
2015-07-13 05:56:27 +00:00
Marius Strobl
6bee009f79 Since r284198, ls(1) just always depends libxo(3), not only in case of
MK_LS_COLORS or !RELEASE_CRUNCH.
2015-07-12 18:40:31 +00:00
Jilles Tjoelker
8956c4ec63 sh(1): libedit has supported multibyte encodings for a while. 2015-07-11 13:07:26 +00:00
Jilles Tjoelker
7bb3697b4e 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
MFC after:	1 week
2015-06-28 21:36:00 +00:00
Jilles Tjoelker
c3c85727d0 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.

MFC after:	1 week
2015-06-24 20:51:48 +00:00
Alexander Kabaev
0d5beab5be Continue ubreaking ``env LANG=ru_RU.KOI8-R ls -l''.
File names are in current locale as well.
2015-06-17 04:26:48 +00:00
Marcel Moolenaar
284e2b82b2 Unbreak ``env LANG=ru_RU.KOI8-R ls -l''.
Time strings are in the current locale.
2015-06-17 03:12:08 +00:00
Simon J. Gerraty
2ef6d5a7b9 new depends 2015-06-16 23:37:19 +00:00
Simon J. Gerraty
4c46adf174 removed extra keyword 2015-06-13 19:53:24 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Sean Bruno
a0be738b20 r284198 seems to have left a null format string printf that gcc does *not*
like breaking mips builds.

Submitted by:	Shawn Webb <shawn.webb@hardenedbsd.org>
Obtained from:	HardenedBSD
2015-06-11 02:29:39 +00:00
Marcel Moolenaar
52e4a08c45 Convert ls(1) to use libxo(3).
Obtained from:	Phil Shafer <phil@juniper.net>
Sponsored by:	Juniper Networks, Inc.
2015-06-10 01:27:38 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Bryan Drewery
724fd44827 Cleanup some style(9) issues.
- Whitespace.
- Comments.
- Wrap long lines.

MFC after:	2 weeks
X-MFC-with:	r284105,r284106
Sponsored by:	EMC / Isilon Storage Division
2015-06-08 19:24:18 +00:00
Xin LI
183714f3f7 It has been long time that when doing 'ls -G /path/to/a/symlink', instead of
using the color of symbolic link, the color is determined by the link target.
This behavior was quite confusing.

Looking at the file history, it looks like that r203665 intends to fix this
but the issue was never actually fixed.

Fix this by not setting FTS_COMFOLLOW when color is requested like what was
done in r203665.

MFC after:	2 weeks
2015-06-08 19:13:04 +00:00
Bryan Drewery
7ea2450f42 Implement '-s' to copy as symlink, similar to the current -l link(2) handling.
This is also implemented in at least GNU coreutils cp.

While here also improve the '-l' handling to not open(2) the source file as
it does not actually need the descriptor.

Sponsored by:	EMC / Isilon Storage Division
2015-06-07 06:30:25 +00:00
Bryan Drewery
14376e1f21 Cleanup some indentation issues. 2015-06-07 03:49:41 +00:00
Sergey Kandaurov
db1a93d4fe Change directory permissions in pre-order.
In this order, it won't try to recurse into a directory for which
it doesn't have permission, before changing that permission.
This follows an existing behavior in other BSDs, linux, OS X.

Obtained from:	NetBSD
2015-06-04 19:18:58 +00:00
Marcelo Araujo
16eb357647 Remove unused variable, this variable fmtstr was introduced at revision r225868
and it is not used anymore after the convertion to use libxo at revision r283304.

Differential Revision:	D2678
Reviewed by:		marcel
2015-06-01 06:00:04 +00:00
Sergey Kandaurov
e8d89b8442 Document recent p_flag2 additions. 2015-05-27 10:08:31 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Marcel Moolenaar
8beb1a2fdc Convert to use libxo. Document use of libxo as well.
Obtained from:  Phil Shafer <phil@juniper.net>
Sponsored by:   Juniper Networks, Inc.
2015-05-22 23:07:55 +00:00
Xin LI
94bdf5cfcc Eliminate unneeded includes.
MFC after:	2 weeks
2015-05-21 18:29:36 +00:00
Xin LI
8b45db8ee2 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 time(1).

MFC after:	2 weeks
2015-05-07 20:54:38 +00:00
Jilles Tjoelker
c633f8dc04 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)
MFC after:	1 week
2015-05-05 13:23:03 +00:00
Steven Hartland
ad34cace15 Standardise chmod, chflags, chown and chgrp recursive symlink processing
chmod, chflags, chgrp, chmod and chown now affect symlinks in -R mode as
defined in symlink(7); previously symlinks were silently ignored.

Differential Revision:	https://reviews.freebsd.org/D2316
Reviewed by:	jilles
MFC after:	1 month
Relnotes:	yes
Sponsored by:	Multiplay
2015-04-29 00:49:00 +00:00
Baptiste Daroussin
dc814fa48b Pet manlint 2015-04-26 10:38:26 +00:00
Baptiste Daroussin
ef2a65a8bd Use mdoc(7) macros for curly braces 2015-04-26 10:09:26 +00:00
Baptiste Daroussin
1517e5649b mdoc: escape Re 2015-04-26 10:03:05 +00:00
Jilles Tjoelker
cad3cc1310 sh: Pass along SIGINT from a child if job control is enabled, even when not
interactive.

I added the interactive check in r208881 to be safe, but in actual use
(scripts in set -m mode) passing along SIGINT seems best.

Discussed with:	bdrewery
2015-04-25 13:34:25 +00:00
Eitan Adler
7d00295b1b ed(1): Fix [-Werror=logical-not-parentheses]
/usr/src/bin/ed/glbl.c:64:36: error: logical not is only applied to
	theleft hand side of comparison [-Werror=logical-not-parentheses]

Obtained from:	Dragonfly (1fff89cbaeaa43af720a1f23d9c466b756dd8a58)
MFC After:	1 month
2015-04-20 02:07:57 +00:00