History log of /freebsd-current/usr.bin/split/split.c
Revision Date Author Comments
# 95032b58 03-May-2024 Shawn Bayern <sbayern@law.fsu.edu>

Tighten boundary check in split(1) to prevent a potential buffer overflow.

Before increasing sufflen, make sure the current name plus two (including
the terminating NUL character and the to-be-added character) does not
exceed the fixed buffer length, and stop immediately if this would occur.

In worst case scenario the code would write an nul character beyond the
boundary, however it would be caught by open(2) and based on the memory
layout, we do not believe this would constitute a security vulnerability.

MFC after: 3 days


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

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


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

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


# d9d69a6f 28-Sep-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

split: Improve GNU compatibility.

* Like GNU split, turn autoextend back on if given -a0.
* Add a test case that verifies that -a<non-zero> turns autoextend off.
* Add a test case that verifies that -a0 turns autoextend back on.

Sponsored by: Klara, Inc.
Reviewed by: christos, kevans
Differential Revision: https://reviews.freebsd.org/D42011


# d7399551 28-Sep-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

split: Further option parsing improvements.

* Whenever possible, use strtonum() to parse numeric arguments.
* Improve usefulness and consistency of error messages.
* While here, fix some type and style issues.

Sponsored by: Klara, Inc.
Reviewed by: christos, kevans
Differential Revision: https://reviews.freebsd.org/D42010


# 117c54a7 05-Sep-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

split: Fix linecount parsing.

The “undocumented kludge” which unfortunately can't be dropped for backward compatibility reasons was prone to segfaulting and would improperly allow a new linecount when one was already set. Fix these issues and add regression tests.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D41757


# 851bf856 05-Sep-2023 Dag-Erling Smørgrav <des@FreeBSD.org>

split: Code cleanup.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D41756


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# cccdaf50 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# ac17fc81 30-May-2023 Jan Schaumann <jschauma@netmeister.org>

split(1): add '-c' to continue creating files

Currently, split(1) will clobber any existing output files:

$ split file; ls
xaa xab xac xad
$ split second-file; ls
xaa xab xac xad xae xaf

This patch adds a flag "-c" (mnemonic "create, don't overwrite" or
"continue where you left off"):

$ split file; ls
xaa xab xac xad
$ split -c second-file; ls
xaa xab xac xad xae xaf xag xah xai xaj

Reviewed by: christos
Approved by: kevans
Different Revision: https://reviews.freebsd.org/D38553


# c4f7198f 30-May-2023 Jan Schaumann <jschauma@netmeister.org>

split(1): auto-extend suffix length if required

If the input cannot be split into the number of files resulting from the
default suffix length, automatically extend the suffix length rather
than bailing out with 'too many files'.

Suffixes are extended such that the resulting files continue to sort
lexically and "cat *" would reproduce the input. For example, splitting
a 1M lines file into (default) 1000 lines per file would yield files
named 'xaa', 'xab', ..., 'xyy', 'xyz', 'xzaaa', 'xzaab', ..., 'xzanl'.

If '-a' is specified, the suffix length is not auto-extended.

This behavior matches GNU sort(1) since around version 8.16.

Reviewed by: christos
Approved by: kevans
Different Revision: https://reviews.freebsd.org/D38279


# fb499259 14-Apr-2023 Mateusz Piotrowski <0mp@FreeBSD.org>

split: Update synopsis and usage; fix examples

- Mark -d as an optional flag
- Add a prompt to one of the examples for consistency
- Add -d to the usage message

Sponsored by: Klara Inc.


# 172be864 26-Oct-2022 Math Ieu <sigsys@gmail.com>

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: 5c053aa3c5e90 ("split: switch to getline() [...]")


# 5c053aa3 22-Aug-2022 Kyle Evans <kevans@FreeBSD.org>

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.
Differential Revision: https://reviews.freebsd.org/D36323


# bcd34af4 02-Oct-2019 Alexander Kabaev <kan@FreeBSD.org>

Revert r352953: Convert pnmatch to single element array in regexec calls

Requested by: cem


# c5672dd7 02-Oct-2019 Alexander Kabaev <kan@FreeBSD.org>

Convert pnmatch to single element array in regexec calls

The regexec function is declared as taking an array of regmatch_t
elements, and passing in the pointer to singleton element, while
correct, triggers a Coverity warning. Convert the singleton into
an array of one to silence the warning.

Reported by: Coverity
Coverity CID: 1009732, 1009733
MFC after: 2 weeks


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

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.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

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


# 3ebd4af7 09-Nov-2013 Eitan Adler <eadler@FreeBSD.org>

Change manual string conversion to expand_number

Reviewed by: adrian


# 89c5c3aa 21-May-2013 Eitan Adler <eadler@FreeBSD.org>

Avoid signed overflow in error handling code.

Reviewed by: cperciva, bjk


# 7f418e34 09-May-2013 Eitan Adler <eadler@FreeBSD.org>

Implement 'split -d' which allows a numeric suffix instead of an
alphabetic one.

PR: bin/116209
Submitted by: Marcin Gryszkalis <mg@fork.pl> (adapted from)
Reviewed by: will
MFC after: 1 week


# af9eff1f 09-Jan-2012 Eitan Adler <eadler@FreeBSD.org>

Fix warning when compiling with gcc46:
error: variable 'defname' set but not use

Approved by: dim
MFC after: 3 day


# 973aa6bc 06-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Add missing static keywords to split(1)


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 0e286f08 16-Mar-2008 David Schultz <das@FreeBSD.org>

Add a -n option to split(1) to split files into N chunks rather than
having to specify the right number of bytes.

Obtained from: NetBSD
Submitted by: Jan Schaumann <jschauma@netmeister.org>
PR: 113175


# a6dd1c93 10-Aug-2006 Giorgos Keramidas <keramida@FreeBSD.org>

Add support for splitting at gigabyte boundaries. [1]

Also make both lowercase and uppercase suffix letters work
as byte-count suffixes, i.e. the following two commands are
equivalent now:

% split -b 4m foo
% split -b 4M foo

Submitted by: Roman Divacky [1]
Lots of help by: cperciva
Reviewed by: cperciva
MFC after: 1 week


# 49198c42 08-Aug-2006 Giorgos Keramidas <keramida@FreeBSD.org>

Update usage & SYNOPSIS and clarify that input files are not removed.
Sort getopt option handling of -p too, while here.

The changes are adapted from a patch by Ruslan Ermilov, posted as
followup to docs/33852.

PR: docs/33852
Submitted by: Gary W. Swearingen <swear@blarg.net>
MFC after: 1 week


# bb78dba4 29-Aug-2005 Tim J. Robbins <tjr@FreeBSD.org>

Remove undocumented historic support for treating "-" as an option
instead of a file operand; this is not compatible with POSIX.


# e93586df 21-Aug-2005 Tim J. Robbins <tjr@FreeBSD.org>

Remove the hack that varied the first character of the output file name
if none was specified on the command line. This is not permitted by
POSIX, and no longer needed now that we have the -a option.

PR: 85099
Submitted by: Toby Peterson (Apple Computer)


# 0742d4ed 11-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Respect locale settings from the environment.


# c81180b8 14-Jul-2002 Tim J. Robbins <tjr@FreeBSD.org>

Support larger files (at least 64-bit offsets) by using off_t instead of
int to store offsets.


# 2c69ee9b 15-Jun-2002 Juli Mallett <jmallett@FreeBSD.org>

Remove <sys/types> where we use <sys/param> already.

protoize.


# 3e4228c3 26-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Allow "-" to be specified as an operand as well as an option.
SUSV3 requires something like "split -- -" to work. Document the "-" operand.


# 3f5869d0 26-May-2002 Tim J. Robbins <tjr@FreeBSD.org>

Avoid overflowing `fname' if the file name prefix given on the command
line is too long.

Obtained from: OpenBSD


# 3f330d7d 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# 41850495 31-Jan-2002 Mike Barcroft <mike@FreeBSD.org>

Add -a option (SUSv3) to split(1).

Submitted by: Tim J. Robbins <tim@robbins.dropbear.id.au>
MFC after: 1 month


# f1d37c20 12-Dec-2001 Mark Murray <markm@FreeBSD.org>

WARNS=2 fixes, use __FBSDID, remove GCC-specific flags.


# aecbd999 18-Nov-2000 John W. De Boskey <jwd@FreeBSD.org>

Add/fix the ability to split a file larger than 2 gigabytes.

Added $FreeBSD tag (in the way the already present sccsid is
done). I've been told the rcsid stuff may be of dubious value
so I'm curious to know if folks (still) use it.

Submitted by: Brad Chisholm <blc@bsdwins.com>


# d37fcb98 04-Feb-1999 Archie Cobbs <archie@FreeBSD.org>

Print usage via fprintf(stderr, ..) instead of errx() to avoid progname prefix.
Submitted by: Philippe Charnier <charnier@xp11.frmug.org>


# 2fa6610f 01-Feb-1999 Archie Cobbs <archie@FreeBSD.org>

Add new option '-p pattern' for splitting files based on matching lines in
the file with a regular expression. Useful for e.g. 'cvs diff' output.
Also compile cleanly with -Wall and fix a few style bugs.
PR: bin/9405


# c002b33b 11-Aug-1997 Philippe Charnier <charnier@FreeBSD.org>

Cosmetic in err() string.


# c44252b6 06-Jul-1997 Bruce Evans <bde@FreeBSD.org>

Finish importing Lite2's src/usr.bin, except for ex, diff, grep, mail,
pascal and vmstat.sparc. All changed files on the vendor branch should
already have been imported.


# 1c8af878 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# a3f8d23a 07-Jul-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

This fixes 'split -l NNN foo'. As it stands split will
complain about an 'illegal line count' becuase it's looking
at the wrong end pointer (ep) to detect any extra characters
after the NNN.

Submitted by: Rich Murphey <rich@freebsd.org>

This should probably get pulled into 2.0.6 and 2.1.0


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources