summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorYi EungJun <eungjun.yi@navercorp.com>2014-08-18 18:46:19 +0900
committerYi EungJun <eungjun.yi@navercorp.com>2014-08-21 00:45:39 +0900
commitda6e72908647f8b1d702137564ef8b06582b37e4 (patch)
tree5a916aca3532b41bf2502989d10cab7b3dd0d8db /org.eclipse.jgit/src
parent8e19fea1a9fb222d09b3fc32b1c71c86ff07e7cd (diff)
downloadjgit-da6e72908647f8b1d702137564ef8b06582b37e4.tar.gz
jgit-da6e72908647f8b1d702137564ef8b06582b37e4.zip
Throw URISyntaxException for incorrect percent-encoding
URIish.unescape() threw an ArrayIndexOutOfBoundsException if the given url has incorrect percent-encoding (e.g. http://example.com/%gg). But an URISyntaxException is much better to know the reason of the failure. Change-Id: I3f40a26d43cd2eb4e32c11aba7dc2594bc1f98e2 Signed-off-by: Yi EungJun <eungjun.yi@navercorp.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java15
1 files changed, 13 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
index aae898db81..91e212b478 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
@@ -252,6 +252,11 @@ public class URIish implements Serializable {
throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
}
+ private static int parseHexByte(byte c1, byte c2) {
+ return ((RawParseUtils.parseHexInt4(c1) << 4)
+ | RawParseUtils.parseHexInt4(c2));
+ }
+
private static String unescape(String s) throws URISyntaxException {
if (s == null)
return null;
@@ -272,8 +277,14 @@ public class URIish implements Serializable {
if (c == '%') {
if (i + 2 >= bytes.length)
throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
- int val = (RawParseUtils.parseHexInt4(bytes[i + 1]) << 4)
- | RawParseUtils.parseHexInt4(bytes[i + 2]);
+ byte c1 = bytes[i + 1];
+ byte c2 = bytes[i + 2];
+ int val;
+ try {
+ val = parseHexByte(c1, c2);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish);
+ }
os[j++] = (byte) val;
i += 2;
} else