History log of /openbsd-current/usr.bin/sed/process.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.35 12-Jan-2022 martijn

Make lputs use psl instead of expecting it to be null-terminated.
This allows us to enable the commandl1 and commandl2 regress tests.

Original analysis from seL4 <at> disroot <dot> org
OK millert@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.34 14-Nov-2018 martijn

Make sed's -i flag more compatible with what gsed does.
- Reset the hold-space in between files
- quit the editor as soon as a 'q' command is found
- Make sure the temp-file is written back to the original file if we quit
the editor

temp-file not written back issue found by Time Chase.
Lots of feedback from millert@ and schwarze@
OK millert@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.33 13-Dec-2017 millert

Fix sign compare warnings; OK martijn@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.32 22-Feb-2017 tom

Remove unused-with-dead-store variable oldpsanl.

From Daniel Cegielka - thanks

ok jca@


# 1.31 21-Jan-2017 krw

Nuke more whitespace caught in the headlights of "warning:"
rectification.


# 1.30 20-Jan-2017 krw

Split error() into error() and warning() so error() can be marked __dead to
appease gcc.

ok procter@ deraadt@


# 1.29 11-Oct-2016 martijn

Fix an off by one error when no matches were found in a substitute.
By pfg@ from FreeBSD

OK millert@ and otto@


Revision tags: OPENBSD_6_0_BASE
# 1.28 30-May-2016 martijn

Make sed use the new REG_STARTEND | REG_NOTBOL combination. This fixes a begin
of word mismatch as reported by jsg@.

Discussed with otto@ and others early on, earlier version tested in ports build
by aja@

OK millert@
Few readability tweaks and OK schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.27 26-Oct-2015 mmcc

Rename err() to error() to prevent confusion with the stdlib function.

Discussed with jca@.


Revision tags: OPENBSD_5_8_BASE
# 1.26 20-Jul-2015 jasper

fix eyesore whitespace


# 1.25 19-Jul-2015 deraadt

figure out the linewidth at initialization, rather than late
ok tedu miod


# 1.24 17-Jul-2015 jasper

add -i flag to sed to do in-place editing; mostly based on freebsd

feedback/ok deraadt@ millert@


# 1.23 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.22 13-Apr-2015 deraadt

correct multiplication idiom during xreallocarray, and expand appendnum
to size_t to avoid overflow after allocation success
ok guenther doug


Revision tags: OPENBSD_5_7_BASE
# 1.21 12-Dec-2014 jsg

Rework the pointer swap in the 'P' command to make the intent
clearer and avoid a crash on 'g;P' found by Sebastien Marie with
the afl fuzzer.


# 1.20 01-Dec-2014 deraadt

sed has a xreallocarray(), but two n*s cases were not replaced


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 28-Nov-2013 deraadt

unsigned char for ctype
ok krw okan


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.18 17-Sep-2011 schwarze

Rewrite the main loop of the "sed s/..." command, to fix multiple
issues regarding the replacement of zero-length strings.

This commit brings back rev. 1.16, but without the regression that
forced the backout: No NUL bytes will be output now, not even when
the input file lacks a trailing newline character and there is a
zero-length match at the end.

OK otto@ deraadt@;
and naddy@ (who originally found the regression) checked that
the regression is indeed fixed.


Revision tags: OPENBSD_5_0_BASE
# 1.17 26-Jul-2011 schwarze

Backout previous, naddy@ found the following regression:
When the input does not end in a trailing newline character
and there is an empty match at the end, the new code adds
a spurious '\0' character.
I have a fix, but otto@ prefers backout and full re-evaluation
after release.


# 1.16 24-Jul-2011 schwarze

Rewrite the main loop of the "sed s/..." command, shortening it by ten
lines and simplifying it by removing the switch statement implementing
/g, /1, and /2 separately and repetitively.
The idea to make the loop control variable slen, i.e. the length of the
string remaining to be processed, signed, and stay in the loop even when
slen == 0 (i.e. at the end of the string), lifted from FreeBSD by otto@.
On i386, process.o shrinks by 440 bytes, and the sed binary by 23 bytes.

This fixes multiple aspects of the replacement of multiple (/g) or
specific (e.g. /2) instances of zero-length matches, both with BREs and
EREs, both with and without a trailing newline character on the input.

Feedback and OK otto@.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.15 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.14 07-Oct-2008 millert

The 'l' command should not encode newlines. Also document that
backspace is escaped as \b. OK phessler@ and jmc@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.13 09-Oct-2006 tedu

pretty. the comma operator should not be used to cram two statements into
an if without braces, or worse, into a return.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.12 07-Nov-2003 tedu

prevent overflow, see freebsd r1.32. also, do nicer reallocs.
ok millert@ otto@


Revision tags: OPENBSD_3_4_BASE
# 1.11 10-Jun-2003 deraadt

mostly ansi cleanup; pval ok


# 1.10 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.9 11-Jun-2002 jsyn

kill err(3) newlines; ok miod@, deraadt@


# 1.8 15-Apr-2002 millert

Fix sed(1) in the case where a last line is specified and hold space
is not specified, and then the first part of the pattern space is
deleted, when there are two or more input lines, as this results
in subtraction of one from an unsigned integral value of '0'. That
bogus value is used in one case for a loop (that will run far too
many times in this case) and a function to search for a value within
a specified range of memory, however now the range of memory is
obscenely large and a segmentation (or memory) fault will occur.
This is fixed by checking for and appropriately handling a nil
pattern space as if the specified search in memory failed, as indeed
it obviously will with nil pattern space.

From Tim J. Robbins by way of FreeBSD


Revision tags: OPENBSD_3_1_BASE
# 1.7 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.6 19-Nov-2001 mpech

kill more registers

millert@ ok


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.5 06-Jun-1999 deraadt

make G newline if hold is empty


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.4 30-Apr-1998 deraadt

make y command 8 bit clean; Elmar.Bartel@informatik.tu-muenchen.de


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 11-Sep-1997 deraadt

extra ()


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 26-Jun-1996 deraadt

rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.34 14-Nov-2018 martijn

Make sed's -i flag more compatible with what gsed does.
- Reset the hold-space in between files
- quit the editor as soon as a 'q' command is found
- Make sure the temp-file is written back to the original file if we quit
the editor

temp-file not written back issue found by Time Chase.
Lots of feedback from millert@ and schwarze@
OK millert@


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.33 13-Dec-2017 millert

Fix sign compare warnings; OK martijn@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.32 22-Feb-2017 tom

Remove unused-with-dead-store variable oldpsanl.

From Daniel Cegielka - thanks

ok jca@


# 1.31 21-Jan-2017 krw

Nuke more whitespace caught in the headlights of "warning:"
rectification.


# 1.30 20-Jan-2017 krw

Split error() into error() and warning() so error() can be marked __dead to
appease gcc.

ok procter@ deraadt@


# 1.29 11-Oct-2016 martijn

Fix an off by one error when no matches were found in a substitute.
By pfg@ from FreeBSD

OK millert@ and otto@


Revision tags: OPENBSD_6_0_BASE
# 1.28 30-May-2016 martijn

Make sed use the new REG_STARTEND | REG_NOTBOL combination. This fixes a begin
of word mismatch as reported by jsg@.

Discussed with otto@ and others early on, earlier version tested in ports build
by aja@

OK millert@
Few readability tweaks and OK schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.27 26-Oct-2015 mmcc

Rename err() to error() to prevent confusion with the stdlib function.

Discussed with jca@.


Revision tags: OPENBSD_5_8_BASE
# 1.26 20-Jul-2015 jasper

fix eyesore whitespace


# 1.25 19-Jul-2015 deraadt

figure out the linewidth at initialization, rather than late
ok tedu miod


# 1.24 17-Jul-2015 jasper

add -i flag to sed to do in-place editing; mostly based on freebsd

feedback/ok deraadt@ millert@


# 1.23 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.22 13-Apr-2015 deraadt

correct multiplication idiom during xreallocarray, and expand appendnum
to size_t to avoid overflow after allocation success
ok guenther doug


Revision tags: OPENBSD_5_7_BASE
# 1.21 12-Dec-2014 jsg

Rework the pointer swap in the 'P' command to make the intent
clearer and avoid a crash on 'g;P' found by Sebastien Marie with
the afl fuzzer.


# 1.20 01-Dec-2014 deraadt

sed has a xreallocarray(), but two n*s cases were not replaced


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 28-Nov-2013 deraadt

unsigned char for ctype
ok krw okan


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.18 17-Sep-2011 schwarze

Rewrite the main loop of the "sed s/..." command, to fix multiple
issues regarding the replacement of zero-length strings.

This commit brings back rev. 1.16, but without the regression that
forced the backout: No NUL bytes will be output now, not even when
the input file lacks a trailing newline character and there is a
zero-length match at the end.

OK otto@ deraadt@;
and naddy@ (who originally found the regression) checked that
the regression is indeed fixed.


Revision tags: OPENBSD_5_0_BASE
# 1.17 26-Jul-2011 schwarze

Backout previous, naddy@ found the following regression:
When the input does not end in a trailing newline character
and there is an empty match at the end, the new code adds
a spurious '\0' character.
I have a fix, but otto@ prefers backout and full re-evaluation
after release.


# 1.16 24-Jul-2011 schwarze

Rewrite the main loop of the "sed s/..." command, shortening it by ten
lines and simplifying it by removing the switch statement implementing
/g, /1, and /2 separately and repetitively.
The idea to make the loop control variable slen, i.e. the length of the
string remaining to be processed, signed, and stay in the loop even when
slen == 0 (i.e. at the end of the string), lifted from FreeBSD by otto@.
On i386, process.o shrinks by 440 bytes, and the sed binary by 23 bytes.

This fixes multiple aspects of the replacement of multiple (/g) or
specific (e.g. /2) instances of zero-length matches, both with BREs and
EREs, both with and without a trailing newline character on the input.

Feedback and OK otto@.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.15 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.14 07-Oct-2008 millert

The 'l' command should not encode newlines. Also document that
backspace is escaped as \b. OK phessler@ and jmc@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.13 09-Oct-2006 tedu

pretty. the comma operator should not be used to cram two statements into
an if without braces, or worse, into a return.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.12 07-Nov-2003 tedu

prevent overflow, see freebsd r1.32. also, do nicer reallocs.
ok millert@ otto@


Revision tags: OPENBSD_3_4_BASE
# 1.11 10-Jun-2003 deraadt

mostly ansi cleanup; pval ok


# 1.10 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.9 11-Jun-2002 jsyn

kill err(3) newlines; ok miod@, deraadt@


# 1.8 15-Apr-2002 millert

Fix sed(1) in the case where a last line is specified and hold space
is not specified, and then the first part of the pattern space is
deleted, when there are two or more input lines, as this results
in subtraction of one from an unsigned integral value of '0'. That
bogus value is used in one case for a loop (that will run far too
many times in this case) and a function to search for a value within
a specified range of memory, however now the range of memory is
obscenely large and a segmentation (or memory) fault will occur.
This is fixed by checking for and appropriately handling a nil
pattern space as if the specified search in memory failed, as indeed
it obviously will with nil pattern space.

From Tim J. Robbins by way of FreeBSD


Revision tags: OPENBSD_3_1_BASE
# 1.7 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.6 19-Nov-2001 mpech

kill more registers

millert@ ok


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.5 06-Jun-1999 deraadt

make G newline if hold is empty


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.4 30-Apr-1998 deraadt

make y command 8 bit clean; Elmar.Bartel@informatik.tu-muenchen.de


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 11-Sep-1997 deraadt

extra ()


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 26-Jun-1996 deraadt

rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.33 13-Dec-2017 millert

Fix sign compare warnings; OK martijn@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.32 22-Feb-2017 tom

Remove unused-with-dead-store variable oldpsanl.

From Daniel Cegielka - thanks

ok jca@


# 1.31 21-Jan-2017 krw

Nuke more whitespace caught in the headlights of "warning:"
rectification.


# 1.30 20-Jan-2017 krw

Split error() into error() and warning() so error() can be marked __dead to
appease gcc.

ok procter@ deraadt@


# 1.29 11-Oct-2016 martijn

Fix an off by one error when no matches were found in a substitute.
By pfg@ from FreeBSD

OK millert@ and otto@


Revision tags: OPENBSD_6_0_BASE
# 1.28 30-May-2016 martijn

Make sed use the new REG_STARTEND | REG_NOTBOL combination. This fixes a begin
of word mismatch as reported by jsg@.

Discussed with otto@ and others early on, earlier version tested in ports build
by aja@

OK millert@
Few readability tweaks and OK schwarze@


Revision tags: OPENBSD_5_9_BASE
# 1.27 26-Oct-2015 mmcc

Rename err() to error() to prevent confusion with the stdlib function.

Discussed with jca@.


Revision tags: OPENBSD_5_8_BASE
# 1.26 20-Jul-2015 jasper

fix eyesore whitespace


# 1.25 19-Jul-2015 deraadt

figure out the linewidth at initialization, rather than late
ok tedu miod


# 1.24 17-Jul-2015 jasper

add -i flag to sed to do in-place editing; mostly based on freebsd

feedback/ok deraadt@ millert@


# 1.23 18-Apr-2015 deraadt

Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way.
Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert


# 1.22 13-Apr-2015 deraadt

correct multiplication idiom during xreallocarray, and expand appendnum
to size_t to avoid overflow after allocation success
ok guenther doug


Revision tags: OPENBSD_5_7_BASE
# 1.21 12-Dec-2014 jsg

Rework the pointer swap in the 'P' command to make the intent
clearer and avoid a crash on 'g;P' found by Sebastien Marie with
the afl fuzzer.


# 1.20 01-Dec-2014 deraadt

sed has a xreallocarray(), but two n*s cases were not replaced


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 28-Nov-2013 deraadt

unsigned char for ctype
ok krw okan


Revision tags: OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.18 17-Sep-2011 schwarze

Rewrite the main loop of the "sed s/..." command, to fix multiple
issues regarding the replacement of zero-length strings.

This commit brings back rev. 1.16, but without the regression that
forced the backout: No NUL bytes will be output now, not even when
the input file lacks a trailing newline character and there is a
zero-length match at the end.

OK otto@ deraadt@;
and naddy@ (who originally found the regression) checked that
the regression is indeed fixed.


Revision tags: OPENBSD_5_0_BASE
# 1.17 26-Jul-2011 schwarze

Backout previous, naddy@ found the following regression:
When the input does not end in a trailing newline character
and there is an empty match at the end, the new code adds
a spurious '\0' character.
I have a fix, but otto@ prefers backout and full re-evaluation
after release.


# 1.16 24-Jul-2011 schwarze

Rewrite the main loop of the "sed s/..." command, shortening it by ten
lines and simplifying it by removing the switch statement implementing
/g, /1, and /2 separately and repetitively.
The idea to make the loop control variable slen, i.e. the length of the
string remaining to be processed, signed, and stay in the loop even when
slen == 0 (i.e. at the end of the string), lifted from FreeBSD by otto@.
On i386, process.o shrinks by 440 bytes, and the sed binary by 23 bytes.

This fixes multiple aspects of the replacement of multiple (/g) or
specific (e.g. /2) instances of zero-length matches, both with BREs and
EREs, both with and without a trailing newline character on the input.

Feedback and OK otto@.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.15 27-Oct-2009 deraadt

rcsid[] and sccsid[] and copyright[] are essentially unmaintained (and
unmaintainable). these days, people use source. these id's do not provide
any benefit, and do hurt the small install media
(the 33,000 line diff is essentially mechanical)
ok with the idea millert, ok dms


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.14 07-Oct-2008 millert

The 'l' command should not encode newlines. Also document that
backspace is escaped as \b. OK phessler@ and jmc@


Revision tags: OPENBSD_4_1_BASE OPENBSD_4_2_BASE OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.13 09-Oct-2006 tedu

pretty. the comma operator should not be used to cram two statements into
an if without braces, or worse, into a return.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE
# 1.12 07-Nov-2003 tedu

prevent overflow, see freebsd r1.32. also, do nicer reallocs.
ok millert@ otto@


Revision tags: OPENBSD_3_4_BASE
# 1.11 10-Jun-2003 deraadt

mostly ansi cleanup; pval ok


# 1.10 03-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.9 11-Jun-2002 jsyn

kill err(3) newlines; ok miod@, deraadt@


# 1.8 15-Apr-2002 millert

Fix sed(1) in the case where a last line is specified and hold space
is not specified, and then the first part of the pattern space is
deleted, when there are two or more input lines, as this results
in subtraction of one from an unsigned integral value of '0'. That
bogus value is used in one case for a loop (that will run far too
many times in this case) and a function to search for a value within
a specified range of memory, however now the range of memory is
obscenely large and a segmentation (or memory) fault will occur.
This is fixed by checking for and appropriately handling a nil
pattern space as if the specified search in memory failed, as indeed
it obviously will with nil pattern space.

From Tim J. Robbins by way of FreeBSD


Revision tags: OPENBSD_3_1_BASE
# 1.7 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


# 1.6 19-Nov-2001 mpech

kill more registers

millert@ ok


Revision tags: OPENBSD_2_6_BASE OPENBSD_2_7_BASE OPENBSD_2_8_BASE OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.5 06-Jun-1999 deraadt

make G newline if hold is empty


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE
# 1.4 30-Apr-1998 deraadt

make y command 8 bit clean; Elmar.Bartel@informatik.tu-muenchen.de


Revision tags: OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.3 11-Sep-1997 deraadt

extra ()


Revision tags: OPENBSD_2_0_BASE OPENBSD_2_1_BASE
# 1.2 26-Jun-1996 deraadt

rcsid


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision