operasoftware / dns-ui

Opera's LDAP-authenticated PowerDNS user interface
Apache License 2.0
282 stars 57 forks source link

Replaces variable `$base_path` with constant to avoid NullPointerExcption in `path_join()`. #163

Closed chr-fritz closed 4 years ago

chr-fritz commented 4 years ago

When running dns-ui under PHP 7.4.1 it will produce the following error:

Fatal error: Uncaught ErrorException: Trying to access array offset on value of type null in /var/www/dns-ui/core.php:102
Stack trace:
#0 /var/www/dns-ui/core.php(102): exception_error_handler(8, 'Trying to acces...', '/var/www/dns-ui...', 102, Array) 
#1 /var/www/dns-ui/core.php(69): path_join(NULL, 'model', 'migrationdirect...') 
#2 [internal function]: autoload_model('migrationdirect...') 
#3 /var/www/dns-ui/core.php(81): spl_autoload_call('MigrationDirect...') 
#4 /var/www/dns-ui/core.php(55): setup_database() 
#5 /var/www/dns-ui/requesthandler.php(19): require('/var/www/dns-ui...') 
#6 /var/www/dns-ui/public_html/init.php(18): require('/var/www/dns-ui...') 
#7 {main} thrown in /var/www/dns-ui/core.php on line 102

The reason about this is, that the variable $base_path is not available in core.php. This PR replaces this variable by a new constant BASE_PATH which is set before core.php is included.

thomas-pike commented 4 years ago

It feels to me like converting to a constant is just hiding the problem (the variable being unset when being used prior to being defined). I don't have PHP 7.4 to test on right now, but I think a more correct solution would be just to move the definition of the $base_path variable in to core.php. Moving it to earlier in requesthandler.php does help, but moving it to core.php would also make the variable available to files in the scripts/ directory so those files don't need changes. Of course one can debate the merits of using a constant instead of a variable, but the actual bug here is that we're defining the variable in the wrong place.

thomas-pike commented 4 years ago

I hope you consider the fix in 66ba8bb to be sufficient. Thank you for finding this bug.