From 3773798aa6fa752e4210506ebbfba6857863ca75 Mon Sep 17 00:00:00 2001 From: Tom Callaway Date: Sat, 12 Jul 2014 11:34:09 -0400 Subject: [PATCH 1/8] fix license handling --- grep.spec | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/grep.spec b/grep.spec index 5f38f17..c1de47c 100644 --- a/grep.spec +++ b/grep.spec @@ -3,7 +3,7 @@ Summary: Pattern matching utilities Name: grep Version: 2.20 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -76,7 +76,9 @@ fi %files -f %{name}.lang %defattr(-,root,root,-) -%doc ABOUT-NLS AUTHORS THANKS TODO NEWS README ChangeLog COPYING +%doc ABOUT-NLS AUTHORS THANKS TODO NEWS README ChangeLog +%{!?_licensedir:%global license %%doc} +%license COPYING %{_bindir}/* %config(noreplace) %{_sysconfdir}/profile.d/colorgrep.*sh @@ -85,6 +87,9 @@ fi %{_mandir}/*/* %changelog +* Sat Jul 12 2014 Tom Callaway - 2.20-3 +- fix license handling . + * Sat Jun 07 2014 Fedora Release Engineering - 2.20-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild From 3740ef625b6fb2e39c351b6037ca9ad0aefdfe4d Mon Sep 17 00:00:00 2001 From: Peter Robinson Date: Sat, 16 Aug 2014 18:59:10 +0000 Subject: [PATCH 2/8] - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild --- grep.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/grep.spec b/grep.spec index c1de47c..a4798b0 100644 --- a/grep.spec +++ b/grep.spec @@ -3,7 +3,7 @@ Summary: Pattern matching utilities Name: grep Version: 2.20 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -87,6 +87,9 @@ fi %{_mandir}/*/* %changelog +* Sat Aug 16 2014 Fedora Release Engineering - 2.20-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild + * Sat Jul 12 2014 Tom Callaway - 2.20-3 - fix license handling . From 9469ab4bec98694b06fcb3b0d4fcaa6235f64a7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 11 Nov 2014 16:41:57 +0100 Subject: [PATCH 3/8] Fixed invalid UTF-8 byte sequence error in PCRE mode (by pcre-invalid-utf8-fix patch) Resolves: rhbz#1161832 --- grep-2.20-pcre-invalid-utf8-fix.patch | 136 ++++++++++++++++++++++++++ grep.spec | 10 +- 2 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 grep-2.20-pcre-invalid-utf8-fix.patch diff --git a/grep-2.20-pcre-invalid-utf8-fix.patch b/grep-2.20-pcre-invalid-utf8-fix.patch new file mode 100644 index 0000000..5f7530f --- /dev/null +++ b/grep-2.20-pcre-invalid-utf8-fix.patch @@ -0,0 +1,136 @@ +diff --git a/src/pcresearch.c b/src/pcresearch.c +index 820dd00..11df488 100644 +--- a/src/pcresearch.c ++++ b/src/pcresearch.c +@@ -136,34 +136,42 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + #else + /* This array must have at least two elements; everything after that + is just for performance improvement in pcre_exec. */ +- int sub[300]; ++ enum { nsub = 300 }; ++ int sub[nsub]; + +- const char *line_buf, *line_end, *line_next; ++ char const *p = start_ptr ? start_ptr : buf; ++ int options = p == buf || p[-1] == eolbyte ? 0 : PCRE_NOTBOL; ++ char const *line_start = buf; + int e = PCRE_ERROR_NOMATCH; +- ptrdiff_t start_ofs = start_ptr ? start_ptr - buf : 0; ++ char const *line_end; + + /* PCRE can't limit the matching to single lines, therefore we have to + match each line in the buffer separately. */ +- for (line_next = buf; +- e == PCRE_ERROR_NOMATCH && line_next < buf + size; +- start_ofs -= line_next - line_buf) ++ for (; p < buf + size; p = line_start = line_end + 1) + { +- line_buf = line_next; +- line_end = memchr (line_buf, eolbyte, (buf + size) - line_buf); +- if (line_end == NULL) +- line_next = line_end = buf + size; +- else +- line_next = line_end + 1; +- +- if (start_ptr && start_ptr >= line_end) +- continue; ++ line_end = memchr (p, eolbyte, buf + size - p); + +- if (INT_MAX < line_end - line_buf) ++ if (INT_MAX < line_end - p) + error (EXIT_TROUBLE, 0, _("exceeded PCRE's line length limit")); + +- e = pcre_exec (cre, extra, line_buf, line_end - line_buf, +- start_ofs < 0 ? 0 : start_ofs, 0, +- sub, sizeof sub / sizeof *sub); ++ /* Treat encoding-error bytes as data that cannot match. */ ++ for (;;) ++ { ++ e = pcre_exec (cre, extra, p, line_end - p, 0, options, sub, nsub); ++ if (e != PCRE_ERROR_BADUTF8) ++ break; ++ e = pcre_exec (cre, extra, p, sub[0], 0, ++ options | PCRE_NO_UTF8_CHECK | PCRE_NOTEOL, ++ sub, nsub); ++ if (e != PCRE_ERROR_NOMATCH) ++ break; ++ p += sub[0] + 1; ++ options = PCRE_NOTBOL; ++ } ++ ++ if (e != PCRE_ERROR_NOMATCH) ++ break; ++ options = 0; + } + + if (e <= 0) +@@ -180,10 +188,6 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + error (EXIT_TROUBLE, 0, + _("exceeded PCRE's backtracking limit")); + +- case PCRE_ERROR_BADUTF8: +- error (EXIT_TROUBLE, 0, +- _("invalid UTF-8 byte sequence in input")); +- + default: + /* For now, we lump all remaining PCRE failures into this basket. + If anyone cares to provide sample grep usage that can trigger +@@ -197,25 +201,8 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + } + else + { +- /* Narrow down to the line we've found. */ +- char const *beg = line_buf + sub[0]; +- char const *end = line_buf + sub[1]; +- char const *buflim = buf + size; +- char eol = eolbyte; +- if (!start_ptr) +- { +- /* FIXME: The case when '\n' is not found indicates a bug: +- Since grep is line oriented, the match should never contain +- a newline, so there _must_ be a newline following. +- */ +- if (!(end = memchr (end, eol, buflim - end))) +- end = buflim; +- else +- end++; +- while (buf < beg && beg[-1] != eol) +- --beg; +- } +- ++ char const *beg = start_ptr ? p + sub[0] : line_start; ++ char const *end = start_ptr ? p + sub[1] : line_end + 1; + *match_size = end - beg; + return beg - buf; + } +diff --git a/tests/pcre-infloop b/tests/pcre-infloop +index 1b33e72..b92f8e1 100755 +--- a/tests/pcre-infloop ++++ b/tests/pcre-infloop +@@ -28,6 +28,6 @@ printf 'a\201b\r' > in || framework_failure_ + fail=0 + + LC_ALL=en_US.UTF-8 timeout 3 grep -P 'a.?..b' in +-test $? = 2 || fail_ "libpcre's match function appears to infloop" ++test $? = 1 || fail_ "libpcre's match function appears to infloop" + + Exit $fail +diff --git a/tests/pcre-invalid-utf8-input b/tests/pcre-invalid-utf8-input +index 913e8ee..9da4b18 100755 +--- a/tests/pcre-invalid-utf8-input ++++ b/tests/pcre-invalid-utf8-input +@@ -13,9 +13,12 @@ require_en_utf8_locale_ + + fail=0 + +-printf 'j\202\nj\n' > in || framework_failure_ ++printf 'j\202j\nj\nk\202\n' > in || framework_failure_ + + LC_ALL=en_US.UTF-8 grep -P j in +-test $? -eq 2 || fail=1 ++test $? -eq 0 || fail=1 ++ ++LC_ALL=en_US.UTF-8 grep -P 'k$' in ++test $? -eq 1 || fail=1 + + Exit $fail diff --git a/grep.spec b/grep.spec index a4798b0..6870319 100644 --- a/grep.spec +++ b/grep.spec @@ -3,7 +3,7 @@ Summary: Pattern matching utilities Name: grep Version: 2.20 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -14,6 +14,8 @@ Source3: GREP_COLORS Patch0: grep-2.20-man-fix-gs.patch # upstream ticket 39445 Patch1: grep-2.20-help-align.patch +# backported from upstream +Patch2: grep-2.20-pcre-invalid-utf8-fix.patch URL: http://www.gnu.org/software/grep/ Requires(post): /sbin/install-info Requires(preun): /sbin/install-info @@ -34,6 +36,7 @@ GNU grep is needed by many scripts, so it shall be installed on every system. %setup -q %patch0 -p1 -b .man-fix-gs %patch1 -p1 -b .help-align +%patch2 -p1 -b .pcre-invalid-utf8-fix %build %global BUILD_FLAGS $RPM_OPT_FLAGS @@ -87,6 +90,11 @@ fi %{_mandir}/*/* %changelog +* Tue Nov 11 2014 Jaroslav Škarvada - 2.20-5 +- Fixed invalid UTF-8 byte sequence error in PCRE mode + (by pcre-invalid-utf8-fix patch) + Resolves: rhbz#1161832 + * Sat Aug 16 2014 Fedora Release Engineering - 2.20-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild From 57348fea032fc5950a11835346b6d81072462d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Fri, 14 Nov 2014 17:35:02 +0100 Subject: [PATCH 4/8] Backported more PCRE fixes (by pcre-backported-fixes patch) - Dropped pcre-invalid-utf8-fix patch, handled by pcre-backported-fixes patch --- grep-2.20-pcre-backported-fixes.patch | 389 ++++++++++++++++++++++++++ grep-2.20-pcre-invalid-utf8-fix.patch | 136 --------- grep.spec | 10 +- 3 files changed, 396 insertions(+), 139 deletions(-) create mode 100644 grep-2.20-pcre-backported-fixes.patch delete mode 100644 grep-2.20-pcre-invalid-utf8-fix.patch diff --git a/grep-2.20-pcre-backported-fixes.patch b/grep-2.20-pcre-backported-fixes.patch new file mode 100644 index 0000000..4a9dbcd --- /dev/null +++ b/grep-2.20-pcre-backported-fixes.patch @@ -0,0 +1,389 @@ +diff --git a/src/grep.h b/src/grep.h +index 4935872..729c906 100644 +--- a/src/grep.h ++++ b/src/grep.h +@@ -27,4 +27,19 @@ extern int match_words; /* -w */ + extern int match_lines; /* -x */ + extern unsigned char eolbyte; /* -z */ + ++/* An enum textbin describes the file's type, inferred from data read ++ before the first line is selected for output. */ ++enum textbin ++ { ++ /* Binary, as it contains null bytes and the -z option is not in effect, ++ or it contains encoding errors. */ ++ TEXTBIN_BINARY = -1, ++ ++ /* Not known yet. Only text has been seen so far. */ ++ TEXTBIN_UNKNOWN = 0, ++ ++ /* Text. */ ++ TEXTBIN_TEXT = 1 ++ }; ++ + #endif +diff --git a/src/pcresearch.c b/src/pcresearch.c +index 820dd00..9938ffc 100644 +--- a/src/pcresearch.c ++++ b/src/pcresearch.c +@@ -33,13 +33,19 @@ static pcre *cre; + /* Additional information about the pattern. */ + static pcre_extra *extra; + +-# ifdef PCRE_STUDY_JIT_COMPILE +-static pcre_jit_stack *jit_stack; +-# else ++# ifndef PCRE_STUDY_JIT_COMPILE + # define PCRE_STUDY_JIT_COMPILE 0 + # endif + #endif + ++/* Table, indexed by ! (flag & PCRE_NOTBOL), of whether the empty ++ string matches when that flag is used. */ ++static int empty_match[2]; ++ ++/* This must be at least 2; everything after that is for performance ++ in pcre_exec. */ ++enum { NSUB = 300 }; ++ + void + Pcompile (char const *pattern, size_t size) + { +@@ -52,13 +58,17 @@ Pcompile (char const *pattern, size_t size) + char const *ep; + char *re = xnmalloc (4, size + 7); + int flags = (PCRE_MULTILINE +- | (match_icase ? PCRE_CASELESS : 0) +- | (using_utf8 () ? PCRE_UTF8 : 0)); ++ | (match_icase ? PCRE_CASELESS : 0)); + char const *patlim = pattern + size; + char *n = re; + char const *p; + char const *pnul; + ++ if (using_utf8 ()) ++ flags |= PCRE_UTF8; ++ else if (MB_CUR_MAX != 1) ++ error (EXIT_TROUBLE, 0, _("-P supports only unibyte and UTF-8 locales")); ++ + /* FIXME: Remove these restrictions. */ + if (memchr (pattern, '\n', size)) + error (EXIT_TROUBLE, 0, _("the -P option only supports a single pattern")); +@@ -114,14 +124,20 @@ Pcompile (char const *pattern, size_t size) + /* A 32K stack is allocated for the machine code by default, which + can grow to 512K if necessary. Since JIT uses far less memory + than the interpreter, this should be enough in practice. */ +- jit_stack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024); ++ pcre_jit_stack *jit_stack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024); + if (!jit_stack) + error (EXIT_TROUBLE, 0, + _("failed to allocate memory for the PCRE JIT stack")); + pcre_assign_jit_stack (extra, NULL, jit_stack); + } ++ + # endif + free (re); ++ ++ int sub[NSUB]; ++ empty_match[false] = pcre_exec (cre, extra, "", 0, 0, ++ PCRE_NOTBOL, sub, NSUB); ++ empty_match[true] = pcre_exec (cre, extra, "", 0, 0, 0, sub, NSUB); + #endif /* HAVE_LIBPCRE */ + } + +@@ -134,36 +150,110 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + error (EXIT_TROUBLE, 0, _("internal error")); + return -1; + #else +- /* This array must have at least two elements; everything after that +- is just for performance improvement in pcre_exec. */ +- int sub[300]; +- +- const char *line_buf, *line_end, *line_next; ++ int sub[NSUB]; ++ char const *p = start_ptr ? start_ptr : buf; ++ bool bol = p[-1] == eolbyte; ++ char const *line_start = buf; + int e = PCRE_ERROR_NOMATCH; +- ptrdiff_t start_ofs = start_ptr ? start_ptr - buf : 0; ++ char const *line_end; + +- /* PCRE can't limit the matching to single lines, therefore we have to +- match each line in the buffer separately. */ +- for (line_next = buf; +- e == PCRE_ERROR_NOMATCH && line_next < buf + size; +- start_ofs -= line_next - line_buf) ++ /* If the input type is unknown, the caller is still testing the ++ input, which means the current buffer cannot contain encoding ++ errors and a multiline search is typically more efficient. ++ Otherwise, a single-line search is typically faster, so that ++ pcre_exec doesn't waste time validating the entire input ++ buffer. */ ++ bool multiline = TEXTBIN_UNKNOWN; ++ ++ for (; p < buf + size; p = line_start = line_end + 1) + { +- line_buf = line_next; +- line_end = memchr (line_buf, eolbyte, (buf + size) - line_buf); +- if (line_end == NULL) +- line_next = line_end = buf + size; +- else +- line_next = line_end + 1; ++ bool too_big; + +- if (start_ptr && start_ptr >= line_end) +- continue; ++ if (multiline) ++ { ++ size_t pcre_size_max = MIN (INT_MAX, SIZE_MAX - 1); ++ size_t scan_size = MIN (pcre_size_max + 1, buf + size - p); ++ line_end = memrchr (p, eolbyte, scan_size); ++ too_big = ! line_end; ++ } ++ else ++ { ++ line_end = memchr (p, eolbyte, buf + size - p); ++ too_big = INT_MAX < line_end - p; ++ } + +- if (INT_MAX < line_end - line_buf) ++ if (too_big) + error (EXIT_TROUBLE, 0, _("exceeded PCRE's line length limit")); + +- e = pcre_exec (cre, extra, line_buf, line_end - line_buf, +- start_ofs < 0 ? 0 : start_ofs, 0, +- sub, sizeof sub / sizeof *sub); ++ for (;;) ++ { ++ /* Skip past bytes that are easily determined to be encoding ++ errors, treating them as data that cannot match. This is ++ faster than having pcre_exec check them. */ ++ while (mbclen_cache[to_uchar (*p)] == (size_t) -1) ++ { ++ p++; ++ bol = false; ++ } ++ ++ /* Check for an empty match; this is faster than letting ++ pcre_exec do it. */ ++ int search_bytes = line_end - p; ++ if (search_bytes == 0) ++ { ++ sub[0] = sub[1] = 0; ++ e = empty_match[bol]; ++ break; ++ } ++ ++ int options = 0; ++ if (!bol) ++ options |= PCRE_NOTBOL; ++ if (multiline) ++ options |= PCRE_NO_UTF8_CHECK; ++ ++ e = pcre_exec (cre, extra, p, search_bytes, 0, ++ options, sub, NSUB); ++ if (e != PCRE_ERROR_BADUTF8) ++ { ++ if (0 < e && multiline && sub[1] - sub[0] != 0) ++ { ++ char const *nl = memchr (p + sub[0], eolbyte, ++ sub[1] - sub[0]); ++ if (nl) ++ { ++ /* This match crosses a line boundary; reject it. */ ++ p += sub[0]; ++ line_end = nl; ++ continue; ++ } ++ } ++ break; ++ } ++ int valid_bytes = sub[0]; ++ ++ /* Try to match the string before the encoding error. ++ Again, handle the empty-match case specially, for speed. */ ++ if (valid_bytes == 0) ++ { ++ sub[1] = 0; ++ e = empty_match[bol]; ++ } ++ else ++ e = pcre_exec (cre, extra, p, valid_bytes, 0, ++ options | PCRE_NO_UTF8_CHECK | PCRE_NOTEOL, ++ sub, NSUB); ++ if (e != PCRE_ERROR_NOMATCH) ++ break; ++ ++ /* Treat the encoding error as data that cannot match. */ ++ p += valid_bytes + 1; ++ bol = false; ++ } ++ ++ if (e != PCRE_ERROR_NOMATCH) ++ break; ++ bol = true; + } + + if (e <= 0) +@@ -171,7 +261,7 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + switch (e) + { + case PCRE_ERROR_NOMATCH: +- return -1; ++ break; + + case PCRE_ERROR_NOMEMORY: + error (EXIT_TROUBLE, 0, _("memory exhausted")); +@@ -180,10 +270,6 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + error (EXIT_TROUBLE, 0, + _("exceeded PCRE's backtracking limit")); + +- case PCRE_ERROR_BADUTF8: +- error (EXIT_TROUBLE, 0, +- _("invalid UTF-8 byte sequence in input")); +- + default: + /* For now, we lump all remaining PCRE failures into this basket. + If anyone cares to provide sample grep usage that can trigger +@@ -192,30 +278,33 @@ Pexecute (char const *buf, size_t size, size_t *match_size, + error (EXIT_TROUBLE, 0, _("internal PCRE error: %d"), e); + } + +- /* NOTREACHED */ + return -1; + } + else + { +- /* Narrow down to the line we've found. */ +- char const *beg = line_buf + sub[0]; +- char const *end = line_buf + sub[1]; +- char const *buflim = buf + size; +- char eol = eolbyte; +- if (!start_ptr) ++ char const *matchbeg = p + sub[0]; ++ char const *matchend = p + sub[1]; ++ char const *beg; ++ char const *end; ++ if (start_ptr) + { +- /* FIXME: The case when '\n' is not found indicates a bug: +- Since grep is line oriented, the match should never contain +- a newline, so there _must_ be a newline following. +- */ +- if (!(end = memchr (end, eol, buflim - end))) +- end = buflim; +- else +- end++; +- while (buf < beg && beg[-1] != eol) +- --beg; ++ beg = matchbeg; ++ end = matchend; ++ } ++ else if (multiline) ++ { ++ char const *prev_nl = memrchr (line_start - 1, eolbyte, ++ matchbeg - (line_start - 1)); ++ char const *next_nl = memchr (matchend, eolbyte, ++ line_end + 1 - matchend); ++ beg = prev_nl + 1; ++ end = next_nl + 1; ++ } ++ else ++ { ++ beg = line_start; ++ end = line_end + 1; + } +- + *match_size = end - beg; + return beg - buf; + } +diff --git a/src/search.h b/src/search.h +index 14877bc..e671bea 100644 +--- a/src/search.h ++++ b/src/search.h +@@ -45,6 +45,7 @@ extern void kwsinit (kwset_t *); + + extern char *mbtoupper (char const *, size_t *, mb_len_map_t **); + extern void build_mbclen_cache (void); ++extern size_t mbclen_cache[]; + extern ptrdiff_t mb_goback (char const **, char const *, char const *); + extern wint_t mb_prev_wc (char const *, char const *, char const *); + extern wint_t mb_next_wc (char const *, char const *); +diff --git a/src/searchutils.c b/src/searchutils.c +index 5eb9a12..aba9335 100644 +--- a/src/searchutils.c ++++ b/src/searchutils.c +@@ -22,7 +22,7 @@ + + #define NCHAR (UCHAR_MAX + 1) + +-static size_t mbclen_cache[NCHAR]; ++size_t mbclen_cache[NCHAR]; + + void + kwsinit (kwset_t *kwset) +diff --git a/tests/pcre-infloop b/tests/pcre-infloop +index 1b33e72..8054844 100755 +--- a/tests/pcre-infloop ++++ b/tests/pcre-infloop +@@ -18,16 +18,16 @@ + # along with this program. If not, see . + + . "${srcdir=.}/init.sh"; path_prepend_ ../src +-require_pcre_ + require_timeout_ + require_en_utf8_locale_ + require_compiled_in_MB_support ++LC_ALL=en_US.UTF-8 require_pcre_ + + printf 'a\201b\r' > in || framework_failure_ + + fail=0 + + LC_ALL=en_US.UTF-8 timeout 3 grep -P 'a.?..b' in +-test $? = 2 || fail_ "libpcre's match function appears to infloop" ++test $? = 1 || fail_ "libpcre's match function appears to infloop" + + Exit $fail +diff --git a/tests/pcre-invalid-utf8-input b/tests/pcre-invalid-utf8-input +index 913e8ee..abcc7e8 100755 +--- a/tests/pcre-invalid-utf8-input ++++ b/tests/pcre-invalid-utf8-input +@@ -8,14 +8,19 @@ + # notice and this notice are preserved. + + . "${srcdir=.}/init.sh"; path_prepend_ ../src +-require_pcre_ ++require_timeout_ + require_en_utf8_locale_ ++require_compiled_in_MB_support ++LC_ALL=en_US.UTF-8 require_pcre_ + + fail=0 + +-printf 'j\202\nj\n' > in || framework_failure_ ++printf 'j\202j\nj\nk\202\n' > in || framework_failure_ + +-LC_ALL=en_US.UTF-8 grep -P j in +-test $? -eq 2 || fail=1 ++LC_ALL=en_US.UTF-8 timeout 3 grep -P j in ++test $? -eq 0 || fail=1 ++ ++LC_ALL=en_US.UTF-8 timeout 3 grep -P 'k$' in ++test $? -eq 1 || fail=1 + + Exit $fail +diff --git a/tests/pcre-utf8 b/tests/pcre-utf8 +index 41676f4..2dda116 100755 +--- a/tests/pcre-utf8 ++++ b/tests/pcre-utf8 +@@ -8,8 +8,8 @@ + # notice and this notice are preserved. + + . "${srcdir=.}/init.sh"; path_prepend_ ../src +-require_pcre_ + require_en_utf8_locale_ ++LC_ALL=en_US.UTF-8 require_pcre_ + + fail=0 + diff --git a/grep-2.20-pcre-invalid-utf8-fix.patch b/grep-2.20-pcre-invalid-utf8-fix.patch deleted file mode 100644 index 5f7530f..0000000 --- a/grep-2.20-pcre-invalid-utf8-fix.patch +++ /dev/null @@ -1,136 +0,0 @@ -diff --git a/src/pcresearch.c b/src/pcresearch.c -index 820dd00..11df488 100644 ---- a/src/pcresearch.c -+++ b/src/pcresearch.c -@@ -136,34 +136,42 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - #else - /* This array must have at least two elements; everything after that - is just for performance improvement in pcre_exec. */ -- int sub[300]; -+ enum { nsub = 300 }; -+ int sub[nsub]; - -- const char *line_buf, *line_end, *line_next; -+ char const *p = start_ptr ? start_ptr : buf; -+ int options = p == buf || p[-1] == eolbyte ? 0 : PCRE_NOTBOL; -+ char const *line_start = buf; - int e = PCRE_ERROR_NOMATCH; -- ptrdiff_t start_ofs = start_ptr ? start_ptr - buf : 0; -+ char const *line_end; - - /* PCRE can't limit the matching to single lines, therefore we have to - match each line in the buffer separately. */ -- for (line_next = buf; -- e == PCRE_ERROR_NOMATCH && line_next < buf + size; -- start_ofs -= line_next - line_buf) -+ for (; p < buf + size; p = line_start = line_end + 1) - { -- line_buf = line_next; -- line_end = memchr (line_buf, eolbyte, (buf + size) - line_buf); -- if (line_end == NULL) -- line_next = line_end = buf + size; -- else -- line_next = line_end + 1; -- -- if (start_ptr && start_ptr >= line_end) -- continue; -+ line_end = memchr (p, eolbyte, buf + size - p); - -- if (INT_MAX < line_end - line_buf) -+ if (INT_MAX < line_end - p) - error (EXIT_TROUBLE, 0, _("exceeded PCRE's line length limit")); - -- e = pcre_exec (cre, extra, line_buf, line_end - line_buf, -- start_ofs < 0 ? 0 : start_ofs, 0, -- sub, sizeof sub / sizeof *sub); -+ /* Treat encoding-error bytes as data that cannot match. */ -+ for (;;) -+ { -+ e = pcre_exec (cre, extra, p, line_end - p, 0, options, sub, nsub); -+ if (e != PCRE_ERROR_BADUTF8) -+ break; -+ e = pcre_exec (cre, extra, p, sub[0], 0, -+ options | PCRE_NO_UTF8_CHECK | PCRE_NOTEOL, -+ sub, nsub); -+ if (e != PCRE_ERROR_NOMATCH) -+ break; -+ p += sub[0] + 1; -+ options = PCRE_NOTBOL; -+ } -+ -+ if (e != PCRE_ERROR_NOMATCH) -+ break; -+ options = 0; - } - - if (e <= 0) -@@ -180,10 +188,6 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - error (EXIT_TROUBLE, 0, - _("exceeded PCRE's backtracking limit")); - -- case PCRE_ERROR_BADUTF8: -- error (EXIT_TROUBLE, 0, -- _("invalid UTF-8 byte sequence in input")); -- - default: - /* For now, we lump all remaining PCRE failures into this basket. - If anyone cares to provide sample grep usage that can trigger -@@ -197,25 +201,8 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - } - else - { -- /* Narrow down to the line we've found. */ -- char const *beg = line_buf + sub[0]; -- char const *end = line_buf + sub[1]; -- char const *buflim = buf + size; -- char eol = eolbyte; -- if (!start_ptr) -- { -- /* FIXME: The case when '\n' is not found indicates a bug: -- Since grep is line oriented, the match should never contain -- a newline, so there _must_ be a newline following. -- */ -- if (!(end = memchr (end, eol, buflim - end))) -- end = buflim; -- else -- end++; -- while (buf < beg && beg[-1] != eol) -- --beg; -- } -- -+ char const *beg = start_ptr ? p + sub[0] : line_start; -+ char const *end = start_ptr ? p + sub[1] : line_end + 1; - *match_size = end - beg; - return beg - buf; - } -diff --git a/tests/pcre-infloop b/tests/pcre-infloop -index 1b33e72..b92f8e1 100755 ---- a/tests/pcre-infloop -+++ b/tests/pcre-infloop -@@ -28,6 +28,6 @@ printf 'a\201b\r' > in || framework_failure_ - fail=0 - - LC_ALL=en_US.UTF-8 timeout 3 grep -P 'a.?..b' in --test $? = 2 || fail_ "libpcre's match function appears to infloop" -+test $? = 1 || fail_ "libpcre's match function appears to infloop" - - Exit $fail -diff --git a/tests/pcre-invalid-utf8-input b/tests/pcre-invalid-utf8-input -index 913e8ee..9da4b18 100755 ---- a/tests/pcre-invalid-utf8-input -+++ b/tests/pcre-invalid-utf8-input -@@ -13,9 +13,12 @@ require_en_utf8_locale_ - - fail=0 - --printf 'j\202\nj\n' > in || framework_failure_ -+printf 'j\202j\nj\nk\202\n' > in || framework_failure_ - - LC_ALL=en_US.UTF-8 grep -P j in --test $? -eq 2 || fail=1 -+test $? -eq 0 || fail=1 -+ -+LC_ALL=en_US.UTF-8 grep -P 'k$' in -+test $? -eq 1 || fail=1 - - Exit $fail diff --git a/grep.spec b/grep.spec index 6870319..f227ad1 100644 --- a/grep.spec +++ b/grep.spec @@ -3,7 +3,7 @@ Summary: Pattern matching utilities Name: grep Version: 2.20 -Release: 5%{?dist} +Release: 6%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -15,7 +15,7 @@ Patch0: grep-2.20-man-fix-gs.patch # upstream ticket 39445 Patch1: grep-2.20-help-align.patch # backported from upstream -Patch2: grep-2.20-pcre-invalid-utf8-fix.patch +Patch2: grep-2.20-pcre-backported-fixes.patch URL: http://www.gnu.org/software/grep/ Requires(post): /sbin/install-info Requires(preun): /sbin/install-info @@ -36,7 +36,7 @@ GNU grep is needed by many scripts, so it shall be installed on every system. %setup -q %patch0 -p1 -b .man-fix-gs %patch1 -p1 -b .help-align -%patch2 -p1 -b .pcre-invalid-utf8-fix +%patch2 -p1 -b .pcre-backported-fixes %build %global BUILD_FLAGS $RPM_OPT_FLAGS @@ -90,6 +90,10 @@ fi %{_mandir}/*/* %changelog +* Fri Nov 14 2014 Jaroslav Škarvada - 2.20-6 +- Backported more PCRE fixes (by pcre-backported-fixes patch) +- Dropped pcre-invalid-utf8-fix patch, handled by pcre-backported-fixes patch + * Tue Nov 11 2014 Jaroslav Škarvada - 2.20-5 - Fixed invalid UTF-8 byte sequence error in PCRE mode (by pcre-invalid-utf8-fix patch) From 4397c94fae30391a503f9404ed93141e6455a570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 25 Nov 2014 11:16:00 +0100 Subject: [PATCH 5/8] New version Resolves: rhbz#1167657 - De-fuzzified patches - Dropped pcre-backported-fixes patch (not needed) --- grep-2.20-pcre-backported-fixes.patch | 389 ------------------ ...-align.patch => grep-2.21-help-align.patch | 9 +- ...fix-gs.patch => grep-2.21-man-fix-gs.patch | 12 +- grep.spec | 17 +- sources | 2 +- 5 files changed, 22 insertions(+), 407 deletions(-) delete mode 100644 grep-2.20-pcre-backported-fixes.patch rename grep-2.20-help-align.patch => grep-2.21-help-align.patch (92%) rename grep-2.20-man-fix-gs.patch => grep-2.21-man-fix-gs.patch (89%) diff --git a/grep-2.20-pcre-backported-fixes.patch b/grep-2.20-pcre-backported-fixes.patch deleted file mode 100644 index 4a9dbcd..0000000 --- a/grep-2.20-pcre-backported-fixes.patch +++ /dev/null @@ -1,389 +0,0 @@ -diff --git a/src/grep.h b/src/grep.h -index 4935872..729c906 100644 ---- a/src/grep.h -+++ b/src/grep.h -@@ -27,4 +27,19 @@ extern int match_words; /* -w */ - extern int match_lines; /* -x */ - extern unsigned char eolbyte; /* -z */ - -+/* An enum textbin describes the file's type, inferred from data read -+ before the first line is selected for output. */ -+enum textbin -+ { -+ /* Binary, as it contains null bytes and the -z option is not in effect, -+ or it contains encoding errors. */ -+ TEXTBIN_BINARY = -1, -+ -+ /* Not known yet. Only text has been seen so far. */ -+ TEXTBIN_UNKNOWN = 0, -+ -+ /* Text. */ -+ TEXTBIN_TEXT = 1 -+ }; -+ - #endif -diff --git a/src/pcresearch.c b/src/pcresearch.c -index 820dd00..9938ffc 100644 ---- a/src/pcresearch.c -+++ b/src/pcresearch.c -@@ -33,13 +33,19 @@ static pcre *cre; - /* Additional information about the pattern. */ - static pcre_extra *extra; - --# ifdef PCRE_STUDY_JIT_COMPILE --static pcre_jit_stack *jit_stack; --# else -+# ifndef PCRE_STUDY_JIT_COMPILE - # define PCRE_STUDY_JIT_COMPILE 0 - # endif - #endif - -+/* Table, indexed by ! (flag & PCRE_NOTBOL), of whether the empty -+ string matches when that flag is used. */ -+static int empty_match[2]; -+ -+/* This must be at least 2; everything after that is for performance -+ in pcre_exec. */ -+enum { NSUB = 300 }; -+ - void - Pcompile (char const *pattern, size_t size) - { -@@ -52,13 +58,17 @@ Pcompile (char const *pattern, size_t size) - char const *ep; - char *re = xnmalloc (4, size + 7); - int flags = (PCRE_MULTILINE -- | (match_icase ? PCRE_CASELESS : 0) -- | (using_utf8 () ? PCRE_UTF8 : 0)); -+ | (match_icase ? PCRE_CASELESS : 0)); - char const *patlim = pattern + size; - char *n = re; - char const *p; - char const *pnul; - -+ if (using_utf8 ()) -+ flags |= PCRE_UTF8; -+ else if (MB_CUR_MAX != 1) -+ error (EXIT_TROUBLE, 0, _("-P supports only unibyte and UTF-8 locales")); -+ - /* FIXME: Remove these restrictions. */ - if (memchr (pattern, '\n', size)) - error (EXIT_TROUBLE, 0, _("the -P option only supports a single pattern")); -@@ -114,14 +124,20 @@ Pcompile (char const *pattern, size_t size) - /* A 32K stack is allocated for the machine code by default, which - can grow to 512K if necessary. Since JIT uses far less memory - than the interpreter, this should be enough in practice. */ -- jit_stack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024); -+ pcre_jit_stack *jit_stack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024); - if (!jit_stack) - error (EXIT_TROUBLE, 0, - _("failed to allocate memory for the PCRE JIT stack")); - pcre_assign_jit_stack (extra, NULL, jit_stack); - } -+ - # endif - free (re); -+ -+ int sub[NSUB]; -+ empty_match[false] = pcre_exec (cre, extra, "", 0, 0, -+ PCRE_NOTBOL, sub, NSUB); -+ empty_match[true] = pcre_exec (cre, extra, "", 0, 0, 0, sub, NSUB); - #endif /* HAVE_LIBPCRE */ - } - -@@ -134,36 +150,110 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - error (EXIT_TROUBLE, 0, _("internal error")); - return -1; - #else -- /* This array must have at least two elements; everything after that -- is just for performance improvement in pcre_exec. */ -- int sub[300]; -- -- const char *line_buf, *line_end, *line_next; -+ int sub[NSUB]; -+ char const *p = start_ptr ? start_ptr : buf; -+ bool bol = p[-1] == eolbyte; -+ char const *line_start = buf; - int e = PCRE_ERROR_NOMATCH; -- ptrdiff_t start_ofs = start_ptr ? start_ptr - buf : 0; -+ char const *line_end; - -- /* PCRE can't limit the matching to single lines, therefore we have to -- match each line in the buffer separately. */ -- for (line_next = buf; -- e == PCRE_ERROR_NOMATCH && line_next < buf + size; -- start_ofs -= line_next - line_buf) -+ /* If the input type is unknown, the caller is still testing the -+ input, which means the current buffer cannot contain encoding -+ errors and a multiline search is typically more efficient. -+ Otherwise, a single-line search is typically faster, so that -+ pcre_exec doesn't waste time validating the entire input -+ buffer. */ -+ bool multiline = TEXTBIN_UNKNOWN; -+ -+ for (; p < buf + size; p = line_start = line_end + 1) - { -- line_buf = line_next; -- line_end = memchr (line_buf, eolbyte, (buf + size) - line_buf); -- if (line_end == NULL) -- line_next = line_end = buf + size; -- else -- line_next = line_end + 1; -+ bool too_big; - -- if (start_ptr && start_ptr >= line_end) -- continue; -+ if (multiline) -+ { -+ size_t pcre_size_max = MIN (INT_MAX, SIZE_MAX - 1); -+ size_t scan_size = MIN (pcre_size_max + 1, buf + size - p); -+ line_end = memrchr (p, eolbyte, scan_size); -+ too_big = ! line_end; -+ } -+ else -+ { -+ line_end = memchr (p, eolbyte, buf + size - p); -+ too_big = INT_MAX < line_end - p; -+ } - -- if (INT_MAX < line_end - line_buf) -+ if (too_big) - error (EXIT_TROUBLE, 0, _("exceeded PCRE's line length limit")); - -- e = pcre_exec (cre, extra, line_buf, line_end - line_buf, -- start_ofs < 0 ? 0 : start_ofs, 0, -- sub, sizeof sub / sizeof *sub); -+ for (;;) -+ { -+ /* Skip past bytes that are easily determined to be encoding -+ errors, treating them as data that cannot match. This is -+ faster than having pcre_exec check them. */ -+ while (mbclen_cache[to_uchar (*p)] == (size_t) -1) -+ { -+ p++; -+ bol = false; -+ } -+ -+ /* Check for an empty match; this is faster than letting -+ pcre_exec do it. */ -+ int search_bytes = line_end - p; -+ if (search_bytes == 0) -+ { -+ sub[0] = sub[1] = 0; -+ e = empty_match[bol]; -+ break; -+ } -+ -+ int options = 0; -+ if (!bol) -+ options |= PCRE_NOTBOL; -+ if (multiline) -+ options |= PCRE_NO_UTF8_CHECK; -+ -+ e = pcre_exec (cre, extra, p, search_bytes, 0, -+ options, sub, NSUB); -+ if (e != PCRE_ERROR_BADUTF8) -+ { -+ if (0 < e && multiline && sub[1] - sub[0] != 0) -+ { -+ char const *nl = memchr (p + sub[0], eolbyte, -+ sub[1] - sub[0]); -+ if (nl) -+ { -+ /* This match crosses a line boundary; reject it. */ -+ p += sub[0]; -+ line_end = nl; -+ continue; -+ } -+ } -+ break; -+ } -+ int valid_bytes = sub[0]; -+ -+ /* Try to match the string before the encoding error. -+ Again, handle the empty-match case specially, for speed. */ -+ if (valid_bytes == 0) -+ { -+ sub[1] = 0; -+ e = empty_match[bol]; -+ } -+ else -+ e = pcre_exec (cre, extra, p, valid_bytes, 0, -+ options | PCRE_NO_UTF8_CHECK | PCRE_NOTEOL, -+ sub, NSUB); -+ if (e != PCRE_ERROR_NOMATCH) -+ break; -+ -+ /* Treat the encoding error as data that cannot match. */ -+ p += valid_bytes + 1; -+ bol = false; -+ } -+ -+ if (e != PCRE_ERROR_NOMATCH) -+ break; -+ bol = true; - } - - if (e <= 0) -@@ -171,7 +261,7 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - switch (e) - { - case PCRE_ERROR_NOMATCH: -- return -1; -+ break; - - case PCRE_ERROR_NOMEMORY: - error (EXIT_TROUBLE, 0, _("memory exhausted")); -@@ -180,10 +270,6 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - error (EXIT_TROUBLE, 0, - _("exceeded PCRE's backtracking limit")); - -- case PCRE_ERROR_BADUTF8: -- error (EXIT_TROUBLE, 0, -- _("invalid UTF-8 byte sequence in input")); -- - default: - /* For now, we lump all remaining PCRE failures into this basket. - If anyone cares to provide sample grep usage that can trigger -@@ -192,30 +278,33 @@ Pexecute (char const *buf, size_t size, size_t *match_size, - error (EXIT_TROUBLE, 0, _("internal PCRE error: %d"), e); - } - -- /* NOTREACHED */ - return -1; - } - else - { -- /* Narrow down to the line we've found. */ -- char const *beg = line_buf + sub[0]; -- char const *end = line_buf + sub[1]; -- char const *buflim = buf + size; -- char eol = eolbyte; -- if (!start_ptr) -+ char const *matchbeg = p + sub[0]; -+ char const *matchend = p + sub[1]; -+ char const *beg; -+ char const *end; -+ if (start_ptr) - { -- /* FIXME: The case when '\n' is not found indicates a bug: -- Since grep is line oriented, the match should never contain -- a newline, so there _must_ be a newline following. -- */ -- if (!(end = memchr (end, eol, buflim - end))) -- end = buflim; -- else -- end++; -- while (buf < beg && beg[-1] != eol) -- --beg; -+ beg = matchbeg; -+ end = matchend; -+ } -+ else if (multiline) -+ { -+ char const *prev_nl = memrchr (line_start - 1, eolbyte, -+ matchbeg - (line_start - 1)); -+ char const *next_nl = memchr (matchend, eolbyte, -+ line_end + 1 - matchend); -+ beg = prev_nl + 1; -+ end = next_nl + 1; -+ } -+ else -+ { -+ beg = line_start; -+ end = line_end + 1; - } -- - *match_size = end - beg; - return beg - buf; - } -diff --git a/src/search.h b/src/search.h -index 14877bc..e671bea 100644 ---- a/src/search.h -+++ b/src/search.h -@@ -45,6 +45,7 @@ extern void kwsinit (kwset_t *); - - extern char *mbtoupper (char const *, size_t *, mb_len_map_t **); - extern void build_mbclen_cache (void); -+extern size_t mbclen_cache[]; - extern ptrdiff_t mb_goback (char const **, char const *, char const *); - extern wint_t mb_prev_wc (char const *, char const *, char const *); - extern wint_t mb_next_wc (char const *, char const *); -diff --git a/src/searchutils.c b/src/searchutils.c -index 5eb9a12..aba9335 100644 ---- a/src/searchutils.c -+++ b/src/searchutils.c -@@ -22,7 +22,7 @@ - - #define NCHAR (UCHAR_MAX + 1) - --static size_t mbclen_cache[NCHAR]; -+size_t mbclen_cache[NCHAR]; - - void - kwsinit (kwset_t *kwset) -diff --git a/tests/pcre-infloop b/tests/pcre-infloop -index 1b33e72..8054844 100755 ---- a/tests/pcre-infloop -+++ b/tests/pcre-infloop -@@ -18,16 +18,16 @@ - # along with this program. If not, see . - - . "${srcdir=.}/init.sh"; path_prepend_ ../src --require_pcre_ - require_timeout_ - require_en_utf8_locale_ - require_compiled_in_MB_support -+LC_ALL=en_US.UTF-8 require_pcre_ - - printf 'a\201b\r' > in || framework_failure_ - - fail=0 - - LC_ALL=en_US.UTF-8 timeout 3 grep -P 'a.?..b' in --test $? = 2 || fail_ "libpcre's match function appears to infloop" -+test $? = 1 || fail_ "libpcre's match function appears to infloop" - - Exit $fail -diff --git a/tests/pcre-invalid-utf8-input b/tests/pcre-invalid-utf8-input -index 913e8ee..abcc7e8 100755 ---- a/tests/pcre-invalid-utf8-input -+++ b/tests/pcre-invalid-utf8-input -@@ -8,14 +8,19 @@ - # notice and this notice are preserved. - - . "${srcdir=.}/init.sh"; path_prepend_ ../src --require_pcre_ -+require_timeout_ - require_en_utf8_locale_ -+require_compiled_in_MB_support -+LC_ALL=en_US.UTF-8 require_pcre_ - - fail=0 - --printf 'j\202\nj\n' > in || framework_failure_ -+printf 'j\202j\nj\nk\202\n' > in || framework_failure_ - --LC_ALL=en_US.UTF-8 grep -P j in --test $? -eq 2 || fail=1 -+LC_ALL=en_US.UTF-8 timeout 3 grep -P j in -+test $? -eq 0 || fail=1 -+ -+LC_ALL=en_US.UTF-8 timeout 3 grep -P 'k$' in -+test $? -eq 1 || fail=1 - - Exit $fail -diff --git a/tests/pcre-utf8 b/tests/pcre-utf8 -index 41676f4..2dda116 100755 ---- a/tests/pcre-utf8 -+++ b/tests/pcre-utf8 -@@ -8,8 +8,8 @@ - # notice and this notice are preserved. - - . "${srcdir=.}/init.sh"; path_prepend_ ../src --require_pcre_ - require_en_utf8_locale_ -+LC_ALL=en_US.UTF-8 require_pcre_ - - fail=0 - diff --git a/grep-2.20-help-align.patch b/grep-2.21-help-align.patch similarity index 92% rename from grep-2.20-help-align.patch rename to grep-2.21-help-align.patch index cef6311..56f24d6 100644 --- a/grep-2.20-help-align.patch +++ b/grep-2.21-help-align.patch @@ -1,8 +1,8 @@ diff --git a/src/grep.c b/src/grep.c -index 0fcc272..2208a4e 100644 +index e3461a7..50a9868 100644 --- a/src/grep.c +++ b/src/grep.c -@@ -1579,16 +1579,19 @@ Output control:\n\ +@@ -1757,17 +1757,20 @@ Output control:\n\ -D, --devices=ACTION how to handle devices, FIFOs and sockets;\n\ ACTION is 'read' or 'skip'\n\ -r, --recursive like --directories=recurse\n\ @@ -12,11 +12,12 @@ index 0fcc272..2208a4e 100644 ")); printf (_("\ - --include=FILE_PATTERN search only files that match FILE_PATTERN\n\ -- --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN\n\ +- --exclude=FILE_PATTERN skip files and directories matching\ + --include=FILE_PATTERN\n\ + search only files that match FILE_PATTERN\n\ + --exclude=FILE_PATTERN\n\ -+ skip files and directories matching FILE_PATTERN\n\ ++ skip files and directories matching\ + FILE_PATTERN\n\ --exclude-from=FILE skip files matching any file pattern from FILE\n\ - --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n\ + --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n\ diff --git a/grep-2.20-man-fix-gs.patch b/grep-2.21-man-fix-gs.patch similarity index 89% rename from grep-2.20-man-fix-gs.patch rename to grep-2.21-man-fix-gs.patch index db3dd24..65f41bf 100644 --- a/grep-2.20-man-fix-gs.patch +++ b/grep-2.21-man-fix-gs.patch @@ -1,8 +1,8 @@ diff --git a/doc/grep.in.1 b/doc/grep.in.1 -index 58a6c0e..3e6a8cf 100644 +index b6362ee..5a1e3ea 100644 --- a/doc/grep.in.1 +++ b/doc/grep.in.1 -@@ -377,7 +377,7 @@ Print +@@ -314,7 +314,7 @@ Print .I NUM lines of trailing context after matching lines. Places a line containing a group separator @@ -11,7 +11,7 @@ index 58a6c0e..3e6a8cf 100644 between contiguous groups of matches. With the .B \-o -@@ -390,7 +390,7 @@ Print +@@ -327,7 +327,7 @@ Print .I NUM lines of leading context before matching lines. Places a line containing a group separator @@ -20,7 +20,7 @@ index 58a6c0e..3e6a8cf 100644 between contiguous groups of matches. With the .B \-o -@@ -403,13 +403,24 @@ Print +@@ -340,13 +340,24 @@ Print .I NUM lines of output context. Places a line containing a group separator @@ -47,10 +47,10 @@ index 58a6c0e..3e6a8cf 100644 .TP .BR \-a ", " \-\^\-text diff --git a/src/grep.c b/src/grep.c -index 7c0f8a8..0fcc272 100644 +index 8dbf86e..e3461a7 100644 --- a/src/grep.c +++ b/src/grep.c -@@ -1602,6 +1602,8 @@ Context control:\n\ +@@ -1781,6 +1781,8 @@ Context control:\n\ ")); printf (_("\ -NUM same as --context=NUM\n\ diff --git a/grep.spec b/grep.spec index f227ad1..441dae3 100644 --- a/grep.spec +++ b/grep.spec @@ -2,8 +2,8 @@ Summary: Pattern matching utilities Name: grep -Version: 2.20 -Release: 6%{?dist} +Version: 2.21 +Release: 1%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -11,11 +11,9 @@ Source1: colorgrep.sh Source2: colorgrep.csh Source3: GREP_COLORS # upstream ticket 39444 -Patch0: grep-2.20-man-fix-gs.patch +Patch0: grep-2.21-man-fix-gs.patch # upstream ticket 39445 -Patch1: grep-2.20-help-align.patch -# backported from upstream -Patch2: grep-2.20-pcre-backported-fixes.patch +Patch1: grep-2.21-help-align.patch URL: http://www.gnu.org/software/grep/ Requires(post): /sbin/install-info Requires(preun): /sbin/install-info @@ -36,7 +34,6 @@ GNU grep is needed by many scripts, so it shall be installed on every system. %setup -q %patch0 -p1 -b .man-fix-gs %patch1 -p1 -b .help-align -%patch2 -p1 -b .pcre-backported-fixes %build %global BUILD_FLAGS $RPM_OPT_FLAGS @@ -90,6 +87,12 @@ fi %{_mandir}/*/* %changelog +* Tue Nov 25 2014 Jaroslav Škarvada - 2.21-1 +- New version + Resolves: rhbz#1167657 +- De-fuzzified patches +- Dropped pcre-backported-fixes patch (not needed) + * Fri Nov 14 2014 Jaroslav Škarvada - 2.20-6 - Backported more PCRE fixes (by pcre-backported-fixes patch) - Dropped pcre-invalid-utf8-fix patch, handled by pcre-backported-fixes patch diff --git a/sources b/sources index fe1f529..d9d5863 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -2cbea44a4f1548aee20b9ff2d3076908 grep-2.20.tar.xz +43c48064d6409862b8a850db83c8038a grep-2.21.tar.xz From 9ce00030a5baad778f208ccf9ea92f58f101508f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 20 Jan 2015 15:30:25 +0100 Subject: [PATCH 6/8] Fixed buffer overrun for grep -F Resolves: rhbz#1183653 --- grep-2.21-buf-overrun-fix.patch | 146 ++++++++++++++++++++++++++++++++ grep.spec | 11 ++- 2 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 grep-2.21-buf-overrun-fix.patch diff --git a/grep-2.21-buf-overrun-fix.patch b/grep-2.21-buf-overrun-fix.patch new file mode 100644 index 0000000..661a3ff --- /dev/null +++ b/grep-2.21-buf-overrun-fix.patch @@ -0,0 +1,146 @@ +From 83a95bd8c8561875b948cadd417c653dbe7ef2e2 Mon Sep 17 00:00:00 2001 +From: Yuliy Pisetsky +Date: Thu, 01 Jan 2015 23:36:55 +0000 +Subject: grep -F: fix a heap buffer (read) overrun + +grep's read buffer is often filled to its full size, except when +reading the final buffer of a file. In that case, the number of +bytes read may be far less than the size of the buffer. However, for +certain unusual pattern/text combinations, grep -F would mistakenly +examine bytes in that uninitialized region of memory when searching +for a match. With carefully chosen inputs, one can cause grep -F to +read beyond the end of that buffer altogether. This problem arose via +commit v2.18-90-g73893ff with the introduction of a more efficient +heuristic using what is now the memchr_kwset function. The use of +that function in bmexec_trans could leave TP much larger than EP, +and the subsequent call to bm_delta2_search would mistakenly access +beyond end of the main input read buffer. + +* src/kwset.c (bmexec_trans): When TP reaches or exceeds EP, +do not call bm_delta2_search. +* tests/kwset-abuse: New file. +* tests/Makefile.am (TESTS): Add it. +* THANKS.in: Update. +* NEWS (Bug fixes): Mention it. + +Prior to this patch, this command would trigger a UMR: + + printf %0360db 0 | valgrind src/grep -F $(printf %019dXb 0) + + Use of uninitialised value of size 8 + at 0x4142BE: bmexec_trans (kwset.c:657) + by 0x4143CA: bmexec (kwset.c:678) + by 0x414973: kwsexec (kwset.c:848) + by 0x414DC4: Fexecute (kwsearch.c:128) + by 0x404E2E: grepbuf (grep.c:1238) + by 0x4054BF: grep (grep.c:1417) + by 0x405CEB: grepdesc (grep.c:1645) + by 0x405EC1: grep_command_line_arg (grep.c:1692) + by 0x4077D4: main (grep.c:2570) + +See the accompanying test for how to trigger the heap buffer overrun. + +Thanks to Nima Aghdaii for testing and finding numerous +ways to break early iterations of this patch. +--- +--- a/THANKS.in ++++ b/THANKS.in +@@ -62,6 +62,7 @@ Michael Aichlmayr mikla@nx.com + Miles Bader miles@ccs.mt.nec.co.jp + Mirraz Mirraz mirraz1@rambler.ru + Nelson H. F. Beebe beebe@math.utah.edu ++Nima Aghdaii naghdaii@fb.com + Olaf Kirch okir@ns.lst.de + Paul Kimoto kimoto@spacenet.tn.cornell.edu + Péter Radics mitchnull@gmail.com +diff --git a/src/kwset.c b/src/kwset.c +index 6d21893..998dbfe 100644 +--- a/src/kwset.c ++++ b/src/kwset.c +@@ -643,6 +643,8 @@ bmexec_trans (kwset_t kwset, char const *text, size_t size) + if (! tp) + return -1; + tp++; ++ if (ep <= tp) ++ break; + } + } + } +diff --git a/tests/Makefile.am b/tests/Makefile.am +index 217a731..2f69835 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -72,6 +72,7 @@ TESTS = \ + inconsistent-range \ + invalid-multibyte-infloop \ + khadafy \ ++ kwset-abuse \ + long-line-vs-2GiB-read \ + match-lines \ + max-count-overread \ +diff --git a/tests/Makefile.in b/tests/Makefile.in +index e40a070..9ecafe7 100644 +--- a/tests/Makefile.in ++++ b/tests/Makefile.in +@@ -1376,6 +1376,7 @@ TESTS = \ + inconsistent-range \ + invalid-multibyte-infloop \ + khadafy \ ++ kwset-abuse \ + long-line-vs-2GiB-read \ + match-lines \ + max-count-overread \ +@@ -2030,6 +2031,13 @@ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ ++ "$$tst" $(AM_TESTS_FD_REDIRECT) ++kwset-abuse.log: kwset-abuse ++ @p='kwset-abuse'; \ ++ b='kwset-abuse'; \ ++ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ ++ --log-file $$b.log --trs-file $$b.trs \ ++ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) + long-line-vs-2GiB-read.log: long-line-vs-2GiB-read + @p='long-line-vs-2GiB-read'; \ +diff --git a/tests/kwset-abuse b/tests/kwset-abuse +new file mode 100755 +index 0000000..6d8ec0c +--- a/dev/null ++++ b/tests/kwset-abuse +@@ -0,0 +1,32 @@ ++#! /bin/sh ++# Evoke a segfault in a hard-to-reach code path of kwset.c. ++# This bug affected grep versions 2.19 through 2.21. ++# ++# Copyright (C) 2015 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 . ++ ++. "${srcdir=.}/init.sh"; path_prepend_ ../src ++ ++fail=0 ++ ++# This test case chooses a haystack of size 260,000, since prodding ++# with gdb showed a reallocation slightly larger than that in fillbuf. ++# To reach the buggy code, the needle must have length < 1/11 that of ++# the haystack, and 10,000 is a nice round number that fits the bill. ++printf '%0260000dXy\n' 0 | grep -F $(printf %010000dy 0) ++ ++test $? = 1 || fail=1 ++ ++Exit $fail +-- +cgit v0.9.0.2 diff --git a/grep.spec b/grep.spec index 441dae3..26cad67 100644 --- a/grep.spec +++ b/grep.spec @@ -3,7 +3,7 @@ Summary: Pattern matching utilities Name: grep Version: 2.21 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -14,6 +14,8 @@ Source3: GREP_COLORS Patch0: grep-2.21-man-fix-gs.patch # upstream ticket 39445 Patch1: grep-2.21-help-align.patch +# fix buffer overrun for grep -F, rhbz#1183653 +Patch2: grep-2.21-buf-overrun-fix.patch URL: http://www.gnu.org/software/grep/ Requires(post): /sbin/install-info Requires(preun): /sbin/install-info @@ -34,6 +36,9 @@ GNU grep is needed by many scripts, so it shall be installed on every system. %setup -q %patch0 -p1 -b .man-fix-gs %patch1 -p1 -b .help-align +%patch2 -p1 -b .buf-overrun-fix + +chmod 755 tests/kwset-abuse %build %global BUILD_FLAGS $RPM_OPT_FLAGS @@ -87,6 +92,10 @@ fi %{_mandir}/*/* %changelog +* Tue Jan 20 2015 Jaroslav Škarvada - 2.21-2 +- Fixed buffer overrun for grep -F + Resolves: rhbz#1183653 + * Tue Nov 25 2014 Jaroslav Škarvada - 2.21-1 - New version Resolves: rhbz#1167657 From da0d7afa9eee3bb7bfecedd506cfe04039e5f19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 7 Apr 2015 11:16:45 +0200 Subject: [PATCH 7/8] Documented change in behaviour of recurse option Resolves: rhbz#1178305 --- grep-2.21-recurse-behaviour-change-doc.patch | 24 ++++++++++++++++++++ grep.spec | 10 +++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 grep-2.21-recurse-behaviour-change-doc.patch diff --git a/grep-2.21-recurse-behaviour-change-doc.patch b/grep-2.21-recurse-behaviour-change-doc.patch new file mode 100644 index 0000000..52a3550 --- /dev/null +++ b/grep-2.21-recurse-behaviour-change-doc.patch @@ -0,0 +1,24 @@ +diff --git a/doc/grep.in.1 b/doc/grep.in.1 +index 5a1e3ea..3f633ea 100644 +--- a/doc/grep.in.1 ++++ b/doc/grep.in.1 +@@ -478,6 +478,7 @@ Search only files whose base name matches + .BR \-r ", " \-\^\-recursive + Read all files under each directory, recursively, + following symbolic links only if they are on the command line. ++Note that if no file operand is given, grep searches the working directory. + This is equivalent to the + .B "\-d recurse" + option. +diff --git a/doc/grep.texi b/doc/grep.texi +index da9a1be..63016bd 100644 +--- a/doc/grep.texi ++++ b/doc/grep.texi +@@ -698,6 +698,7 @@ For each directory operand, + read and process all files in that directory, recursively. + Follow symbolic links on the command line, but skip symlinks + that are encountered recursively. ++Note that if no file operand is given, grep searches the working directory. + This is the same as the @samp{--directories=recurse} option. + + @item -R diff --git a/grep.spec b/grep.spec index 26cad67..af8c0b8 100644 --- a/grep.spec +++ b/grep.spec @@ -3,7 +3,7 @@ Summary: Pattern matching utilities Name: grep Version: 2.21 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv3+ Group: Applications/Text Source: ftp://ftp.gnu.org/pub/gnu/grep/grep-%{version}.tar.xz @@ -16,6 +16,9 @@ Patch0: grep-2.21-man-fix-gs.patch Patch1: grep-2.21-help-align.patch # fix buffer overrun for grep -F, rhbz#1183653 Patch2: grep-2.21-buf-overrun-fix.patch +# backported from upstream +# http://git.savannah.gnu.org/cgit/grep.git/commit/?id=c8b9364d5900a40809827aee6cc53705073278f6 +Patch3: grep-2.21-recurse-behaviour-change-doc.patch URL: http://www.gnu.org/software/grep/ Requires(post): /sbin/install-info Requires(preun): /sbin/install-info @@ -37,6 +40,7 @@ GNU grep is needed by many scripts, so it shall be installed on every system. %patch0 -p1 -b .man-fix-gs %patch1 -p1 -b .help-align %patch2 -p1 -b .buf-overrun-fix +%patch3 -p1 -b .recurse-behaviour-change-doc chmod 755 tests/kwset-abuse @@ -92,6 +96,10 @@ fi %{_mandir}/*/* %changelog +* Tue Apr 7 2015 Jaroslav Škarvada - 2.21-3 +- Documented change in behaviour of recurse option + Resolves: rhbz#1178305 + * Tue Jan 20 2015 Jaroslav Škarvada - 2.21-2 - Fixed buffer overrun for grep -F Resolves: rhbz#1183653 From 401e77224387663f2dddfa6bd49bedc01476f348 Mon Sep 17 00:00:00 2001 From: Jaromir Capik Date: Thu, 11 Jun 2015 15:51:11 +0200 Subject: [PATCH 8/8] Adding STAGE1 bootstrap recipe --- STAGE1-grep | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 STAGE1-grep diff --git a/STAGE1-grep b/STAGE1-grep new file mode 100644 index 0000000..f80f9ca --- /dev/null +++ b/STAGE1-grep @@ -0,0 +1,7 @@ +srpm $1 +mcd $BUILDDIR/$1 +$SRC/${1}-*/configure $TCONFIGARGS +notparallel +test -d tools/gnulib/lib && make $J V=1 -C tools/gnulib/lib +make $J V=1 +make $J install DESTDIR=${ROOTFS}