From c4698341d75ef4adc38ebbc3bfbca81bf0ed80dc Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Mon, 11 Nov 2019 16:24:45 +0100 Subject: [PATCH] Guard docs pages against bad URLs 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 | 5 +++++ src/main/java/com/gitblit/wicket/pages/DocsPage.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/gitblit/wicket/pages/DocPage.java b/src/main/java/com/gitblit/wicket/pages/DocPage.java index 5d711343..6e76f1cd 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocPage.java @@ -51,6 +51,11 @@ public class DocPage extends RepositoryPage { Repository r = getRepository(); RevCommit commit = JGitUtils.getCommit(r, objectId); + if (commit == null) { + setResponsePage(NoDocsPage.class, params); + return; + } + String [] encodings = getEncodings(); // Read raw markup content and transform it to html diff --git a/src/main/java/com/gitblit/wicket/pages/DocsPage.java b/src/main/java/com/gitblit/wicket/pages/DocsPage.java index 52443862..f87d5134 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocsPage.java @@ -62,6 +62,10 @@ public class DocsPage extends RepositoryPage { final boolean userCanEdit = currentUser.canEdit(getRepositoryModel()); RevCommit head = JGitUtils.getCommit(r, objectId); + if (head == null) { + setResponsePage(NoDocsPage.class, params); + return; + } final String commitId = getBestCommitId(head); List extensions = processor.getAllExtensions(); -- 2.39.5