mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
fix possible npe with unpacked war files
This commit is contained in:
@@ -35,6 +35,7 @@ package sonia.scm.web.cgi;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -99,8 +100,8 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
public DefaultCGIExecutor(ScmConfiguration configuration,
|
public DefaultCGIExecutor(ScmConfiguration configuration,
|
||||||
ServletContext context, HttpServletRequest request,
|
ServletContext context, HttpServletRequest request,
|
||||||
HttpServletResponse response)
|
HttpServletResponse response)
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -149,10 +150,14 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
String path = command.getAbsolutePath();
|
String path = command.getAbsolutePath();
|
||||||
String pathTranslated = request.getPathTranslated();
|
String pathTranslated = request.getPathTranslated();
|
||||||
|
|
||||||
if (Util.isEmpty(pathTranslated))
|
if (Strings.isNullOrEmpty(pathTranslated))
|
||||||
{
|
{
|
||||||
pathTranslated = path;
|
pathTranslated = path;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pathTranslated = HttpUtil.removeMatrixParameter(pathTranslated);
|
||||||
|
}
|
||||||
|
|
||||||
env.set(ENV_PATH_TRANSLATED, pathTranslated);
|
env.set(ENV_PATH_TRANSLATED, pathTranslated);
|
||||||
|
|
||||||
@@ -296,8 +301,6 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
String uri = HttpUtil.removeMatrixParameter(request.getRequestURI());
|
String uri = HttpUtil.removeMatrixParameter(request.getRequestURI());
|
||||||
String scriptName = uri.substring(0, uri.length() - pathInfo.length());
|
String scriptName = uri.substring(0, uri.length() - pathInfo.length());
|
||||||
String scriptPath = context.getRealPath(scriptName);
|
String scriptPath = context.getRealPath(scriptName);
|
||||||
String pathTranslated =
|
|
||||||
HttpUtil.removeMatrixParameter(request.getPathTranslated());
|
|
||||||
int len = request.getContentLength();
|
int len = request.getContentLength();
|
||||||
EnvList env = new EnvList();
|
EnvList env = new EnvList();
|
||||||
|
|
||||||
@@ -331,7 +334,6 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
env.set(ENV_CONTENT_TYPE, Util.nonNull(request.getContentType()));
|
env.set(ENV_CONTENT_TYPE, Util.nonNull(request.getContentType()));
|
||||||
env.set(ENV_GATEWAY_INTERFACE, CGI_VERSION);
|
env.set(ENV_GATEWAY_INTERFACE, CGI_VERSION);
|
||||||
env.set(ENV_PATH_INFO, pathInfo);
|
env.set(ENV_PATH_INFO, pathInfo);
|
||||||
env.set(ENV_PATH_TRANSLATED, pathTranslated);
|
|
||||||
env.set(ENV_QUERY_STRING, request.getQueryString());
|
env.set(ENV_QUERY_STRING, request.getQueryString());
|
||||||
env.set(ENV_REMOTE_ADDR, request.getRemoteAddr());
|
env.set(ENV_REMOTE_ADDR, request.getRemoteAddr());
|
||||||
env.set(ENV_REMOTE_HOST, request.getRemoteHost());
|
env.set(ENV_REMOTE_HOST, request.getRemoteHost());
|
||||||
@@ -351,9 +353,8 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
|
|
||||||
env.set(ENV_SERVER_PORT, Integer.toString(serverPort));
|
env.set(ENV_SERVER_PORT, Integer.toString(serverPort));
|
||||||
env.set(ENV_SERVER_PROTOCOL, Util.nonNull(request.getProtocol()));
|
env.set(ENV_SERVER_PROTOCOL, Util.nonNull(request.getProtocol()));
|
||||||
env.set(
|
env.set(ENV_SERVER_SOFTWARE,
|
||||||
ENV_SERVER_SOFTWARE,
|
SERVER_SOFTWARE_PREFIX.concat(SCMContext.getContext().getVersion()));
|
||||||
SERVER_SOFTWARE_PREFIX.concat(SCMContext.getContext().getVersion()));
|
|
||||||
|
|
||||||
Enumeration enm = request.getHeaderNames();
|
Enumeration enm = request.getHeaderNames();
|
||||||
|
|
||||||
@@ -363,13 +364,13 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
String value = request.getHeader(name);
|
String value = request.getHeader(name);
|
||||||
|
|
||||||
env.set(ENV_HTTP_HEADER_PREFIX + name.toUpperCase().replace('-', '_'),
|
env.set(ENV_HTTP_HEADER_PREFIX + name.toUpperCase().replace('-', '_'),
|
||||||
value);
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// these extra ones were from printenv on www.dev.nomura.co.uk
|
// these extra ones were from printenv on www.dev.nomura.co.uk
|
||||||
env.set(ENV_HTTPS, (request.isSecure()
|
env.set(ENV_HTTPS, (request.isSecure()
|
||||||
? ENV_HTTPS_VALUE_ON
|
? ENV_HTTPS_VALUE_ON
|
||||||
: ENV_HTTPS_VALUE_OFF));
|
: ENV_HTTPS_VALUE_OFF));
|
||||||
|
|
||||||
if (SystemUtil.isWindows())
|
if (SystemUtil.isWindows())
|
||||||
{
|
{
|
||||||
@@ -552,8 +553,8 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
logger.error(
|
logger.error(
|
||||||
"could not read from ServletInputStream and write to ProcessOutputStream",
|
"could not read from ServletInputStream and write to ProcessOutputStream",
|
||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -574,8 +575,8 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private void waitForFinish(Process process, ServletOutputStream output,
|
private void waitForFinish(Process process, ServletOutputStream output,
|
||||||
long content)
|
long content)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -586,14 +587,14 @@ public class DefaultCGIExecutor extends AbstractCGIExecutor
|
|||||||
if (logger.isTraceEnabled())
|
if (logger.isTraceEnabled())
|
||||||
{
|
{
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"handle status code {} with statusCodeHandler, there are {} bytes written to outputstream",
|
"handle status code {} with statusCodeHandler, there are {} bytes written to outputstream",
|
||||||
exitCode, content);
|
exitCode, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content == 0)
|
if (content == 0)
|
||||||
{
|
{
|
||||||
getStatusCodeHandler().handleStatusCode(request, response, output,
|
getStatusCodeHandler().handleStatusCode(request, response, output,
|
||||||
exitCode);
|
exitCode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user