From 2ea418cbe60ebca1b89e7110b7ef444bcf54e1f7 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Mon, 30 Jun 2014 15:48:43 +0200
Subject: [PATCH] doc module: Respond with 404 if a chapter was not found or
 the doc directory is empty

refs #4820
---
 .../application/controllers/ModuleController.php  | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/modules/doc/application/controllers/ModuleController.php b/modules/doc/application/controllers/ModuleController.php
index e8b7c2fdd..2ce1b1e73 100644
--- a/modules/doc/application/controllers/ModuleController.php
+++ b/modules/doc/application/controllers/ModuleController.php
@@ -2,9 +2,10 @@
 // {{{ICINGA_LICENSE_HEADER}}}
 // {{{ICINGA_LICENSE_HEADER}}}
 
-use Zend_Controller_Action_Exception;
+use \Zend_Controller_Action_Exception;
 use Icinga\Application\Icinga;
 use Icinga\Module\Doc\DocController;
+use Icinga\Module\Doc\Exception\DocException;
 
 class Doc_ModuleController extends DocController
 {
@@ -53,7 +54,11 @@ class Doc_ModuleController extends DocController
         $moduleName = $this->getParam('moduleName');
         $this->assertModuleEnabled($moduleName);
         $moduleManager = Icinga::app()->getModuleManager();
-        $this->populateToc($moduleManager->getModuleDir($moduleName, '/doc'), $moduleName);
+        try {
+            $this->populateToc($moduleManager->getModuleDir($moduleName, '/doc'), $moduleName);
+        } catch (DocException $e) {
+            throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
+        }
         $this->view->moduleName = $moduleName;
     }
 
@@ -71,7 +76,11 @@ class Doc_ModuleController extends DocController
             throw new Zend_Controller_Action_Exception('Missing parameter "chapterName"', 404);
         }
         $moduleManager = Icinga::app()->getModuleManager();
-        $this->populateChapter($chapterName, $moduleManager->getModuleDir($moduleName, '/doc'));
+        try {
+            $this->populateChapter($chapterName, $moduleManager->getModuleDir($moduleName, '/doc'));
+        } catch (DocException $e) {
+            throw new Zend_Controller_Action_Exception($e->getMessage(), 404);
+        }
         $this->view->moduleName = $moduleName;
     }
 }