Commit graph

29 commits

Author SHA1 Message Date
Warner Losh 2e406c584f ota: Import One True Awk from 20231102 (254b979f32df)
This is a rollup of a lot of changes. In summary, lots of bug fixes,
Unicode support and CSV support to match the 2nd Edition of the Awk
Book.

In detail, from AWK's FIXES and FIXES.1e:

From FIXES:
Oct 30, 2023:
	multiple fixes and a minor code cleanup.
	disabled utf-8 for non-multibyte locales, such as C or POSIX.
	fixed a bad char * cast that causes incorrect results on big-endian
	systems. also fixed an out-of-bounds read for empty CCL.
	fixed a buffer overflow in substr with utf-8 strings.
	many thanks to Todd C Miller.

Sep 24, 2023:
	fnematch and getrune have been overhauled to solve issues around
	unicode FS and RS. also fixed gsub null match issue with unicode.
	big thanks to Arnold Robbins.

Sep 12, 2023:
	Fixed a length error in u8_byte2char that set RSTART to
	incorrect (cannot happen) value for EOL match(str, /$/).

-----------------------------------------------------------------

[This entry is a summary, not a precise list of changes.]

	Added --csv option to enable processing of comma-separated
	values inputs.  When --csv is enabled, fields are separated
	by commas, fields may be quoted with " double quotes, fields
	may contain embedded newlines.

	If no explicit separator argument is provided, split() uses
	the setting of --csv to determine how fields are split.

	Strings may now contain UTF-8 code points (not necessarily
	characters).  Functions that operate on characters, like
	length, substr, index, match, etc., use UTF-8, so the length
	of a string of 3 emojis is 3, not 12 as it would be if bytes
	were counted.

	Regular expressions are processes as UTF-8.

	Unicode literals can be written as \u followed by one
	to eight hexadecimal digits.  These may appear in strings and
	regular expressions.

From FIXES.1e:

Sep 06, 2023:
	Fix edge case where FS is changed on commandline. Thanks to
	Gordon Shephard and Miguel Pineiro Jr.

	Fix regular expression clobbering in the lexer, where lexer does
	not make a copy of regexp literals. also makedfa memory leaks have
	been plugged. Thanks to Miguel Pineiro Jr.

Dec 15, 2022:
	Force hex escapes in strings to be no more than two characters,
	as they already are in regular expressions. This brings internal
	consistency, as well as consistency with gawk. Thanks to
	Arnold Robbins.

Sep 12, 2022:
	adjbuf minlen error (cannot be 0) in cat, resulting in NULL pbuf.
	discovered by todd miller. also use-after-free issue with
	tempfree in cat, thanks to Miguel Pineiro Jr and valgrind.

Aug 30, 2022:
	Various leaks and use-after-free issues plugged/fixed.
	Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>.

May 23, 2022:
	Memory leak when assigning a string to some of the built-in
	variables. allocated string erroneously marked DONTFREE.
	Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>.

Mar 14, 2022:
	Historic bug: command-line "name=value" assignment had been
	truncating its entry in ARGV. (circa 1989) Thanks to
	Miguel Pineiro Jr. <mpj@pineiro.cc>.

Mar 3, 2022:
	Fixed file management memory leak that appears to have been
	there since the files array was first initialized with stdin,
	stdout, and stderr (circa 1992). Thanks to Miguel Pineiro Jr.
	<mpj@pineiro.cc>.

December 8, 2021:
	The error handling in closefile and closeall was mangled. Long
	standing warnings had been made fatal and some fatal errors went
	undetected. Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>.

Nov 03, 2021:
        getline accesses uninitialized data after getrec()
	returns 0 on EOF and leaves the contents of buf unchanged.
	Thanks to Volodymyr Gubarkov, and Todd C Miller.

Oct 12, 2021:
	The fix for #83 changed the code to insert 2 chars, but the
	call to adjbuf just above it only allows for 1 char. This can
	cause a heap buffer overflow.

Sponsored by:		Netflix
2023-11-02 10:20:09 -06:00
Warner Losh f9002b8561 awk: bring in vendor branch from upstream 20210727
Changes since the last import:

July 27, 2021:
	As per IEEE Std 1003.1-2008, -F "str" is now consistent with
	-v FS="str" when str is null. Thanks to Warner Losh.

July 24, 2021:
	Fix readrec's definition of a record. This fixes an issue
	with NetBSD's RS regular expression support that can cause
	an infinite read loop. Thanks to Miguel Pineiro Jr.

	Fix regular expression RS ^-anchoring. RS ^-anchoring needs to
	know if it is reading the first record of a file. This change
	restores a missing line that was overlooked when porting NetBSD's
	RS regex functionality. Thanks to Miguel Pineiro Jr.

	Fix size computation in replace_repeat() for special case
	REPEAT_WITH_Q. Thanks to Todd C. Miller.

Also, for the first time, import all the tests.

Sponsored by:		Netflix
2021-08-01 10:04:30 -06:00
Warner Losh 746b7396bb one-true-awk: import 20210221 (1e4bc42c53a1) which fixes a number of bugs
Import the latest bsd-features branch of the one-true-awk upstream:

o Move to bison for $YACC
o Set close-on-exec flag for file and pipe redirects that aren't std*
o lots of little fixes to modernize ocde base
o free sval member before setting it
o fix a bug where a{0,3} could match aaaa
o pull in systime and strftime from NetBSD awk
o pull in fixes from {Net,Free,Open}BSD
o add BSD extensions and, or, xor, compl, lsheift, rshift

Sponsored by:		Netflix
2021-07-07 17:09:41 -06:00
Warner Losh 03ee4d05f1 Import latest one-true-awk from upstream
Import git hash 4189ef5d from https://github.com/onetrueawk/awk.git as
there's not been a release in a while.

Upstream one-true-awk woke-up! Time to catch up. This may also revert
FreeBSD changes that we'd placed in the vendor branch in anticipation
of their inclusion in upstream. That's not yet the case, and these
will be resolved in the merge.

See FIXES for a complete list of bugs fixed (starting with the Jun 7,
2018 entry).
2019-06-02 04:23:56 +00:00
Pedro F. Giffuni 3a4488f93f one-true-awk: have calloc(3) do the multiplication.
Recently upstreamed.
2017-03-16 21:26:26 +00:00
Pedro F. Giffuni 7fdcc31daa one-true-awk: replace 0 with NULL for pointers
Also remove a redundant semicolon.
Submitted upstream already.
2016-05-29 16:18:55 +00:00
Xin LI c323c12cd8 Vendor import of bwk's Dec 20, 2012 version. 2013-01-02 21:53:45 +00:00
Ruslan Ermilov b0f5e94e3f Corrected description of the bugfix; distfile was updated. 2011-08-11 10:24:09 +00:00
Ruslan Ermilov 0abe4b0321 Vendor import of bwk's 10-Aug-2011 release. 2011-08-11 04:58:20 +00:00
Ruslan Ermilov 9cb3faa660 Vendor import of bwk's 7-Aug-2011 release. 2011-08-09 12:23:27 +00:00
Ruslan Ermilov e2f76e526c Vendor import of bwk's 6-May-2011 release. 2011-05-06 14:08:24 +00:00
Ruslan Ermilov f11de29169 Don't track the generated file. 2011-05-06 14:07:34 +00:00
Ruslan Ermilov bd726c262e Vendor import of bwk's 1-May-2011 release. 2011-05-03 11:37:03 +00:00
Ruslan Ermilov d9859a0e4b Vendor import of bwk's 26-Nov-2009 release. 2010-01-09 23:04:24 +00:00
Ruslan Ermilov 2f77d60407 Clean up. 2010-01-09 22:39:01 +00:00
Ruslan Ermilov 6023075d0d Flatten out vendor tree. 2010-01-09 22:31:11 +00:00
David E. O'Brien d2f6e49220 Vendor import of bwk's 23-Oct-2007 release.
This includes fixes for FreeBSD PR's: bin/104795, bin/100443
2007-10-25 12:38:02 +00:00
Rong-En Fan addad6af5a Vendor import of bwk's 01-May-2007 release.
Approved by:	delphij (mentor)
Nodded by:	ru
Tested by:	make universe
2007-06-05 15:33:51 +00:00
Ruslan Ermilov c263f9bff0 Vendor import of bwk's 24-Apr-2005 release. 2005-05-16 19:11:36 +00:00
Ruslan Ermilov 62ebc626e6 Vendor import of bwk's 7-Feb-2004 release. 2004-02-08 21:32:21 +00:00
Ruslan Ermilov 2e454f23fa Fixes from 31-Jul-2003; make it 8-bit clean.
Forgotten by:	ru (for far too long)
2004-02-05 23:16:31 +00:00
Ruslan Ermilov 88b8d48716 Vendor import of bwk's 29-Jul-2003 release. 2003-07-30 06:47:03 +00:00
David E. O'Brien fc6b1dfe95 Vendor import of bwk's 14-March-2003 release. 2003-03-17 07:59:59 +00:00
David E. O'Brien 72969a2212 Vendor import of bwk's 13-Dec-2002 release. 2002-12-19 04:33:15 +00:00
David E. O'Brien 813da98d0e Vendor import of bwk's 29-Nov-2002 release.
Most significant update is the inclusion of our port's locale patches.
2002-12-13 04:59:48 +00:00
David E. O'Brien 146a1e500c Vendor import of bwk's 2002-02-10 release. 2002-03-16 16:50:57 +00:00
Dag-Erling Smørgrav 007c6572bf Vendor import of bwk's 2002-02-18 release. Most significant update is the
inclusion of my character class patch.
2002-02-19 09:35:25 +00:00
Dag-Erling Smørgrav 82b279f73e We don't need ths file. 2002-02-19 09:27:25 +00:00
David E. O'Brien 2a55deb138 Import the One True AWK, in the form of bwk's AWK Nov 15, 2000 release. 2001-10-27 08:07:37 +00:00