On 16:22 Wed 02 Mar     , Pekka Enberg wrote:
> This patch fixes a problem in Match.find() where the following piece of code
> would enter an infinite loop:
> 
>     Pattern p = Pattern.compile("\uFFFF");
>     Matcher m = p.matcher("hello, world");
>     System.out.println(m.find());
> 

Seems a sensible fix.  Could you provide a testcase for Mauve for this too?

> Signed-off-by: Pekka Enberg <penb...@kernel.org>
> ---
>  ChangeLog                    |    5 +++++
>  java/util/regex/Matcher.java |    6 ++++++
>  2 files changed, 11 insertions(+), 0 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 05aa794..2b9cb5c 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,8 @@
> +2011-03-02  Pekka Enberg  <penb...@kernel.org>
> +
> +     * java/util/regex/Matcher:
> +     (find): Make sure match is within input data limits.
> +
>  2011-02-22  Pekka Enberg  <penb...@kernel.org>
>  
>       * java/util/HashMap:
> diff --git a/java/util/regex/Matcher.java b/java/util/regex/Matcher.java
> index be57471..86c4873 100644
> --- a/java/util/regex/Matcher.java
> +++ b/java/util/regex/Matcher.java
> @@ -169,6 +169,12 @@ public final class Matcher implements MatchResult
>      if (match != null)
>        {
>          int endIndex = match.getEndIndex();
> +        // Is the match within input limits?
> +        if (endIndex >= input.length())
> +          {
> +            match = null;
> +            return false;
> +          }
>          // Are we stuck at the same position?
>          if (!first && endIndex == position)
>            {
> -- 
> 1.7.1
> 
> 

-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and IcedTea
http://www.gnu.org/software/classpath
http://icedtea.classpath.org
PGP Key: F5862A37 (https://keys.indymedia.org/)
Fingerprint = EA30 D855 D50F 90CD F54D  0698 0713 C3ED F586 2A37

Reply via email to