summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorPekka Enberg <penberg@kernel.org>2011-03-02 19:40:10 +0000
committerPekka Enberg <penberg@kernel.org>2011-03-02 19:40:10 +0000
commit749bd1d71b3ae5a64bde7440a87808536ee24823 (patch)
tree2a2d850e1c15e66fb02eb930c4fc9f83c9c82a49 /java
parentf154af643a6909a062df3051084da49651d720e6 (diff)
downloadclasspath-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.
Diffstat (limited to 'java')
-rw-r--r--java/util/regex/Matcher.java6
1 files changed, 6 insertions, 0 deletions
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)
{