* testsuite/mb-bad-delim.sh: Don't run the sub-test that uses an
incomplete multibyte byte as a single-byte delimiter in C locale.
* testsuite/mb-y-translate.sh: Don't run the two sub-tests that
expect a y/// length-mismatch error in C locale.
Android's bionic libc uses UTF-8 even in the C locale, so these
sub-tests would always fail.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00019.html
* init.cfg (remove_selinux_warning_): New function.
* testsuite/in-place-hyphen.sh: Use it before comparing stderr.
* testsuite/in-place-suffix-backup.sh: Likewise.
* testsuite/panic-tests.sh: Likewise.
* testsuite/temp-file-cleanup.sh: Likewise.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00019.html
* testsuite/read-error-stale-errno.sh: Skip when a FIFO with
O_NONBLOCK returns EOF instead of EAGAIN while a writer is still
attached. Cygwin gets this wrong.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00011.html
* sed/regexp.c (match_regex): Change type of 'ret' from int
to regoff_t, to avoid truncation results larger than INT_MAX.
* testsuite/regex-max-int.sh: Update this "very expensive"
test to expect correct output (bbbbb) rather than exit-code-4 panic.
* NEWS (Bug fixes): Mention this.
The following is related but mostly incidental (--debug only).
I tested via --debug, (where it generate 20GB of output!), but couldn't
easily add a test case without adding a further option to suppress
debug printing of each escaped input line.
* sed/execute.c (do_subst): Don't cast regoff_t values to (int) for
debug printing via %d. Instead, cast to (ptrdiff_t) and print via %td.
* testsuite/panic-tests.sh: Test explicitly and skip if we can
still write to a directory that's been subject to "chmod a-w".
This struck on CentOS 7, Alma Linux, Alpine Linux and Cygwin.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2026-04/msg00008.html
Surprisingly (comparing with the grep fix for this same bug), this
no-anchor case works properly both before and after the fix:
$ echo ab | sed -E 's/^(.?)(.?).?\2\1/X/'
Xb
That is because sed uses RE_NO_POSIX_BACKTRACKING, which avoids
grep's find-longest-match behavior (just fixed) that POSIX requires.
* gnulib: Update to latest for the regex bug fix.
* testsuite/backref-anchor.sh: New file. Test for this.
* testsuite/local.mk (T): Add the new file.
* NEWS (Bug fixes): Mention this.
* THANKS.in: Update.
Reported by Ed Morton in https://bugs.gnu.org/68725
With --posix, normalize_text tracks bracket-expression state to avoid
converting \X escapes inside bracket expressions. It uses p[-1] and
p[-2] to detect the closing sequence of POSIX classes like [:alpha:].
However, normalize_text operates in-place with separate read (p)
and write (q) pointers, and when an earlier \n was collapsed from
two bytes to one, q falls behind p, so p[-1] and p[-2] read positions
already overwritten by q.
E.g., with '^A\n[[:alpha:]]\n*', the first \n shrinks, putting q one
byte behind p. When processing the closing ']' in '[:alpha:]', p[-2]
reads ':' (written by q) rather than the original 'a', making the
"p[-2] != bracket_state" check fail. Then, the second \n is never
converted to a newline.
* sed/compile.c (normalize_text): Use q[-1] and q[-2] for bracket
state tracking, not p[-1] and p[-2].
* NEWS: Mention this bug fix.
* testsuite/posix-bracket-esc.sh: New test.
* testsuite/local.mk (T): Add it.
Reported by Wolfgang Jeltsch in https://debbugs.gnu.org/77786
Using --debug after -f on the command line would deref uninitialized
memory usually evoking a segfault.
* sed/compile.c (next_cmd_entry): Zero-initialize the struct.
* sed/debug.c (debug_print_function): Print only when label_name
is non-NULL.
* testsuite/debug-label.sh: New test.
* testsuite/local.mk (T): Add it.
Reported in https://debbugs.gnu.org/70232
* sed/regexp.c (compile_regex_1): Clear RE_CONTEXT_INVALID_DUP for
BRE, to accept ** as a GNU extension. In --posix mode, restore
RE_CONTEXT_INVALID_DUP for BRE to enforce strict POSIX behavior.
* NEWS: Mention this bug fix.
* testsuite/bre-star-star.sh: New test.
* testsuite/local.mk (T): Add it.
Reported in https://debbugs.gnu.org/70476
* sed/compile.c: Remove cases for 'L' command.
* testsuite/compile-errors.sh: remove test for 'L' command in posix
mode. The 'L' command was removed in version 4.3, but was still allowed
by the compiler (resulting in an internal error when running a script
that uses it). Reported in https://bugs.gnu.org/80704
Before, it would print this:
$ echo | sed L1
sed: INTERNAL ERROR: Bad cmd L
Now, it prints this:
sed: -e expression #1, char 1: unknown command: 'L'
* sed/execute.c (line_reset): Also free buf->text when buf->alloc is zero.
* testsuite/bug80573.sh: New file.
* testsuite/local.mk (T): Add it to the list.
Demonstrate via this:
echo | valgrind --leak-check=full sed/sed -e x -e 's/.*/echo hi/e' 2>&1 | grep -A5 'definitely lost'
Reported in https://bugs.gnu.org/80573
As a GNU extension, "\c[" in a regexp matches the ESC character
(i.e., control-[). Yet 's/\c[//' was rejected because "[" was treated
as the beginning of a bracket expression.
* sed/compile.c (match_slash): When matching "slash"es, treat \c as
an escape sequence, so that s/\c[// no longer fails because it
misinterprets [ as a bracket-group start.
* testsuite/misc.pl (bug79519_1,2,3,fail): Add tests.
* NEWS (Bug fixes): Mention it.
Reported by Michael Ludwig in https://bugs.gnu.org/79519.
* sed/compile.c (match_slash): Convert regex parameter from int to bool
since all callers use true or false. Add s_command parameter and warn
about nonportable backslashes when true.
(compile_address, compile_program): Update calls to match_slash.
* testsuite/posix-backslash-warn.sh: New test.
* testsuite/local.mk (T): Add it.
* NEWS: Mention the change.
* sed/sed.c: Spell as <getopt.h> and hoist it to be with other system
header includes. Also, use "", not <> for "selinux/selinux.h".
* testsuite/test-mbrtowc.c: Same, for <error.h>.
* sed/utils.c (ck_rename): When diagnosting rename failure,
also mention the target file name.
* testsuite/in-place-suffix-backup.sh: Adjust test expectations
to match.
Reported by Sebastian Carlos in https://bugs.gnu.org/63833
* basicdefs.h: Do not include alloca.h.
* bootstrap.conf (gnulib_modules): Remove alloca, stdalign,
c-ctype, closeout, mbrlen, verify.
Add version-etc.
* lib/.gitignore, m4/.gitignore: Omit now-unused files.
* po/POTFILES.in: Remove closeout.c.
* testsuite/test-mbrtowc.c: Do not include closeout.h.
(main): Close stdout by hand, to avoid a dependency on closeout.
v4.9-14-g3d75b4a changed the diagnostic, but did not update
the occurrences of the diagnostic in expected test outputs.
* testsuite/compile-errors.sh: Accommodate changed diagnostic.
* testsuite/mb-y-translate.sh: Likewise.
* testsuite/normalize-text.sh: Likewise.
Reported by Bruno Haible in https://bugs.gnu.org/61159
Problem reported by Hauke Mehrtens.
* sed/utils.c (follow_symlink): Fix typo when checking size of
second and later symlink, when that symlink is so large that it
does not fit into the buffer. Although the bug is not a buffer
overflow, it does cause sed to mishandle the symlink.
* testsuite/follow-symlinks.sh: Test for the bug.
* testsuite/local.mk (TESTS_ENVIRONMENT): Remove the erroneous ";"
that effectively elided all following var=val pairs from the test
environment. Report and patch from http://bugs.gnu.org/57831
Bug introduced via v4.2.2-100-gb250bd4.
* bootstrap.conf (gnulib_modules):
Add eloop-threshold, idx, minmax, readlink.
* configure.ac: Do not check for lstat; no longer needed.
(ENABLE_FOLLOW_SYMLINKS): Remove; all uses removed.
(TEST_SYMLINKS): Depend only on readlink.
* sed/utils.c: Include eloop-threshold.h, idx.h, minmax.h.
(SSIZE_IDX_MAX): New macro.
(follow_symlink): Rewrite to not loop when given a symlink cycle.
Do not use lstat, since readlink suffices. Use just one memory
buffer, not two; this simplifies memory management.
* testsuite/follow-symlinks.sh: Adjust diagnostics to
to match revised behavior. Test for symlink loops.
Before this change, the testsuite/inplace-selinux test fails in some
cases when SELinux is available. The reason it fails is because the
require_selinux_ function in init.cfg expects the CONFIG_HEADER
environment variable to be defined, but in fact it is not defined.
Even though we do invoke AM_CONFIG_HEADER in configure.ac, and even
though the CONFIG_HEADER variable does get set in the resulting
Makefile, nothing actually exports the CONFIG_HEADER variable, so the
test is doomed to fail whenever it is not skipped. Fix this by
exporting the variable.
* testsuite/local.mk (TESTS_ENVIRONMENT): Add CONFIG_HEADER to the
list of variables to export to the environment of the test scripts.
Reported by Vineet Jain <vkjain@gmail.com> in
https://bugs.gnu.org/36150 . The fix was suggested by Timothy Sample
<samplet@ngyro.com> in the same bug report.
The 'r' command can be used with address zero, effectively prepending
a file to the beginning of the input file, e.g.:
sed '0rA.TXT' B.TXT > C.TXT
is equivalent to:
cat A.TXT B.TXT > C.TXT
With "sed -i", this allows safe in-place prepending of files.
A typical example would be adding a license header to multiple source
files:
sed -i '0rLICENSE' *.c *.h
find -iname '*.cpp' | xargs sed -i '0rLICENSE'
A current cumbersome alternative is:
sed -i -e 'x;${p;x};1rA.TXT' -e '1d' B.TXT
* NEWS: Mention new feature.
* sed/sed.h (struct readcmd): New struct. (struct sed_cmd): Use new
struct instead of a char* for the filename.
* sed/compile.c (compile_program): Expand conditional detecting invalid
usage of "0" address to allow "0r"; Adjust '0r' to '1r' with prepending
(instead of appending).
* sed/execute.c (execute_program): 'r' command: support prepending.
* sed/debug.c (debug_print_function): Use the new 'struct readcmd'.
* testsuite/cmd-0r.sh: New test.
* testsuite/local.mk (TESTS): Add new test.
* doc/sed.texi (Zero Address): New section. (Adding a header to multiple
files): New example section.
* testsuite/bug32271-2.sh: Filter out lines starting with "==".
This avoids unwarranted failures on e.g., windows systems that
would emit this to stderr:
+==16281== error calling PR_SET_PTRACER, vgdb might block
* testsuite/newline-dfa-bug.sh: Likewise.
Reported by Vagelis Prokopiou on Windows subsystem for Linux
(Debian 10) in https://lists.gnu.org/r/sed-devel/2020-01/msg00018.html
and by Bruno Haible for mingw in
https://lists.gnu.org/r/sed-devel/2020-01/msg00005.html
* testsuite/title-case.sh: Correct printf usage not to trigger
unspecified behavior for '\(\)'. Instead, just use sed with its -r
option so those parentheses don't need any backslash at all.
Reported by Bruno Haible in
https://lists.gnu.org/r/sed-devel/2020-01/msg00008.html
Before this change, the two perl-requiring tests would fail
on systems without perl. Now, they are skipped, as intended.
* bootstrap.conf (gnulib_modules): Add perl.
* testsuite/no-perl: New file. From coreutils.
* testsuite/local.mk (EXTRA_DIST): Add it.
(TESTSUITE_PERL): Include testsuite/ prefix.
Run "make update-copyright" and then...
* gnulib: Update to latest with copyright year adjusted.
* tests/init.sh: Sync with gnulib to pick up copyright year.
* bootstrap: Likewise.
Avoid false-positive failure on system with SELinux enabled when SED
is built without SELinux suppport.
Reported by Jeffrey Walton <noloader@gmail.com> in
https://bugs.gnu.org/35997 .
* testsuite/inplace-selinux.sh: Call 'sed --version' to check if sed
was built with SELinux support before continuing with the test.
Under some conditions, \b would mistakenly fail to match. E.g.,
this would mistakenly print "123-x" instead of "123":
echo 123-x|LC_ALL=C sed 's/.\bx//'
* NEWS (Bug fixes): Mention it
* gnulib: Update to latest, for DFA regression fix.
* testsuite/word-delim.sh: New file, to test for the dfa.c regression.
* testsuite/local.mk (T): Add it.
Reported by Jan Palus in
https://lists.gnu.org/r/sed-devel/2018-12/msg00022.html