Browse Source

Don't crash while parsing ignore patterns

Catch unexpected PatternSyntaxException and convert it to
InvalidPatternException. Log such errors, do not silently ignore them.

Bug: 463581
Change-Id: Id0936d9816769ec0cfae1898beda0f7a3c146e67
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.1
Andrey Loskutov 10 years ago committed by Matthias Sohn
parent
commit
b98c84eb88
  1. 1
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  2. 5
      org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java
  3. 12
      org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java
  4. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

1
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -328,6 +328,7 @@ invalidId=Invalid id: {0}
invalidId0=Invalid id
invalidIdLength=Invalid id length {0}; should be {1}
invalidIgnoreParamSubmodule=Found invalid ignore param for submodule {0}.
invalidIgnoreRule=Exception caught while parsing ignore rule ''{0}''.
invalidIntegerValue=Invalid integer value: {0}.{1}={2}
invalidKey=Invalid key: {0}
invalidLineInConfigFile=Invalid line in config file

5
org.eclipse.jgit/src/org/eclipse/jgit/ignore/FastIgnoreRule.java

@ -47,6 +47,8 @@ import static org.eclipse.jgit.ignore.internal.IMatcher.NO_MATCH;
import org.eclipse.jgit.errors.InvalidPatternException;
import org.eclipse.jgit.ignore.internal.IMatcher;
import org.eclipse.jgit.ignore.internal.PathMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* "Fast" (compared with IgnoreRule) git ignore rule implementation supporting
@ -57,6 +59,8 @@ import org.eclipse.jgit.ignore.internal.PathMatcher;
* @since 3.6
*/
public class FastIgnoreRule {
private final static Logger LOG = LoggerFactory
.getLogger(FastIgnoreRule.class);
/**
* Character used as default path separator for ignore entries
@ -121,6 +125,7 @@ public class FastIgnoreRule {
Character.valueOf(PATH_SEPARATOR), dirOnly);
} catch (InvalidPatternException e) {
m = NO_MATCH;
LOG.error(e.getMessage(), e);
}
this.matcher = m;
}

12
org.eclipse.jgit/src/org/eclipse/jgit/ignore/internal/Strings.java

@ -44,13 +44,16 @@ package org.eclipse.jgit.ignore.internal;
import static java.lang.Character.isLetter;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.eclipse.jgit.errors.InvalidPatternException;
import org.eclipse.jgit.ignore.FastIgnoreRule;
import org.eclipse.jgit.internal.JGitText;
/**
* Various {@link String} related utility methods, written mostly to avoid
@ -367,7 +370,16 @@ public class Strings {
if (in_brackets > 0)
throw new InvalidPatternException("Not closed bracket?", pattern); //$NON-NLS-1$
try {
return Pattern.compile(sb.toString());
} catch (PatternSyntaxException e) {
InvalidPatternException patternException = new InvalidPatternException(
MessageFormat.format(JGitText.get().invalidIgnoreRule,
pattern),
pattern);
patternException.initCause(e);
throw patternException;
}
}
/**

1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -387,6 +387,7 @@ public class JGitText extends TranslationBundle {
/***/ public String invalidId0;
/***/ public String invalidIdLength;
/***/ public String invalidIgnoreParamSubmodule;
/***/ public String invalidIgnoreRule;
/***/ public String invalidIntegerValue;
/***/ public String invalidKey;
/***/ public String invalidLineInConfigFile;

Loading…
Cancel
Save