Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom library path + custom library, without slash in its name, results in exception #4971

Closed
distahl opened this issue Jan 9, 2023 · 0 comments · Fixed by #4978
Closed
Assignees
Labels
area/framework Affects third party integration/development bug Something isn't working
Milestone

Comments

@distahl
Copy link

distahl commented Jan 9, 2023

Describe the bug

I've added a custom library path for icingaweb2 in the apache config. After that I created my own library in this path. The name of the library (composer.json) does not contain any slash. When I now navigate to configuration->module and view other modules having dependencies, like vspheredb or icingadb, I get this exception:

Undefined offset: 1
#0 /usr/share/php/Icinga/Application/Libraries.php(82): Icinga\Application\ApplicationBootstrap->Icinga\Application\{closure}()
#1 /usr/share/php/Icinga/Application/Libraries.php(52): Icinga\Application\Libraries->get()
#2 /usr/share/php/Icinga/Application/Modules/Manager.php(583): Icinga\Application\Libraries->has()
#3 /usr/share/icingaweb2/application/views/scripts/config/module.phtml(13): Icinga\Application\Modules\Manager->hasUnmetDependencies()
#4 /usr/share/php/Icinga/Web/View.php(235): include(String)
#5 /usr/share/icingaweb2/library/vendor/Zend/View/Abstract.php(877): Icinga\Web\View->_run()
#6 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/Helper/ViewRenderer.php(904): Zend_View_Abstract->render()
#7 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/Helper/ViewRenderer.php(925): Zend_Controller_Action_Helper_ViewRenderer->renderScript()
#8 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/Helper/ViewRenderer.php(964): Zend_Controller_Action_Helper_ViewRenderer->render()
#9 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action/HelperBroker.php(272): Zend_Controller_Action_Helper_ViewRenderer->postDispatch()
#10 /usr/share/icingaweb2/library/vendor/Zend/Controller/Action.php(518): Zend_Controller_Action_HelperBroker->notifyPostDispatch()
#11 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(76): Zend_Controller_Action->dispatch()
#12 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch()
#13 /usr/share/php/Icinga/Application/Web.php(304): Zend_Controller_Front->dispatch()
#14 /usr/share/php/Icinga/Application/webrouter.php(109): Icinga\Application\Web->dispatch()
#15 /usr/share/icingaweb2/public/index.php(4): require_once(String)
#16 {main}

This exception points to a condition inside Libraries.php. The elseif clause just assumes every name has at least one slash without testing for it.

    public function get($name)
    {
        $candidate = null;
        foreach ($this->libraries as $library) {
            $libraryName = $library->getName();
            if ($libraryName === $name) {
                return $library;
            } elseif (explode('/', $libraryName)[1] === $name) {
                // Also return libs which only partially match
                $candidate = $library;
            }
        }

        return $candidate;
    }

If I change the name of my library to have at least one slash inside its name, then the exception is gone.

To Reproduce

  1. Go to /etc/httpd/conf.d/icingaweb2.conf and change the libdir like this:
    SetEnv ICINGAWEB_LIBDIR "/usr/share/icinga-php:/usr/share/icingaweb2/modules/libraries".
    ( I know this is not 100% clean, because its inside the module path, but it was working so far)
  2. Reload Apache Service
  3. Create your own library inside the non-default path and in the composer.json give it a name not containing any slash.
  4. In IcingaWeb, navigate to configuration->module and click any module, which is having dependencies for libraries. E.g.: icingadb or vspheredb

Expected behavior

Don't throw exception when names of libraries not contain a slash

Screenshots

Your Environment

Include as many relevant details about the environment you experienced the problem in

  • Icinga Web 2 version and modules (System - About): 2.9.6
  • Web browser used: Chromium (108.0.5359.125)
  • Icinga 2 version used (icinga2 --version): 2.13.6
  • PHP version used (php --version): 7.3.33
  • Server operating system and version: RHEL 7.9

Additional context

@nilmerg nilmerg added bug Something isn't working area/framework Affects third party integration/development labels Jan 11, 2023
@nilmerg nilmerg self-assigned this Jan 11, 2023
nilmerg added a commit that referenced this issue Jan 12, 2023
nilmerg added a commit that referenced this issue Jan 12, 2023
nilmerg added a commit that referenced this issue Jan 12, 2023
@nilmerg nilmerg added this to the 2.11.4 milestone Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/framework Affects third party integration/development bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants