From b30b7bcd0d4481628d8dbe6805be2a2ae5bab080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E6=98=A5=E8=BE=89?= Date: Mon, 3 Apr 2023 10:47:36 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=90=88=E7=A4=BE=E5=8C=BA=E8=A1=A5?= =?UTF-8?q?=E4=B8=81=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E9=9C=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 任春辉 --- ...p-fix-regex-compilation-memory-leaks.patch | 61 +++++++++++++++++++ grep.spec | 4 ++ 2 files changed, 65 insertions(+) create mode 100644 backport-grep-fix-regex-compilation-memory-leaks.patch diff --git a/backport-grep-fix-regex-compilation-memory-leaks.patch b/backport-grep-fix-regex-compilation-memory-leaks.patch new file mode 100644 index 0000000..8b306ed --- /dev/null +++ b/backport-grep-fix-regex-compilation-memory-leaks.patch @@ -0,0 +1,61 @@ +ec8c91e9d6ed3fc76f9f145dec8a456ce623a Mon Sep 17 00:00:00 2001 +From: Paul Eggert +Date: Fri, 24 Jun 2022 17:53:34 -0500 +Subject: grep: fix regex compilation memory leaks + +Problem reported by Jim Meyering in: +https://lists.gnu.org/r/grep-devel/2022-06/msg00012.html +* src/dfasearch.c (regex_compile): Fix memory leaks when SYNTAX_ONLY. +--- + src/dfasearch.c | 24 ++++++++++++++++-------- + 1 file changed, 16 insertions(+), 8 deletions(-) + +diff --git a/src/dfasearch.c b/src/dfasearch.c +index 8d832f0..2720b3a 100644 +--- a/src/dfasearch.c ++++ b/src/dfasearch.c +@@ -148,24 +148,32 @@ regex_compile (struct dfa_comp *dc, char const *p, idx_t len, + idx_t pcount, idx_t lineno, reg_syntax_t syntax_bits, + bool syntax_only) + { +- struct re_pattern_buffer pat0; +- struct re_pattern_buffer *pat = syntax_only ? &pat0 : &dc->patterns[pcount]; +- pat->buffer = NULL; +- pat->allocated = 0; ++ struct re_pattern_buffer pat; ++ pat.buffer = NULL; ++ pat.allocated = 0; + + /* Do not use a fastmap with -i, to work around glibc Bug#20381. */ + verify (UCHAR_MAX < IDX_MAX); + idx_t uchar_max = UCHAR_MAX; +- pat->fastmap = (syntax_only | match_icase) ? NULL : ximalloc (uchar_max + 1); ++ pat.fastmap = syntax_only | match_icase ? NULL : ximalloc (uchar_max + 1); + +- pat->translate = NULL; ++ pat.translate = NULL; + + if (syntax_only) + re_set_syntax (syntax_bits | RE_NO_SUB); + else + re_set_syntax (syntax_bits); + +- char const *err = re_compile_pattern (p, len, pat); ++ char const *err = re_compile_pattern (p, len, &pat); + if (!err) +- return true; ++ { ++ if (syntax_only) ++ regfree (&pat); ++ else ++ dc->patterns[pcount] = pat; ++ ++ return true; ++ } ++ ++ free (pat.fastmap); + + /* Emit a filename:lineno: prefix for patterns taken from files. */ + idx_t pat_lineno; +-- +cgit v1.1 \ No newline at end of file diff --git a/grep.spec b/grep.spec index 0f07167..40ffc33 100644 --- a/grep.spec +++ b/grep.spec @@ -12,6 +12,7 @@ Source3: grepconf.sh Patch1: backport-grep-avoid-sticky-problem-with-f-f.patch Patch2: backport-grep-s-does-not-suppress-binary-file-matches.patch Patch3: backport-grep-bug-backref-in-last-of-multiple-patter.patch +Patch4: backport-grep-fix-regex-compilation-memory-leaks.patch BuildRequires: gcc pcre-devel >= 3.9-10 texinfo gettext libsigsegv-devel automake Provides: /bin/egrep /bin/fgrep /bin/grep bundled(gnulib) @@ -56,6 +57,9 @@ make check %changelog +* Mon Apr 3 2023 renchunhui - 3.7-6 +- backport patch from upstream + * Mon Dec 26 2022 gaoruoshu - 3.7-5 - backport patch from upstream -- Gitee