diff --git a/backport-grep-avoid-regression-with-mN-and-any-of-q-l-L.patch b/backport-grep-avoid-regression-with-mN-and-any-of-q-l-L.patch new file mode 100644 index 0000000000000000000000000000000000000000..a09df4e62d6a869f8446329490126fbd6e7188ad --- /dev/null +++ b/backport-grep-avoid-regression-with-mN-and-any-of-q-l-L.patch @@ -0,0 +1,60 @@ +From 52418599b30c6a42358599b65e2cbb7da2926b8e Mon Sep 17 00:00:00 2001 +From: Jim Meyering +Date: Mon, 7 Apr 2025 22:21:16 -0700 +Subject: [PATCH] grep: avoid regression with -mN and any of -q, -l, -L + +* src/grep.c (grepbuf): Handle this case: echo x|grep -l -m1 . +making it print only the file name, and not the matched line. +(main): Set out_quiet also when exit_on_match (-q) is set, so +"echo x|grep -q -m1 ." no longer prints the matched line. +* tests/max-count-overread: Add those tests, from +https://bugs.gnu.org/68989#21 +--- + src/grep.c | 4 +++- + tests/max-count-overread | 10 ++++++++++ + 2 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/src/grep.c b/src/grep.c +index 192f9d1..f657607 100644 +--- a/src/grep.c ++++ b/src/grep.c +@@ -1487,6 +1487,8 @@ grepbuf (char *beg, char const *lim) + break; + if (!out_invert || p < b) + { ++ if (list_files != LISTFILES_NONE) ++ return 1; + char *prbeg = out_invert ? p : b; + char *prend = out_invert ? b : endp; + prtext (prbeg, prend); +@@ -2899,7 +2901,7 @@ main (int argc, char **argv) + if (max_count == INTMAX_MAX) + done_on_match = true; + } +- out_quiet = count_matches | done_on_match; ++ out_quiet = count_matches | done_on_match | exit_on_match; + + if (out_after < 0) + out_after = default_context; +diff --git a/tests/max-count-overread b/tests/max-count-overread +index f829cc5..e15ea77 100755 +--- a/tests/max-count-overread ++++ b/tests/max-count-overread +@@ -18,4 +18,14 @@ printf 'x\nx\nx\n' >in || framework_failure + (grep -m2 x >/dev/null && head -n1) out || fail=1 + compare exp out || fail=1 + ++# The following two tests would fail before v3.11-70 ++echo x > in || framework_failure_ ++echo in > exp || framework_failure_ ++grep -l -m1 . in > out || fail=1 ++compare exp out || fail=1 ++ ++# Ensure that this prints nothing and exits successfully. ++grep -q -m1 . in > out || fail=1 ++compare /dev/null out || fail=1 ++ + Exit $fail +-- +2.43.0 + diff --git a/grep.spec b/grep.spec index 59f98eb5e26ee74c520a1404df2b1001aa8e41e4..ac0305ee75d973dfb620f0d1e5b978c945d5b4a8 100644 --- a/grep.spec +++ b/grep.spec @@ -1,6 +1,6 @@ Name: grep Version: 3.11 -Release: 4 +Release: 5 Summary: A string search utility License: GPLv3+ URL: https://www.gnu.org/software/grep @@ -12,6 +12,7 @@ Source3: grepconf.sh Patch0001: fix-grep-m2-pattern.patch Patch0002: backport-Fix-troff-typos-found-by-mandoc-and-groff.patch Patch0003: backport-Fix-recognition-of-cs_CZ.UTF-8-locale-on-FreeBSD.patch +Patch0004: backport-grep-avoid-regression-with-mN-and-any-of-q-l-L.patch BuildRequires: gcc pcre2-devel texinfo gettext automake Provides: /bin/egrep /bin/fgrep /bin/grep bundled(gnulib) @@ -52,6 +53,9 @@ install -Dpm 755 %{SOURCE3} $RPM_BUILD_ROOT%{_libexecdir}/grepconf.sh %{_mandir}/man1/*grep.1* %changelog +* Wed Jul 23 2025 yixiangzhike - 3.11-5 +- backport upstream patch to avoid regression with -mN and any of -q,-l,-L + * Mon Aug 26 2024 guojunding - 3.11-4 - fix troff typos - fix recognition of cs_CZ.UTF-8 locale on FreeBSD