]> source.dussan.org Git - gitblit.git/commitdiff
Plugged some repository use count leaks in the zip servlet
authorJames Moger <james.moger@gitblit.com>
Tue, 10 Jan 2012 01:46:54 +0000 (20:46 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 10 Jan 2012 01:46:54 +0000 (20:46 -0500)
src/com/gitblit/Constants.java
src/com/gitblit/DownloadZipServlet.java

index 602a6aef2c0a0b3125f270f1f987e2b957a5b1c4..23e755724002266ec26e9f34cf5c5c8288429839 100644 (file)
@@ -54,13 +54,17 @@ public class Constants {
        public static final String FEDERATION_PATH = "/federation/";\r
 \r
        public static final String RPC_PATH = "/rpc/";\r
+       \r
+       public static final String PAGES= "/pages/";\r
 \r
        public static final String BORDER = "***********************************************************";\r
 \r
        public static final String FEDERATION_USER = "$gitblit";\r
 \r
        public static final String PROPOSAL_EXT = ".json";\r
-\r
+       \r
+       public static final String ENCODING = "UTF-8";\r
+       \r
        public static String getGitBlitVersion() {\r
                return NAME + " v" + VERSION;\r
        }\r
index ed3aa553e78846f31d4a997e2cfe0d71200440ff..209272f2fa9729e765e452e97c8321b673b88b78 100644 (file)
  */\r
 package com.gitblit;\r
 \r
+import java.io.IOException;\r
+import java.text.MessageFormat;\r
+import java.text.ParseException;\r
 import java.util.Date;\r
 \r
+import javax.servlet.ServletException;\r
 import javax.servlet.http.HttpServlet;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
@@ -26,6 +30,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.MarkdownUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
@@ -79,7 +84,7 @@ public class DownloadZipServlet extends HttpServlet {
                        response.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                        return;\r
                }\r
-               \r
+\r
                String repository = request.getParameter("r");\r
                String basePath = request.getParameter("p");\r
                String objectId = request.getParameter("h");\r
@@ -98,8 +103,18 @@ public class DownloadZipServlet extends HttpServlet {
                        }\r
 \r
                        Repository r = GitBlit.self().getRepository(repository);\r
+                       if (r == null) {\r
+                               error(response, MessageFormat.format("# Error\nFailed to find repository {0}", repository));\r
+                               return;\r
+                       }\r
                        RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+                       if (commit == null) {\r
+                               error(response, MessageFormat.format("# Error\nFailed to find commit {0}", objectId));\r
+                               r.close();\r
+                               return;\r
+                       }\r
                        Date date = JGitUtils.getCommitDate(commit);\r
+\r
                        String contentType = "application/octet-stream";\r
                        response.setContentType(contentType + "; charset=" + response.getCharacterEncoding());\r
                        response.setHeader("Content-Disposition", "attachment; filename=\"" + name + ".zip"\r
@@ -115,11 +130,21 @@ public class DownloadZipServlet extends HttpServlet {
                        } catch (Throwable t) {\r
                                logger.error("Failed to write attachment to client", t);\r
                        }\r
+\r
+                       // close the repository\r
+                       r.close();\r
                } catch (Throwable t) {\r
                        logger.error("Failed to write attachment to client", t);\r
                }\r
        }\r
 \r
+       private void error(HttpServletResponse response, String mkd) throws ServletException,\r
+                       IOException, ParseException {\r
+               String content = MarkdownUtils.transformMarkdown(mkd);\r
+               response.setContentType("text/html; charset=" + Constants.ENCODING);\r
+               response.getWriter().write(content);\r
+       }\r
+\r
        @Override\r
        protected void doPost(javax.servlet.http.HttpServletRequest request,\r
                        javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,\r