]> source.dussan.org Git - gitblit.git/commitdiff
Guard docs pages against bad URLs
authorFlorian Zschocke <florian.zschocke@devolo.de>
Mon, 11 Nov 2019 15:24:45 +0000 (16:24 +0100)
committerFlorian Zschocke <florian.zschocke@devolo.de>
Mon, 11 Nov 2019 15:24:45 +0000 (16:24 +0100)
If, for example, an external site links to a docs page or a specific
doc page, and the branch that link points to is no longer existing,
an internal error happens due to a NPE.

The NPE is guarded against and a No Docs page is returned.

src/main/java/com/gitblit/wicket/pages/DocPage.java
src/main/java/com/gitblit/wicket/pages/DocsPage.java

index 5d711343b5ff78f800234d04ce215777e174e97e..6e76f1cd142eac333111240c7508c55ed67ca07f 100644 (file)
@@ -51,6 +51,11 @@ public class DocPage extends RepositoryPage {
                \r
                Repository r = getRepository();\r
                RevCommit commit = JGitUtils.getCommit(r, objectId);\r
+               if (commit == null) {\r
+                       setResponsePage(NoDocsPage.class, params);\r
+                       return;\r
+               }\r
+\r
                String [] encodings = getEncodings();\r
 \r
                // Read raw markup content and transform it to html\r
index 524438626d752fea617d1d117a683b7a1ce557f2..f87d5134764194069e8ceb29f8b3e95e9487bd3e 100644 (file)
@@ -62,6 +62,10 @@ public class DocsPage extends RepositoryPage {
                final boolean userCanEdit = currentUser.canEdit(getRepositoryModel());\r
                \r
                RevCommit head = JGitUtils.getCommit(r, objectId);\r
+               if (head == null) {\r
+                       setResponsePage(NoDocsPage.class, params);\r
+                       return;\r
+               }\r
                final String commitId = getBestCommitId(head);\r
 \r
                List<String> extensions = processor.getAllExtensions();\r