sed: don't segfault for "sed -f<(echo ':label') --debug"
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
This commit is contained in:
1 parent
5eadb1976b
commit
a6aebe155c
5 files changed
+42
-6
No files matched your search
@@ -4,13 +4,16 @@ GNU sed NEWS -*- outline -*-
|
||||
|
||||
** Bug fixes
|
||||
|
||||
sed --debug no longer crashes when a label (":") command is compiled
|
||||
before the --debug option is processed, e.g., sed -f<(...) --debug.
|
||||
[bug introduced in sed 4.7 with --debug]
|
||||
|
||||
sed no longer rejects the documented GNU extension 'a**' (equivalent
|
||||
to 'a*') in Basic Regular Expression (BRE) mode. Previously, this
|
||||
worked only with -E (ERE mode), even though grep has always accepted
|
||||
it in BRE mode.
|
||||
[bug present since "the beginning"]
|
||||
|
||||
|
||||
sed no longer rejects "\c[" in regular expressions
|
||||
[bug present since the beginning]
|
||||
|
||||
|
||||
+1
-4
@@ -362,10 +362,7 @@ next_cmd_entry (struct vector *v)
|
||||
v->v = xpalloc (v->v, &v->v_allocated, 1, -1, sizeof *v->v);
|
||||
|
||||
cmd = v->v + v->v_length;
|
||||
cmd->a1 = NULL;
|
||||
cmd->a2 = NULL;
|
||||
cmd->range_state = RANGE_INACTIVE;
|
||||
cmd->addr_bang = false;
|
||||
memset (cmd, 0, sizeof *cmd);
|
||||
cmd->cmd = '\0'; /* something invalid, to catch bugs early */
|
||||
|
||||
return cmd;
|
||||
|
||||
+2
-1
@@ -276,7 +276,8 @@ debug_print_function (const struct vector *program, const struct sed_cmd *sc)
|
||||
break;
|
||||
|
||||
case ':':
|
||||
printf ("%s", sc->x.label_name);
|
||||
if (sc->x.label_name)
|
||||
printf ("%s", sc->x.label_name);
|
||||
break;
|
||||
|
||||
case '{':
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# Ensure --debug doesn't crash with labels compiled before --debug is set
|
||||
|
||||
# Copyright (C) 2026 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
. "${srcdir=.}/testsuite/init.sh"; path_prepend_ ./sed
|
||||
print_ver_ sed
|
||||
|
||||
# When --debug appears after -f, the label command is compiled
|
||||
# with debug=false, so label_name is not set. This must not crash.
|
||||
printf ':label\n' > prog || framework_failure_
|
||||
|
||||
sed -f prog --debug < /dev/null > out 2>&1 || fail=1
|
||||
|
||||
# The label name may be absent (compiled without debug), but no crash.
|
||||
grep '^SED PROGRAM:' out > /dev/null || fail=1
|
||||
|
||||
# When --debug appears before -f, the label name should be printed.
|
||||
sed --debug -f prog < /dev/null > out2 2>&1 || fail=1
|
||||
grep ':label' out2 > /dev/null || fail=1
|
||||
|
||||
Exit $fail
|
||||
@@ -44,6 +44,7 @@ LOG_COMPILER = false
|
||||
T = \
|
||||
testsuite/misc.pl \
|
||||
testsuite/bre-star-star.sh \
|
||||
testsuite/debug-label.sh \
|
||||
testsuite/bug80573.sh \
|
||||
testsuite/bug32082.sh \
|
||||
testsuite/bug32271-1.sh \
|
||||
|
||||
Reference in new issue
Block a user