Commit graph

15096 commits

Author SHA1 Message Date
John Baldwin
593cb2e370 rs: Fix some pointer arith UB.
If the next column was blank, then the length of the following entry
was computed as the end of the following entry minus a global variable
"blank" which is not in the same string or allocation.  Instead, save
the start value of 'p' explicitly instead of abusing '*ep'.  Possibly
we should just increment p before saving it in sp in the 'blank' case,
but at worst that would just mean maxlen might be one char too large
which should be harmless.

Reviewed by:	brooks
Differential Revision:	https://reviews.freebsd.org/D36832

(cherry picked from commit ba86cffb28)
2022-11-11 10:18:54 -08:00
John Baldwin
59c1904fc2 rs: Fix a use after free.
Using a pointer passed to realloc() after realloc() even for pointer
arithmetic is UB.  It also breaks in practice on CHERI systems as
the updated value of 'sp' in this case would have had the bounds from
the old allocation.

This would be much cleaner if elem were a std::vector<char *>.

Reviewed by:	brooks, emaste
Reported by:	GCC -Wuse-after-free
Differential Revision:	https://reviews.freebsd.org/D36831

(cherry picked from commit e5f2d5b35e)
2022-11-11 10:18:54 -08:00
John Baldwin
068c9d3de7 rs: Fix various harmless warnings.
- Add /* FALLTHROUGH */ comments for intentional fall throughs in
  getargs().

- Remove id strings to quiet -Wunused-const-variable warnings from
  GCC.

- While here, remove __FBSDID.

Reviewed by:	brooks
Differential Revision:	https://reviews.freebsd.org/D36830

(cherry picked from commit bb31e1bbf2)
2022-11-11 10:18:54 -08:00
John Baldwin
1f9f319919 diff: Fix a use after free as well as a memory leak in change().
When -B or -I are used, change() evaluates the lines in a hunk to
determine if it is a hunk that should be ignored.  It does this by
reading each candidate line into a mallocated buffer via preadline()
and then calling ignoreline().  Previously the buffer was freed as a
side effect of ignoreline_pattern() called from ignoreline().
However, if only -B was specified, then ignoreline_pattern() was not
called and the lines were leaked.  If both options were specified,
then ignoreline_pattern() was called before checking for a blank line
so that the second check was a use after free.

To fix, pull the free() out of ignoreline_pattern() and instead do it
up in change() so that is paired with preadline().

While here, simplify ignoreline() by checking for the -B and -I cases
individually without a separate clause for when both are set.  Also,
do the cheaper check (-B) first, and remove a false comment (this
function is only called if at least one of -I or -B are specified).

Reviewed by:	emaste
Reported by:	GCC 12 -Wuse-after-free
Differential Revision:	https://reviews.freebsd.org/D36822

(cherry picked from commit 3736b2dd32)
2022-11-11 10:18:53 -08:00
John Baldwin
78a211c5eb fortune: Unindent a debug printf in get_fort().
The debug printf is intended to execute after the loop has ended to
log the selected file.

Reviewed by:	imp, emaste
Reported by:	GCC
Differential Revision:	https://reviews.freebsd.org/D36815

(cherry picked from commit db695788fc)
2022-11-11 10:18:53 -08:00
John Baldwin
cf668c1697 tail: Fix misleading indentation in ARG() macro.
Reviewed by:	imp, emaste
Reported by:	GCC
Differential Revision:	https://reviews.freebsd.org/D36810

(cherry picked from commit c2e561a38f)
2022-11-11 10:18:53 -08:00
John Baldwin
efe264f2c2 newkey: Fix mismatch in array bounds in for adjust().
Reviewed by:	emaste
Reported by:	GCC -Warray-parameter
Differential Revision:	https://reviews.freebsd.org/D36762

(cherry picked from commit 536f7d84cd)
2022-11-11 10:18:53 -08:00
John Baldwin
c5f61889ea mail: Fix mismatch in array bounds for isign().
Reviewed by:	imp, emaste
Reported by:	GCC -Warray-parameter
Differential Revision:	https://reviews.freebsd.org/D36761

(cherry picked from commit 157436dcbf)
2022-11-11 10:18:53 -08:00
Math Ieu
1a7136cf29 split: reset errno prior to getline()
Something else may have set errno, breaking the post-getline() logic
that tries to detect the getline() error.  This was initially noted in
a jail on a system that has HPET, in a jail that does not expose
/dev/hpet0 -- we see an earlier error in libc's vdso bits.

Fixes:	5c053aa3c5 ("split: switch to getline() [...]")
(cherry picked from commit 172be8642d)
2022-11-11 12:08:57 -06:00
Kyle Evans
6b628a694d split: add word order fix
This was meant to note that both pattern and line matching were
previously restricted, but words are difficult.  +line and rearrange.

Sponsored by:	Klara, Inc.

(cherry picked from commit 7aaa50c6b5)
2022-11-11 12:08:54 -06:00
Kyle Evans
50b1ea7ea0 split: add some tests
This should cover all of the basic functionality, as well as the recent
enhancement to use a dynamic buffer size rather than limiting patterns
and lines to MAXBSIZE.

Reviewed by:	bapt
Sponsored by:	Klara, Inc.

(cherry picked from commit 75c3ca1ebf)
2022-11-11 12:08:51 -06:00
Kyle Evans
f6a842313c split: switch to getline() for line/pattern matching
Get rid of split's home-grown logic for growing the buffer; arbitrarily
breaking at LONG_MAX bytes instead of 65536 bytes gives us much more
wiggle room.  Additionally, we'll actually fail out entirely if we can't
fit a line, which makes noticing this class of problem much easier.

Reviewed by:	bapt, emaste, pauamma
Sponsored by:	Klara, Inc.

(cherry picked from commit 5c053aa3c5)
2022-11-11 12:08:46 -06:00
liu-du
6c49b65d6d xargs: fix exit code when using -P
currently when xargs runs in parallel mode (e.g. -P2), it somtimes
incorrectly returns zero exit code.  this commit fix it and also adds
tests.

Reviewed by:	mjg
PR:	267110

(cherry picked from commit 0ca740d9a6)
2022-11-10 22:43:58 +00:00
Elvin Aslanov
fc929a14cc grep: correct argument name in man page
MFC after:	1 week
Fixes:		4dc88ebedf ("Add BSD grep to the base system...")
Pull Request:	https://github.com/freebsd/freebsd-src/pull/622

(cherry picked from commit 085a42d0cf)
2022-11-08 15:47:49 -05:00
Gordon Bergling
9a4c4a9654 tee.1: Add a HISTORY section
The most accurate information I have found is that
tee(1) first appeared in Version 7 AT&T UNIX.

Reviewed by:	pauamma
Differential Revision:	https://reviews.freebsd.org/D37206

(cherry picked from commit 514df63539)
2022-11-06 08:55:41 +01:00
Dag-Erling Smørgrav
7a254e64bf script: Correct -F in man page and usage string.
Sponsored by:	Klara, Inc.
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D37138

(cherry picked from commit 8e096e24d4)

script: Add usage string for playback mode.

Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37138

(cherry picked from commit e7c13cf438)

script: Use size_t / ssize_t where needed.

Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37177

(cherry picked from commit 3276866f40)

script: Further usage string nits.

Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37177

(cherry picked from commit 6ac087cf8f)

script: Handle a missing 's' stamp gracefully.

Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37182

(cherry picked from commit 473e9fcab4)
2022-11-02 10:44:48 +01:00
Simon J. Gerraty
9ba17e2d1c script add -T fmt to print time-stamps
script -r is useful for recording time-stamps of when output
happened.  With -T, rather than playback the script in real-time
we simply print the time-stamps to show when the output happened.

This is very useful for example, for analyzing boot time activity.

If the fmt provided contains no % characters the default
%n@ %s [%Y-%m-%d %T]
is used, which lends itself to analysis by tools as well as humans.

Sponsored by:	Juniper Networks, Inc.

Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D34511

(cherry picked from commit 6c4afed566)

script -T skip timstamps for same second

The result is much more readable if we only output the time-stamp
when it is at least 1s since last one.

(cherry picked from commit 7b45ad3f89)

script: use %n at the end of default tstamp_fmt

Since we are only outputting time-stamps when they differ
ending it with a newline, interferes with the output less.

(cherry picked from commit 31fde97357)
2022-11-02 10:44:46 +01:00
Dag-Erling Smørgrav
7302f86971 w: cosmetic fixes.
Sponsored by:	Klara, Inc.

(cherry picked from commit 04f6b9cb18)

w: Fix premature rounding.

If the system has been up more longer than a minute, we add 30 seconds to
the uptime so that subsequent calculations will round to the nearest minute
rather than truncate.  However, since the introduction of libxo, we output
the raw value after performing the adjustment.  Rewrite so that we output
the raw value first, then perform the adjustment and recalculate before
outputting the humanized value.

While there, reduce stack usage and avoid needless allocations.

Sponsored by:	Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37128

(cherry picked from commit deb2f1b616)
2022-11-02 10:41:07 +01:00
Dag-Erling Smørgrav
1b9c55cf9a apply: clean up error handling.
Sponsored by:	Klara, Inc.

(cherry picked from commit 441202c00b)
2022-11-02 10:37:24 +01:00
Dag-Erling Smørgrav
938ff8990d renice: support -- as per POSIX.
Sponsored by:	Klara, Inc.
MFC after:	1 week

(cherry picked from commit e24c5c60d7)

renice: fix argument order.

The target modifiers (-g, -p, -u) may occur in any position except
between -n and its argument; furthermore, we support both the old
absolute form (without -n) and the modern relative form (with -n).

Sponsored by: Klara, Inc.

(cherry picked from commit 65ee0a8495)

renice: add unit tests.

Sponsored by:	Klara, Inc.

(cherry picked from commit 7ccdad905f)
2022-11-02 10:37:00 +01:00
Dag-Erling Smørgrav
0ed86bcc0b xinstall: fix dounpriv logic, add tests
Sponsored by:	Klara, Inc.
MFC after:	1 week

(cherry picked from commit 36d67475f5)

xinstall: make md5 and ripemd160 conditional

Sponsored by:	Klara, Inc.

(cherry picked from commit c7a8e8d372)

xinstall: use dynamic bufsize as in cat(1) / cp(1).

Sponsored by:	Klara, Inc.

(cherry picked from commit 54d8d0fe12)

xinstall: alphabetize: upper case precedes lower.

Sponsored by:	Klara, Inc.

(cherry picked from commit f44e257712)
2022-11-02 10:36:19 +01:00
Baptiste Daroussin
b4572fe565 sort: deindent file_reader_free and cleanup its usage
(cherry picked from commit 226e41467e)
2022-10-19 09:59:31 +02:00
Baptiste Daroussin
1cdb98e725 sort: simplify file_reader_clean
Deindent the function, remove useless tests:
 - free already test if argument is NULL
 - closefile already test if the input is stdin or null

(cherry picked from commit ffd41d39c6)
2022-10-19 09:59:31 +02:00
Baptiste Daroussin
0821423134 sort: deindent closefile
(cherry picked from commit f9d9a7cc4f)
2022-10-19 09:59:30 +02:00
Baptiste Daroussin
67ca992f5c sort: use asprintf(3) instead of malloc + snprintf(3)
(cherry picked from commit 48a53cc484)
2022-10-19 09:59:30 +02:00
Baptiste Daroussin
e3231f459f sort: deindent openfile
(cherry picked from commit 958b0d4642)
2022-10-19 09:59:30 +02:00
Baptiste Daroussin
e891183e60 sort: use memset to initialize structure when possible
(cherry picked from commit f02c783757)
2022-10-19 09:59:29 +02:00
Baptiste Daroussin
2afc73005c sort: unify the code to read from FILE *
Previously the code to read from a local file or stdin was sperarated
After the change to remove the home made line reader used for stdin
(replaced by getdelim) it apprears that the rest of the code which is
used to read from any FILE * but stdin can benefit from the exact same
change.

(cherry picked from commit 8b9071360a)
2022-10-19 09:59:29 +02:00
Baptiste Daroussin
d068b2c1ea sort: remove unused function
(cherry picked from commit e8815fb30b)
2022-10-19 09:59:29 +02:00
Baptiste Daroussin
cacedfd1df sort: simplify the code to handle -z flag
(cherry picked from commit f079ef8aa4)
2022-10-19 09:59:29 +02:00
Baptiste Daroussin
713ef741b7 sort: cleanup now unused structutre and prototypes
(cherry picked from commit 4d4fcf619e)
2022-10-19 09:59:28 +02:00
Baptiste Daroussin
1286974328 sort: use mkstemp(3) instead of reinventing it
MFC After:	1 week

(cherry picked from commit 3f9e5e59bd)
2022-10-19 09:59:28 +02:00
Baptiste Daroussin
489c9df198 sort: replace home made line reader by getdelim(3)
The previous code had bug when reading lines with an unexpected
encoding, returning without the full line being captured.
This result in sort complaining with "sort: Illegal byte sequence"

Using getdelim(3) instead of the home made code, fixes the situation.

PR:		241679
Reported by:	Ronald F. Guilmette <rfg-freebsd@tristatelogic.com>
MFC After:	1 week
Reviewed by:	markj, imp
Differential Revision:	https://reviews.freebsd.org/D36948

(cherry picked from commit b58094c0d9)
2022-10-19 09:59:28 +02:00
Baptiste Daroussin
accbb97f87 sort: add wrapper around calloc
(cherry picked from commit a312f3e742)
2022-10-19 09:56:51 +02:00
Baptiste Daroussin
47204fd342 sort: replace malloc+memset with calloc
(cherry picked from commit ecc3c29167)
2022-10-19 09:56:50 +02:00
Simon J. Gerraty
1682f901ec ldd: ignore unverified files
When mac_veriexec is enforcing, we won't run unverified binaries,
don't let ldd examine them either.

Reviewed by:	stevek emaste
MFC after:	1 week
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D36897

(cherry picked from commit f48114b653)
2022-10-15 09:08:44 -07:00
Konstantin Belousov
a763331899 ldd: use direct exec mode unconditionally
PR:	127276, 175339, 231926

(cherry picked from commit 9cabef3d14)
2022-10-13 07:46:01 +03:00
Baptiste Daroussin
08c16de8d4 locate: change from BSD-4-clause to BSD-3-clause
We have the authorization from the University of California to remove
the advertising clause for a while, wosch@ who also hold a copyright
on this code also approved the relicensing

Approved by:	wosch@
MFC after:	3 days

(cherry picked from commit 389844c058)
2022-10-12 11:20:09 +02:00
Baptiste Daroussin
06bcf00f87 mandoc: import version 1.14.6
MFC after: 3 weeks

(cherry picked from commit 6d38604fc5)
2022-10-12 11:04:46 +02:00
Baptiste Daroussin
08180c7043 ident: replace sbuf(9) with open_memstream(3)
This change makes ident only dependant on libc functions

This makes our ident(1) more portable, also the fact that we only
depend on libc which is maintained with excellent backward compatibility
means that if one day ident is removed from base, someone using FreeBSD
22 will be able to fetch ident from FreeBSD 14 to run ident against
FreeBSD 1.0 binary

MFC After:	1 week

(cherry picked from commit 1a4d5f13ba)
2022-10-12 10:41:07 +02:00
Elliott Mitchell
38fe63afdc vmstat: remove processor counting from getcpuinfo()
(cherry picked from commit 42dc8696df)
2022-10-07 05:00:23 +03:00
Ed Maste
8bbc22fac8 clang: remove as(1) cross-reference from man page
PR:		265232
Reviewed by:	dim
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differntial Revision:	https://reviews.freebsd.org/D36634

(cherry picked from commit 61957f3a6f)
2022-10-01 20:35:06 -04:00
Konstantin Belousov
49246fc249 procstat(1): print AT_USRSTACKBASE and AT_USRSTACKLIM
(cherry picked from commit 1d280f2142)
2022-09-30 03:29:09 +03:00
Kirk McKusick
3c67983bab Handle NULL return from localtime(3) in ls(1) and find(1)
(cherry picked from commit 927f8d8bbb)
2022-09-27 09:20:29 -07:00
Fernando Apesteguía
b7c55aaa6d Bump .Dd for recently modified manual pages
During the removal of named(8) references, some pages were modified but their
.Dd where not updated accordingly.

Reported by:	lwhsu@
Fixes:	942e234d86

(cherry picked from commit 4a3c598f35)
2022-09-24 10:25:07 +02:00
Fernando Apesteguía
36c7fd643b Remove references to named(8)
named(8) hasn't been in base for some time. Remove all references to it in
manual pages.

Approved by:	manpages (Pau Amma)
Differential Revision:	https://reviews.freebsd.org/D35586

(cherry picked from commit 942e234d86)
2022-09-24 10:09:35 +02:00
Gordon Bergling
e267c40181 uname.1: Clarify the -r option
It is some times hard to understand the difference between
kernel version and userland version. So clarify the -r option
of uname(1) in terms of a printed kernel version.

While here, add some cross references:

- cross reference freebsd-version(1) in uname(1)
- cross reference freebsd-version(1) and uname(1) in freebsd-update(8)

PR:		265594
Reported by:	rwatson
Reviewed by:	gbe, imp
Differential Revision:	https://reviews.freebsd.org/D36516

(cherry picked from commit 8f98a937ed)
2022-09-24 09:57:44 +02:00
Xin LI
f447ddc7b8 MFV: less v608
Relnotes:	yes
(cherry picked from commit 95270f73ba)
2022-09-19 18:51:53 -07:00
Kyle Evans
426e7ab3ca iconv: only conditionally use ICONV_SET_DISCARD_ILSEQ
If the -c flag is used, then we can set it with ICONV_SET_DISCARD_ILSEQ;
otherwise, leave it alone.  The user may have specified //IGNORE in the
'to' codeset specification, there's no reason we can't allow that but
we'll currently turn it off.

Reviewed by:	thj
Sponsored by: Klara, Inc.

(cherry picked from commit ea0f37dec6)
2022-09-18 01:26:39 -05:00
Kyle Evans
2f5dbe4772 zdiff: avoid non-conformant features
`setvar` is a non-conformant feature that looks slightly neater but is
not portable to other /bin/sh implementations.  Making the script
portable is straightforward, so let's do it.

Tests are added to make sure that I didn't break anything major in the
process.

Reviewed by:	bapt (previous version), jilles
Sponsored by:	Klara, Inc.

(cherry picked from commit 5b7adeb184)
2022-09-18 01:26:39 -05:00