410405 Avoid NPE for requestDispatcher(../)

This commit is contained in:
Greg Wilkins 2013-06-11 14:22:54 +10:00
parent 3db9299369
commit ed04753111
2 changed files with 23 additions and 4 deletions

View File

@ -1871,9 +1871,12 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
// uriInContext = uriInContext.substring(0,q);
String pathInContext = URIUtil.canonicalPath(URIUtil.decodePath(uriInContext));
String uri = URIUtil.addPaths(getContextPath(),uriInContext);
ContextHandler context = ContextHandler.this;
return new Dispatcher(context,uri,pathInContext,query);
if (pathInContext!=null)
{
String uri = URIUtil.addPaths(getContextPath(),uriInContext);
ContextHandler context = ContextHandler.this;
return new Dispatcher(context,uri,pathInContext,query);
}
}
catch (Exception e)
{

View File

@ -226,6 +226,19 @@ public class DispatcherTest
assertEquals(expected, responses);
}
@Test
public void testServletForwardDotDot() throws Exception
{
_contextHandler.addServlet(DispatchServletServlet.class, "/dispatch/*");
_contextHandler.addServlet(RogerThatServlet.class, "/roger/that");
String requests="GET /context/dispatch/test?forward=%2e%2e/roger/that HTTP/1.0\n" + "Host: localhost\n\n";
String responses = _connector.getResponses(requests);
assertThat(responses,startsWith("HTTP/1.1 404 "));
}
@Test
public void testServletInclude() throws Exception
{
@ -418,7 +431,10 @@ public class DispatcherTest
else if(request.getParameter("forward")!=null)
{
dispatcher = getServletContext().getRequestDispatcher(request.getParameter("forward"));
dispatcher.forward(new ServletRequestWrapper(request), new ServletResponseWrapper(response));
if (dispatcher!=null)
dispatcher.forward(new ServletRequestWrapper(request), new ServletResponseWrapper(response));
else
response.sendError(404);
}
}