[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] fix hang in grep -F for empty string search
From: |
Jim Meyering |
Subject: |
Re: [PATCH] fix hang in grep -F for empty string search |
Date: |
Wed, 31 Mar 2010 11:45:08 +0200 |
Paolo Bonzini wrote:
...
> Subject: [PATCH 3/5] grep: fix grep -F against empty string
>
> * src/searchutils.c (is_mb_middle): Do not return true for empty matches
> when p == buf.
> ---
> NEWS | 3 +++
> src/searchutils.c | 7 ++++++-
> 2 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index e822ea1..eb94184 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -4,6 +4,9 @@ GNU grep NEWS -*- outline
> -*-
>
> ** Bug fixes
>
> + Searching with grep -F for an empty string in a multibyte locale
> + would hang grep. [bug introduced in 2.6.2]
> +
> PCRE support is once again detected on systems with <pcre/pcre.h>
> [bug introduced in 2.6.2]
>
> diff --git a/src/searchutils.c b/src/searchutils.c
> index 8c34e31..b04f36f 100644
> --- a/src/searchutils.c
> +++ b/src/searchutils.c
> @@ -142,6 +142,11 @@ is_mb_middle (const char **good, const char *buf, const
> char *end,
> }
>
> *good = prev;
> - return p > buf || match_len < mbrlen (p, end - p, &cur_state);
> +
> + if (p > buf)
> + return true;
> +
> + /* P == BUF here. */
> + return match_len > 0 && match_len < mbrlen (p, end - p, &cur_state);
This is the correct fix, but please rewrite that first comparison
to perform the equivalent test using "<" rather than ">".
That makes it easier to see that we're performing a range test:
return 0 < match_len && match_len < mbrlen (p, end - p, &cur_state);
Thanks for writing the NEWS entry, too.