Commit Graph

137 Commits

Author SHA1 Message Date
Ricardo Branco
e23954bd42 hexdump: Do not trust st_size if it equals zero.
Fix for hexdump -s not being able to skip files residing in
pseudo-filesystems that advertise a zero size value.

Historically, many pseudofs-based filesystems (e.g., procfs) report
a va_size of 0 for numerous files classified as regular files.
Typically, the contents of these files are generated on demand
from kernel data as sbuf(9) strings at the time they are read.
Accurately reporting the size of these files is challenging, as it
often involves generating their contents. These pseudofs implementations
frequently report the size as 0. This is a historical behavior and also
aligns with Linux behavior. To maintain compatibility, we have chosen
to preserve the existing behavior and address it in the userland
application, rather than modifying it in the kernel (by updating the
correct value for va_size).

PR:		bin/276106
MFC after:	1 week
2024-01-04 00:16:50 -08:00
Warner Losh
5e3934b15a usr.bin: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:01 -07:00
Warner Losh
0b8224d1cc Remove copyright strings ifdef'd out
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh
bdcbfde31e usr.bin: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
Warner Losh
b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Xin LI
d101656818 hexdump: Partial lines cannot be repetitions of earlier lines.
When checking for repetitions of earlier lines, we compare the
first nread bytes of the line against the saved line. However,
when we read a partial line, it should never be treated as a
repetition of an earlier line, even if the first bytes match.

This change fixes a bug where a partial line could be
incorrectly identified as a repetition of an earlier line.

Reported-by:	Mark Adler <madler@alumni.caltech.edu>
PR:		118723
Reviewed-by:	emaste
MFC-after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D40471
2023-06-08 18:39:05 -07:00
Xin LI
1232c7884d od(1): Fix skip value handling
POSIX defines -j as the number of bytes that od(1) should skip over the
concatenated input files. The existing code tries to implement this behavior
by checking if the current address was smaller than the skip value. However,
this is not correct, because we adjust both the skip value and the address
at the same time when we do fseeko (when file is seekable) or getchar (when
file is not seekable).

This commit fixes the problem by expecting the skip value to be zero upon
return of next(). If the condition is not satisfied, a diagnostic message
will be issued.

Reported-by:	Mohamed Akram <mohd.akram@outlook.com>
Reviewed-by:	emaste
PR:		271832
MFC-after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D40446
2023-06-07 18:06:07 -07:00
Ben Harris
37e3f5b23b Enable support for printing 8-byte integers. For some reason, most of the
code for this was present, but disabled.
This is required for POSIX compliance on platforms with 8-byte longs.

Obtained-From:	NetBSD
PR:		238586
Reported-By:	Mohamed Akram <mohd.akram@outlook.com>
MFC after:	2 weeks
2023-06-04 19:23:35 -07:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Poul-Henning Kamp
272144ab41 hexdump: Flush stdout after '*' (repeat) lines.
The canonical annoying example being:   hexdump < /dev/zero | less
2021-07-29 06:40:57 +00:00
Fernando Apesteguía
ac2adfb86d hexdump(1): Add EXAMPLES section
* Add examples showing the use of -f, -C, -s, -n
 * Rework the two already present examples that were *format* examples
 * Remove .Tn suggested by mandoc(1)
 * Remove reference to gdb(1) since it is not present in current

Approved by:	manpages (gbe)
Differential Revision:	https://reviews.freebsd.org/D25406
2020-06-29 15:15:14 +00:00
Fernando Apesteguía
63280725b2 od(1): Add EXAMPLES section
* Add two small examples showing the use of -a, -c, -j and -N
 * While here, remove obsolete .Tn reported by mandoc(1)

Approved by:	0mp@
Differential Revision:	https://reviews.freebsd.org/D25372
2020-06-23 07:48:48 +00:00
Kyle Evans
8a9f144c9e hexdump: tests: take into account byte order
Hexdump test was failling on big endian systems when testing decimal, octal
and hexa outputs as the tests were designed on a little endian system. This
revision adds the two distinct flavors of output expected and determines at
runtime which to compare against.

Submitted by:	Renato Riolino <renato.riolino_eldorado.org.br>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D23191
2020-03-02 18:40:34 +00:00
Conrad Meyer
8fb93ac95d hexdump(1): Exit gracefully on format strings missing conversion
PR:		237263
Submitted by:	Bojan Petrovic <bojan_petrovic AT fastmail.fm>
2019-04-13 16:51:48 +00:00
Mariusz Zaborski
7672a0148f Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0.
No functional change intended.
2018-06-19 23:43:14 +00:00
Kyle Evans
f0fb94abca Standardize SPDX tag on files I've added 2018-05-09 16:52:28 +00:00
Li-Wen Hsu
08c80489cd Silence the gcc warning: 'op' may be used uninitialized in this function
Approved by:	kevans
2018-01-20 15:37:47 +00:00
Kyle Evans
450c7a04f7 od(1): Fix mis-patch from r328188
od_test.sh got duplicated erroneously when it was added in r328188. Dedup.
2018-01-20 03:50:56 +00:00
Kyle Evans
6bb764934c od(1): Fix wrong output for some corner cases in multibyte locales.
Restore the original character to print if we used the look-ahead
buffer, but that didn't help -- we either got an illegal sequence
or still can't complete.

PR:		224552
Submitted by:	Yuri Pankov
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D13963
2018-01-20 02:49:32 +00:00
Kyle Evans
df7b0169fa hexdump(1): Speed up -s flag on devices
Using the -s flag on devices is extraordinarily slow due to using fseek(3) a
little too conservatively. Address this by using fseek on character/block
devices as well, falling back to getchar(3) only if we fail to seek or we're
operating on tape drives, where fseek may succeed while not actually being
supported.

PR:		86485
Submitted by:	arundel (originally; modified since then)
Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D10939
2018-01-05 01:46:41 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Bryan Drewery
3806950135 DIRDEPS_BUILD: Connect new directories.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:04:07 +00:00
Kyle Evans
7b9f317cf3 hexdump: Remove expected test failures for now succeeding tests
r323990 fixed the -s flag breakage reported by PR 219173. Mark the
corresponding hexdump tests accordingly, since they should now both succeed.

PR:		222781
Reported by:	ngie
Reviewed by:	emaste, ngie
Approved by:	emaste (mentor)
Differential Revision:	https://reviews.freebsd.org/D12590
2017-10-04 18:11:00 +00:00
Enji Cooper
d511b20a69 Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.
2017-08-02 08:50:42 +00:00
Enji Cooper
4b330699f8 Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
Kyle Evans
b5ddde39ac Add some basic tests for hexdump(1)'s various output flags. Formatting
tests are omitted for this initial run as there are still some bugs to work
out there.

This covers -s flag testing on devices and non-devices that would have
caught breakage found in PR 219173 as well as other subtle breakage caused
locally.

Reviewed by:	cem, ngie
Approved by:	cem (acting co-mentor)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D11279
2017-07-13 03:52:54 +00:00
Ed Maste
e47ea033a1 hexdump: actually enter capability mode on last file
Reviewed by:	cem, Kyle Evans
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D10897
2017-06-13 01:05:55 +00:00
Bryan Drewery
07676084ec DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-05-09 01:48:23 +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
Conrad Meyer
327240c75f hexdump(1): First cut capsicumification
For now, only enter the sandbox for the last file processed (including
stdin for zero-argument mode).

Sandboxing all inputs will require a little restructuring of the
program.

Feedback by:	emaste@ (earlier versions)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D7915
2016-12-16 02:03:40 +00:00
Pedro F. Giffuni
0c9426b684 hexdump(1): Simplify by using asprintf(3)
Instead of strlen() + calloc() + snprintf, just use asprintf().
No functional change.

Obtained from:	OpenBSD (CVS Rev. 1.22)
2016-09-19 18:35:22 +00:00
Kevin Lo
daa1a379ce Fix a bug that caused nothing to be skipped when skipping exactly the
number of bytes present in a regular file was requested.

Obtained from:	OpenBSD
2016-02-14 14:23:56 +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
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Jilles Tjoelker
c321006086 hexdump: Don't use uninitialized struct stat. 2015-04-26 21:34:55 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
John-Mark Gurney
de9dd94772 fix spelling of offset since that is what is used in the body... 2014-10-30 06:54:25 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Xin LI
a1217f20b4 Constify. 2014-04-25 04:01:25 +00:00
Christian Brueffer
8c91e67c8c Simplify the way the end of a singly linked list is followed (for adding
items), so it is more obvious that we aren't going to indirect through
a NULL pointer.

PR:		144723
Submitted by:	Garrett Cooper <yaneurabeya at gmail.com>
Obtained from:	NetBSD r1.19
MFC after:	2 weeks
2014-02-22 10:15:27 +00:00
Simon J. Gerraty
69e6d7b75e sync from head 2013-04-12 20:48:55 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00