diff options
author | Pekka Enberg <penberg@kernel.org> | 2011-03-02 19:40:10 +0000 |
---|---|---|
committer | Pekka Enberg <penberg@kernel.org> | 2011-03-02 19:40:10 +0000 |
commit | 749bd1d71b3ae5a64bde7440a87808536ee24823 (patch) | |
tree | 2a2d850e1c15e66fb02eb930c4fc9f83c9c82a49 | |
parent | f154af643a6909a062df3051084da49651d720e6 (diff) | |
download | classpath-749bd1d71b3ae5a64bde7440a87808536ee24823.tar.gz |
Fix Matcher.find() infinite loop bug
This patch fixes a problem in Match.find() where the following piece of code
would enter an infinite loop:
System.out.println("hello, world".split("\uFFFF");
The root cause is that Matcher.find() returns true for the following snippet:
Pattern p = Pattern.compile("\uFFFF");
Matcher m = p.matcher("hello, world");
System.out.println(m.find());
2011-03-02 Pekka Enberg <penberg@kernel.org>
* java/util/regex/Matcher:
(find): Make sure match is within input data limits.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | java/util/regex/Matcher.java | 6 |
2 files changed, 11 insertions, 0 deletions
@@ -1,3 +1,8 @@ +2011-03-02 Pekka Enberg <penberg@kernel.org> + + * java/util/regex/Matcher: + (find): Make sure match is within input data limits. + 2011-02-22 Pekka Enberg <penberg@kernel.org> * java/util/HashMap: diff --git a/java/util/regex/Matcher.java b/java/util/regex/Matcher.java index be57471de..2d058fbcb 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) { |