operasoftware / ssh-key-authority

A tool for managing SSH key access to any number of servers.
Apache License 2.0
456 stars 71 forks source link

Compatibility issue with php7.4 #59

Closed Chluz closed 3 years ago

Chluz commented 3 years ago

Hi, after upgrading to php7.4, I was having issues with php errors of the type Uncaught ErrorException: Trying to access array offset on value of type null in the file core.php at line 100.

I therefore changed

$prefix = $args[0][0] == "/" ? "/" : "";

to

        if ($args[0] !== null) {
            $prefix = $args[0][0] == "/" ? "/" : "";
        } else {
            $prefix = "";
        }

Its not very clean, but I don't really know php ! Hope it helps others having the same issue. I can create a merge request if this is acceptable.

wastez commented 3 years ago

Thats really strange, i`m using also php7.4 without issues.

Chluz commented 3 years ago

Indeed, perhaps I have settings in php which do not allow for these types of error, or my specific install triggers $args[0] == null.

thomas-pike commented 3 years ago

It would be because the path_join function is being called with a null parameter, which it does not expect. It would be interesting to have the full stacktrace to try to figure out why it is being passed a null value in the first place.

Chluz commented 3 years ago

I reverted the change to retrigger the error, and now I'm not getting any error messages. I do not know what is happening.

The original issue was

[Fri Nov 05 23:25:25.974060 2021] [php:error] [pid 16362] [client 192.168.67.13:39040] PHP Fatal error:  Uncaught ErrorException: Trying to access array offset on value of type null in /var/www/ssh-key-authority/core.php:101\nStack trace:\n#0 /var/www/ssh-key-authority/core.php(101): exception_error_handler()\n#1 /var/www/ssh-key-authority/core.php(55): path_join()\n#2 /var/www/ssh-key-authority/core.php(75): autoload_model()\n#3 /var/www/ssh-key-authority/core.php(42): setup_database()\n#4 /var/www/ssh-key-authority/requesthandler.php(19): require('...')\n#5 /var/www/ssh-key-authority/public_html/init.php(18): require('...')\n#6 {main}\n  thrown in /var/www/ssh-key-authority/core.php on line 101
thomas-pike commented 3 years ago

Making that a bit more readable:

[Fri Nov 05 23:25:25.974060 2021] [php:error] [pid 16362] [client 192.168.67.13:39040] PHP Fatal error:  Uncaught
ErrorException: Trying to access array offset on value of type null in /var/www/ssh-key-authority/core.php:101
Stack trace:
#0 /var/www/ssh-key-authority/core.php(101): exception_error_handler()
#1 /var/www/ssh-key-authority/core.php(55): path_join()
#2 /var/www/ssh-key-authority/core.php(75): autoload_model()
#3 /var/www/ssh-key-authority/core.php(42): setup_database()
#4 /var/www/ssh-key-authority/requesthandler.php(19): require('...')
#5 /var/www/ssh-key-authority/public_html/init.php(18): require('...')
#6 {main}
  thrown in /var/www/ssh-key-authority/core.php on line 101

Given the path this has followed, I can only assume that the error was caused by $base_path somehow being null. Commit be22ecf9 did fix a bug that would cause $base_path to not be set correctly in CLI scripts. Is it possible that you were running an older version of the code that did not have this fix?

Chluz commented 3 years ago

Hi Thomas, thank you for the answer. Yes it's possible, I would even say it's probable. I had not yet pulled this year's changes when the bug was triggered initially. I then implemented the fix above, and starting cherry picking commits - not noticing that the commit you linked might be fixing the issue. I think that you found the root cause, and we can close this issue now. Thanks Again !