Commit Graph

235 Commits

Author SHA1 Message Date
Pedro F. Giffuni
fc04dce059 Fix resource leak and dereference after NULL.
process.c:
Protect access against NULL.

main.c:
Prevent outfile overwrite resource leak.

CID:	271181
CID:	1006930

Obtained from:	NetBSD
MFC after:	3 days
2015-01-27 18:58:24 +00:00
Pedro F. Giffuni
a161398ab8 Replace __inline GNUism with the standard inline.
MFC after:	1 week
2015-01-13 00:04:22 +00:00
Jeremie Le Hen
98648ee85e Add a regression test for PR 192108.
I won't go through the hassle of MFCing it since I expect all changes to go
first through HEAD anyway.

PR:		192108
2015-01-10 10:16:22 +00:00
Pedro F. Giffuni
bfffbac603 Partial revert of r276832:
Do not bump the warns level as it still breaks the gcc build on sparc64

Reported by:	jenkins
2015-01-08 17:23:59 +00:00
Pedro F. Giffuni
707c9cc5d1 sed: Address warnings with clang and gcc48.
MFC after:	2 weeks
2015-01-08 16:33:15 +00:00
Pedro F. Giffuni
a34b42e43c sed: Bounds check the file path used in the 'w' command.
Modified version of a diff from Sebastien Marie to prevent a crash found
with the afl fuzzer.

Obtained from:	OpenBSD (CVS Rev. 1.37)
MFC after:	1 week
2014-12-16 20:26:11 +00:00
Simon J. Gerraty
9268022b74 Merge from head@274682 2014-11-19 01:07:58 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Jean-Sébastien Pédron
96d68291af sed(1): Don't force a newline on last line, if input stream doesn't have one
While here, change how we check if the current line is the last one.
Before, we just checked if there were more files after the current one.
Now, we check the actual content of those files: they files may not have
a line at all. This matches the definition of the "last line" by the
Open Group.

The new behavior is closer to GNU sed.

PR:		160745
Phabric:	https://phabric.freebsd.org/D431
Reviewed by:	jilles
Approved by:	jilles
Exp-run by:	antoine
2014-08-08 17:29:01 +00:00
Jeremie Le Hen
b38ebc0538 Fix relative numerical addressing (addr,+N).
As a bonus the patch untangles a bit the logic and makes the code
easier to grasp.

PR:		192108
MFC after:	1 week
2014-07-30 14:46:39 +00:00
Pedro F. Giffuni
f243100087 More sed(1) usage fixing: the extension -i is not optional.
Pointed out by:	jmallet
MFC after:	3 days
2014-07-03 00:31:13 +00:00
Pedro F. Giffuni
9b788a2e5b Fix sed(1) usage: the extension -i is not an optional.
MFC after:	3 days
2014-07-02 23:07:01 +00:00
Baptiste Daroussin
2b7af31cf5 use .Mt to mark up email addresses consistently (part3)
PR:		191174
Submitted by:	Franco Fichtner  <franco at lastsummer.de>
2014-06-23 08:23:05 +00:00
Pedro F. Giffuni
90d81f30ec Drop ifdef nonsense: just use setvbuf(3).
Pointed out by:		kib, bde
2014-06-21 14:07:33 +00:00
Pedro F. Giffuni
fc39ce9ee1 Add -u (unbuffered output) after GNU sed.
Obtained from:	NetBSD
MFC after:	1 week
2014-06-20 21:41:30 +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
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Warner Losh
c6063d0da8 Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.
2014-05-06 04:22:01 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Julio Merino
ad9105df49 Mark multi_test as requiring /usr/share/dict/words.
The file may not be present if MK_DICT=no.  Pointed out by Casey Peel.
2014-03-19 23:29:00 +00:00
Julio Merino
3a92d97ff0 Migrate most of tools/regression/usr.bin/ to the new tests layout.
I'm starting with the easy cases.  The leftovers need to be looked at a
bit more closely.

Note that this change _does_ modify the code of the old tests.  This is
required in order to allow the code to locate the data files in the
source directory instead of the current directory, because Kyua
automatically changes the latter to a temporary directory.

Also note that at least one test is known to be broken here.  Actually,
the test is not really broken: it's marked as a TODO but unfortunately
Kyua's TAP parser currently does not understand that.  Will have to be
fixed separately.
2014-03-16 08:04:06 +00:00
Eitan Adler
49e8901465 Per the resolution of POSIX bug 0000779 (note 0002050) add support for using 'i'
as a case insensitive flag.

PR:		standards/184641
Requested by:	David A. Wheeler <dwheeler@dwheeler.com>
MFC After:	1 week
2013-12-09 18:57:20 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Pedro F. Giffuni
1a2a4fc8ce sed: use getline() instead of fgetln().
In BSD, fgetln() available in libc but in Illumos the Solaris port had to
include it internally. It also seems to have caused problems [1].

Aid portability by using getline() instead.

Reference:
https://www.illumos.org/issues/3820 [1]

Submitted by:	Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.com>
Reviewed by:	dds
MFC after:	2 weeks
2013-06-26 04:14:19 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Andrey A. Chernov
7d3c2941c4 Reword '}' description to sound more clear.
Submitted by:   dougb
MFC after:      7 days
2011-10-29 06:13:47 +00:00
Andrey A. Chernov
c7d7f9a140 Update '}' description to reflect reality (and POSIX)
PR:             96236
Submitted by:   "Andreas Kohn" <andreas@syndrom23.de>
MFC after:      7 days
2011-10-28 20:28:13 +00:00
Jilles Tjoelker
919e14f01e sed: Try hard links to make -i target available continually.
When creating a backup file, sed renamed the original before renaming the
changed copy into place, leading to a short time when no file with the
original name was present (usually only visible on SMP systems). Try
creating the backup file using a hard link instead, avoiding this problem.
If creating the hard link fails for any reason, fall back to the old rename
method.

When not creating a backup file, sed already renamed the changed copy onto
the original. This remains unchanged.

I am not adding the suppression of redundant fchown/fchmod to this commit,
because FreeBSD appears to check this in the kernel (for msdosfs at least).

PR:		bin/153261
Submitted by:	Pedro F. Giffuni
Reviewed by:	dds (older version)
Obtained from:	Illumos
MFC after:	2 weeks
2011-01-08 00:03:18 +00:00
Warner Losh
701d73b65c Make -r mean exactly the same thing as -E for increased compatibility
with GNU sed.

MFC after:	7 days
2010-03-31 17:40:13 +00:00
Ed Schouten
b7946da96b Build usr.bin/ with WARNS=6 by default.
Also add some missing $FreeBSD$ to keep svn happy.
2010-01-02 10:27:05 +00:00
Xin LI
821df508e8 Revert most part of 200420 as requested, as more review and polish is
needed.
2009-12-13 03:14:06 +00:00
Xin LI
6f2d322192 Remove unneeded header includes from usr.bin/ except contributed code.
Tested with:	make universe
2009-12-11 23:35:38 +00:00
Diomidis Spinellis
ac8f32ce62 IEEE Std 1003.1, 2004 Edition states:
"The escape sequence '\n' shall match a <newline> embedded in
the pattern space."

It is unclear whether this also applies to a \n embedded in a
character class.  Disable the existing handling of \n in a character
class following Mac OS X, GNU sed version 4.1.5 with --posix, and
SunOS 5.10 /usr/bin/sed.

Pointed by:	Marius Strobl
Obtained from:	Mac OS X
2009-09-20 15:47:31 +00:00
Diomidis Spinellis
76570d0a99 Follow POSIX (IEEE Std 1003.1, 2004 Edition) in the implementation
of the y (translate) command.

"If a backslash character is immediately followed by a backslash
character in string1 or string2, the two backslash characters shall
be counted as a single literal backslash character"

Pointed by:	Marius Strobl
Obtained from:	Mac OS X
2009-09-20 15:17:40 +00:00
Diomidis Spinellis
128e6a12b5 Allow [ to be used as a delimiter.
Pointed by:	Marius Strobl
Obtained from:	Apple
2009-09-20 14:11:33 +00:00
Brian Somers
f1b746f92d Bump the document date to reflect the recent address range enhancements.
Suggested by:	throdes
2009-05-25 21:29:06 +00:00
Brian Somers
f879e8d923 Implement "addr1,+N" ranges - not dissimilar to grep's -A switch.
PR:		134856
Submitted by:	Jeremie Le Hen - jeremie at le-hen dot org
2009-05-25 06:45:33 +00:00
Diomidis Spinellis
46da6c4869 Fix the code to conform to the "or more" part of the following POSIX
specification and regression test regress:25.

  "A function can be preceded by one or more '!' characters, in which
  case the function shall be applied if the addresses do not select
  the pattern space."

MFC after:	2 weeks
2008-11-11 17:15:57 +00:00
Hiroki Sato
d3d0d3a3b5 Add workaround for a back reference when no corresponding
parenthesized subexpression is defined.  For example, the
following command line caused unexpected behavior like
segmentation fault:

 % echo test | sed -e 's/test/\1/'

PR:		bin/126682
MFC after:	1 week
2008-11-09 01:10:21 +00:00
Yaroslav Tykhiy
db6fc08364 Correct a silly typo I introduced: withing -> within.
Noticed by:	das
2008-09-01 17:48:40 +00:00
Yaroslav Tykhiy
625451f9f4 Explicitly tell that one needs to start a context address with a
backslash if he/she wants to use a non-traditional delimiter, i.e.,
anything other than a slash.  That is, /abc/ works as is, but xabcx
needs to be spelled as \xabcx.

Add appropriate markup.

Bump Dd.

Checked with:	IEEE Std 1003.1, 2004 Edition
MFC after:	3 days
2008-08-24 13:47:53 +00:00
David Malone
d3e5e11ce6 WARNS fixes:
1) Add missing parens around assignment that is compared to zero.
2) Make some variables that only take non-negative values unsigned.
3) Some casts/type changes to fix other constness warnings.
4) Make one variable a const char *.
5) Make sure termwidth is positive, it doesn't make sense for it to be negative.

Approved by:	dds
2008-02-09 09:12:02 +00:00
Diomidis Spinellis
a511e63958 Fix visibility of "inplace".
Found by: CScout
2007-11-08 08:57:51 +00:00
Xin LI
870945d830 Before doing compile_re() which needs a parameter to identify
whether we should ignore case, determine the flag by calling
compile_flags() first.  Also, make sure that we obtain an
initialized cmd->u.s buffer before processing further.  We
may want to refine this solution later, but for now, make
the changes in order to unbreak world build after a sed(1)
with rev. 1.29 of compile.c is installed.

Approved by:	re (hrs)
2007-07-06 16:34:56 +00:00
Suleiman Souhlal
bdd72b703b Add case-insensitive matching to sed, using the 'I' flag, similarly to GNU sed.
For example,
	sed /foo/Id
	sed s/foo/bar/Ig

Reviewed by:	dds
Approved by:	re (hrs)
2007-07-04 16:42:41 +00:00
Yaroslav Tykhiy
85ae5d2f94 Drop the argument to the OUT macro because it can't emit
anything but the pattern space anyway.  Apply style(9)
to the macro.

Tested with:	md5(1)
2007-06-12 12:17:25 +00:00
Yaroslav Tykhiy
26a5710c40 Don't forget to clear out the hold space for each subsequent file
when in -i mode so that each file gets a clean context of its own.

Add a regression test for the bug.

Tested with:	regression tests
2007-06-12 12:05:24 +00:00
Yaroslav Tykhiy
bebfe2adf7 There is a symbolic antonym for REPLACE as a flag to cspace()
and mf_fgets(): APPEND.  So use it instead of a 0 constant for
clarity.

Tested with:	md5(1)
2007-06-12 10:56:38 +00:00
Yaroslav Tykhiy
70b36fc0c8 Don't forget to bump document date after changing the content. 2007-04-21 01:22:51 +00:00
Yaroslav Tykhiy
f6703c9c0a Change the semantics of -i (in-place editing) so that it treats
each file independently from other files.  The new semantics are
desired in the most of practical cases, e.g.: delete lines 5-9
from each file.

Keep the previous semantics of -i under a new option, -I, which
uses a single continuous address space covering all files to edit
in-place -- they are too cool to just drop them.

Add regression tests for -i and -I.

Approved by:	dds
Compared with:	GNU sed
Discussed on:	-hackers
MFC after:	2 weeks
2007-04-21 01:21:36 +00:00
Yaroslav Tykhiy
9cfc96edd7 style(9):
Use a single space before $FreeBSD$ to avoid terminal line overflow.

Pointed out by:		ru (The All-Seeing Eye)
2007-04-06 08:43:30 +00:00
Yaroslav Tykhiy
4ebdfcd2e1 Add an important detail to paragraph 12: the range is reset only if its
second address is a line number.
2007-04-05 17:12:01 +00:00
Yaroslav Tykhiy
0d68e7fead Reflect the change in rev. 1.44 of process.c.
Add $FreeBSD$ to please commit_prep.pl.
2007-04-05 13:31:17 +00:00
Yaroslav Tykhiy
e9a0eed451 Don't forget to close the range if we branched over its end
and had no chance to match it by the 2nd address precisely.
Otherwise the unclosed range would bogusly extend to the end
of stream.

Add a basic regression test for the bug fixed.  (This change
also fixes the more complex case 5.3 from `multitest.t'.)

Compared with:	SUN and GNU seds
Tested by:	regression tests
MFC after:	1 week
2007-04-02 08:14:46 +00:00
Yaroslav Tykhiy
b1b46280cb Prevent foot-shooting in advance: Put the MATCH() macro's value
in parentheses.  The ?: operator has a remarkably low precedence, so
expressions like (MATCH(foo) && bar) would have an unexpected meaning
w/o the parentheses around MATCH().

Tested with:	md5(1)
2007-04-02 06:47:48 +00:00
Yaroslav Tykhiy
6b8ef68111 This trivial change should fix at least 3 similar bugs. All of
them are related to the `c' function's need to know if we are at
the actual end of the address range.  (It must print the text not
earlier than the whole pattern space was deleted.)  It appears the
only sed function with this requirement.

There is `lastaddr' set by applies(), which is to notify the `c'
function, but it can't always help because it's false when we are
hitting the end of file early.  There is also a bug in applies()
due to which `lastaddr' isn't set to true on degenerate ranges such
as `$,$' or `N,$' if N appears the last line number.

Handling early EOF condition in applies() could look more logical,
but it would effectively revert sed to the unreasonable behaviour
rev. 1.26 of main.c fought against, as it would require lastline()
be called for each line within each address range.  So it's better
to call lastline() only if needed by the `c' function.

Together with this change to sed go regression tests for the bugs
fixed (c1-c3).  A basic test of `c' (c0) is also added as it helped
me to spot my own error.

Discussed with:		dds
Tested by:		the regression tests
MFC after:		1 week
2007-04-01 13:25:03 +00:00
Yaroslav Tykhiy
c691c0ed18 Make the comment for cspace() match reality. 2007-03-31 09:08:22 +00:00
Diomidis Spinellis
d6eb3444a3 Test files repo-copied into tools/regression/usr.bin/sed and integrated
into the regression testing framework.
2007-03-14 13:43:32 +00:00
Kirill Ponomarev
85184b8b23 Fix using "P" command on empty pattern space. If the "P" command is
used once on a non-empty pattern space and then again on an empty
pattern space, the second usage restores the pattern space length to
the length that it had when the first "P" was used.

PR:		bin/96052
Submitted by:	Andrey Zholos <aaz@althenia.net>
MFC after:	7 days
2006-05-27 19:32:28 +00:00
Stefan Farfeleder
7c4847b792 The function inplace_edit() doesn't exist anymore, remove the prototype.
Submitted by:	Leonardo Chiquitto Filho
2005-09-24 13:18:30 +00:00
Diomidis Spinellis
d432588e78 Bug fix: a numeric flag specification in the substitute command would
cause the next substitute flag to be ignored.
While working at it, detect and report overflows.

Reported by:	Jingsong Liu
MFC after:	1 week
2005-08-04 10:05:12 +00:00
Ruslan Ermilov
39c59153e9 Markup and wording fixes.
Approved by:	re (blanket)
2005-06-14 11:50:53 +00:00
Gleb Smirnoff
1ed86f6c90 Add option -l, to make output line buffered.
PR:		bin/78692
Submitted by:	Eugene Grosbein
MFC after:	2 weeks
2005-05-10 13:40:50 +00:00
Stefan Farfeleder
6c97c3d1d3 Remove unused variables. 2005-04-09 14:31:41 +00:00
Stefan Farfeleder
3dc2fe25dc Fix dubious C code construct. 2005-03-09 11:57:32 +00:00
Ruslan Ermilov
0227791b40 Expand *n't contractions. 2005-02-13 22:25:33 +00:00
Stefan Farfeleder
a3eb24c68b Include missing headers. 2005-02-09 09:13:36 +00:00
Ruslan Ermilov
a866e17077 Added the EXIT STATUS section where appropriate. 2005-01-17 07:44:44 +00:00
Ruslan Ermilov
4438d91ea2 Scheduled mdoc(7) sweep. 2005-01-11 10:32:52 +00:00
Diomidis Spinellis
30fd73fb81 Per letter dated July 22, 1999 remove 3rd clause of Berkeley derived
software (original contributor).

Reviewed by:	imp
2004-08-09 15:29:41 +00:00
Tim J. Robbins
e4d0177f50 Document the limitation that multibyte characters cannot be used as
delimiters with the 's' and 'y' commands.
2004-07-17 03:37:31 +00:00
Tim J. Robbins
220d8b581a Document the -E and -a options as being extensions. 2004-07-14 10:37:21 +00:00
Tim J. Robbins
8b086367a0 Update BUGS section to reflect current state of multibyte character support. 2004-07-14 10:33:29 +00:00
Tim J. Robbins
81a8648adb Make the 'y' (translate) command aware of multibyte characters. 2004-07-14 10:06:22 +00:00
Tim J. Robbins
b4828720f7 Overhaul lputs() to deal with multibyte characters, characters that take
up more than one column position, and null bytes.
2004-07-13 04:35:43 +00:00
Tim J. Robbins
4f45d81178 Document missing multibyte character support in utilities specified
by POSIX.
2004-07-03 01:28:21 +00:00
Ruslan Ermilov
6a3e8b0adc Mechanically kill hard sentence breaks. 2004-07-02 22:22:35 +00:00
Ruslan Ermilov
d37ea99837 Removed trailing whitespace. 2004-07-02 19:07:33 +00:00
Brian Somers
7bbdbe1482 Plug a file descriptor leak.
When sed is asked to inline-edit files, it forgets to close the temporary
file and runs out of descriptors for long command lines (assuming you reset
kern.maxfilesperproc to something sane that's less than the number of files
passed to sed).
2004-06-03 22:33:50 +00:00
Sean Kelly
528d980cc0 A new version that does exponents and lots of other neat things. Update
from the original author of math.sed.

Submitted by:	K S Braunsdorf <sed@ksb.npcguild.org>
2004-05-01 02:15:58 +00:00
Philippe Charnier
ca802a8abe Avoid using .Nm at the start of the sentence. 2004-01-04 15:33:06 +00:00
Dag-Erling Smørgrav
591c337e01 Fix the case where the file is not in the current directory.
Discovered by:	Vladimir Kravchenko <jimson@mostcom.ru>
Pointy hat to:	des
2003-11-04 22:39:25 +00:00
Dag-Erling Smørgrav
f54cda1467 Reimplement in-place editing in a slightly less disgusting manner. Also,
make an effort to preserve the ownership and mode of the file we are
editing.

Sponsored by:	Registrar AS
2003-11-04 13:09:16 +00:00
Dag-Erling Smørgrav
9cde9a2e85 Whitespace cleanup 2003-11-04 12:16:47 +00:00
Dag-Erling Smørgrav
e6478125c8 ANSIfy 2003-11-04 12:15:20 +00:00
Dag-Erling Smørgrav
9df25dda8c Correct style bugs in the in-place editing code. 2003-11-04 12:07:09 +00:00
Tim J. Robbins
ce20a8e9be Change the buffer length test in NEEDSP() so that it does not
subtract one unsigned number from another potentially smaller
one, leading to wraparound (and heap corruption, eventually).

PR:		58813
MFC after:	2 weeks
2003-11-02 23:20:24 +00:00
Diomidis Spinellis
b6059c5c01 Fixed .Nm element, updated HISTORY section, added AUTHORS section.
Reviewed by:	schweikh (mentor)
MFC after:	2 weeks
2003-07-22 19:23:45 +00:00
Diomidis Spinellis
37c94e1d78 Test 8.16 in sed.test tests the ability of a sed to handle an empty
regular expression as the first argument to a substitute command. If
used to test a sed which (erroneously) evaluates this at translation
time rather than at execution time, the bugged sed is put into an
infinite loop. This mode of failure seems excessive. Such a failing
sed is the Free Software Foundation's sed 3.02.

The specific test was also not being executed for the BSD sed.

Both problems are now fixed.

PR:		misc/25585
Submitted by:	Walter Briscoe <w.briscoe@ponl.com>
Approved by:	schweikh (mentor)
MFC after:	2 weeks
2003-07-22 19:22:08 +00:00
Tony Finch
c2b9b6eba8 Do not dribble zero bytes into the output, by replacing an obfuscated if
whose true and false clauses were equivalent with a check that we are
not about to stumble off the end of the line.

Reported by:	peter
Pointy hat to:	fanf
2003-06-05 12:10:19 +00:00
Tony Finch
2f17b7e279 Fix substitution when the regex matches the zero-length string.
There are two bugs: in the s///g case, the substitution didn't occur
at the end of the line; in the s///N case, the code didn't count
forwards along the line properly. See the sg, s3, s4, and s5 tests
in src/tools/regression/usr.bin/sed/.

Reviewed by:	tjr
2003-06-04 15:31:55 +00:00
Jens Schweikhardt
9d5abbddbf Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,
especially in troff files.
2003-01-01 18:49:04 +00:00
Ruslan Ermilov
06e482e60a mdoc(7) police: markup polishing.
Approved by:	re
2002-11-26 17:33:37 +00:00
Eric Melville
b81df0819d Initialize a variable in order to fix when faced with picky compilers.
Sponsored by:	Apple
2002-09-20 19:40:23 +00:00
Tim J. Robbins
13ee49d316 Correct boundary condition error in D' and P' commands when the last
line of the pattern space is empty. Don't emit spurious newline when
EOF is reached with the `N' command.

Pointed out by:	Oleg Osyka
MFC after:	1 week
2002-08-11 09:53:44 +00:00
Tony Finch
d1691a2ff6 Fix some bugs in in-place editing:
(1) errors from freopen were not reported correctly
(2) large files were not handled correctly
(3) read-only files broke things

MFC after:	1 week
2002-07-30 19:42:18 +00:00