From aaaf45089a56f7be7e952555b10b4b2ca28104db Mon Sep 17 00:00:00 2001 From: Paladox none Date: Thu, 6 Jul 2017 14:30:42 +0000 Subject: [PATCH] Fix StringIndexOutOfBoundsException on /register with URL prefix HttpServletRequest#getPathInfo() raises StringIndexOutOfBoundsException when the path was not set. Add a pattern to detect this and don't attempt to call getPathInfo(). Bug: Issue 6205 Change-Id: If21d8cbebbedfc1d1aa1d12aee295d5a55d9da41 --- .../src/main/java/com/google/gerrit/httpd/UrlModule.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java index b6719e6332..8dfe38cea0 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/UrlModule.java @@ -88,7 +88,8 @@ class UrlModule extends ServletModule { serve("/starred").with(query("is:starred")); serveRegex("^/settings/?$").with(screen(PageLinks.SETTINGS)); - serveRegex("^/register(/.*)?$").with(registerScreen()); + serveRegex("^/register$").with(registerScreen(false)); + serveRegex("^/register/(.+)$").with(registerScreen(true)); serveRegex("^/([1-9][0-9]*)/?$").with(directChangeById()); serveRegex("^/p/(.*)$").with(queryProjectNew()); serveRegex("^/r/(.+)/?$").with(DirectChangeByCommit.class); @@ -251,7 +252,7 @@ class UrlModule extends ServletModule { return srv; } - private Key registerScreen() { + private Key registerScreen(final Boolean slash) { return key( new HttpServlet() { private static final long serialVersionUID = 1L; @@ -259,7 +260,8 @@ class UrlModule extends ServletModule { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException { - toGerrit("/register" + req.getPathInfo(), req, rsp); + String path = String.format("/register%s", slash ? req.getPathInfo() : ""); + toGerrit(path, req, rsp); } }); }