Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

Wrong if condition handlingin controller/boostrap.php #93

Closed
tniebergall opened this issue Feb 15, 2016 · 19 comments
Closed

Wrong if condition handlingin controller/boostrap.php #93

tniebergall opened this issue Feb 15, 2016 · 19 comments

Comments

@tniebergall
Copy link

I think the following code block is wrong, because the function is triggered when it doesn't exist and causes an server error 500.

// Add the posix_getpwuid function
if (!function_exists('posix_getpwuid')) {
    function posix_getpwuid($int) {
        return array('name'=>$int);
    }
}

It should be

// Add the posix_getpwuid function
if (function_exists('posix_getpwuid')) {
    function posix_getpwuid($int) {
        return array('name'=>$int);
    }
}
@leofeyer
Copy link
Member

I don't think so. The function must only be defined if it does not yet exist, mustn't it?

@tniebergall
Copy link
Author

Yes you're right that was my mistake.

But if you execute the original code on a system where posix_getpwuid isn't enabled, you get the described server error 500.

Whit the changed code the error wont appear.

@leofeyer
Copy link
Member

What is written into the server log file when the error occurs?

@tniebergall
Copy link
Author

PHP Fatal error: Cannot redeclare posix_getpwuid() in /var/www/web204/htdocs/contao-3-5/check/controller/bootstrap.php on line 173

@fritzmg
Copy link
Collaborator

fritzmg commented Mar 12, 2016

This error has been around for a long time. See https://community.contao.org/de/showthread.php?8940-System-Check-Fatal-error-posix_getpwuid&p=76537&viewfull=1#post76537 for one possible workaround for example.

@leofeyer
Copy link
Member

Your "workaround" is not really a workaround. You might as well remove the function declaration completely, because create_function() creates an anonymous function and not one called posix_getpwuid (). Are you sure this is not a duplicate of #86?

@fritzmg
Copy link
Collaborator

fritzmg commented Mar 21, 2016

Well it's not 'my' workaround - but the issue has been around for that long. Yes, the issue is probably a duplicate of #86 - however, that issue was closed by the reporter.

@leofeyer
Copy link
Member

Correct, because a PHP update apparently solved the issue. (Which would indicate a PHP bug.)

@fritzmg
Copy link
Collaborator

fritzmg commented Mar 21, 2016

Indeed. However, I have no idea under which conditions (specific PHP version, specific PHP build of specific Linux distris) this issue might be caused. It just happens to pop up every now and again on various hosters/systems.

@qzminski
Copy link
Member

qzminski commented May 27, 2016

It can also happen if the function is disabled for security reasons, see error:

Warning: posix_getpwuid() has been disabled for security reasons in /home/mirand/domains/domain.com/public_html/check/controller/file-permissions.php on line 142 

Then the function_exists() seem to return false but the function name itself is already registered.

@leofeyer
Copy link
Member

So what's the status on this issue?

@tniebergall
Copy link
Author

So for my opinion it could be closed. I solved it for the corresponding server, but this was the first and only one with this error.

@fritzmg
Copy link
Collaborator

fritzmg commented Sep 12, 2016

If the only cause of this issue is posix_getpwuid being disabled via disable_functions, then a possible "fix" for the check might be:

if (!function_exists('posix_getpwuid') && !in_array('posix_getpwuid', explode(',', ini_get('disable_functions')))) {
    function posix_getpwuid($int) {
        return array('name'=>$int);
    }
}

Then you'll get at least a more useful warning:

screen shot 2016-09-12 at 09 59 12

instead of

PHP Fatal error:  Cannot redeclare posix_getpwuid() in …

@leofeyer
Copy link
Member

I assume you have copied this "solution" from the PHP manual? Did you realize that both these answers have been downvoted?

This is actually a PHP bug, which has been fixed already: https://bugs.php.net/bug.php?id=69297&edit=3

@fritzmg
Copy link
Collaborator

fritzmg commented Sep 12, 2016

No, I did not copy that from anywhere. My "solution" simply prevents the redeclaration of posix_getpwuid when it is defined in disable_functions.

The PHP bug you referred to is something else entirely and has nothing to do with this issue.

@fritzmg
Copy link
Collaborator

fritzmg commented Sep 12, 2016

The problem occurs under PHP 5.4.39, 5.6.24 and 7.0.9.

As long as posix_getpwuid is defined in disable_functions, the Contao Check will run into the aforementioned fatal error.

@leofeyer
Copy link
Member

My "solution" simply prevents the redeclaration of posix_getpwuid when it is defined in disable_functions.

Which does not improve anything at all! You are just exchanging one error message with another.

@fritzmg
Copy link
Collaborator

fritzmg commented Sep 12, 2016

I know, but, as I said, at least then you are getting a warning telling you what the actual problem is. Of course you could also simply do

if (in_array('posix_getpwuid', explode(',', ini_get('disable_functions'))))
{
    die("'posix_getpwuid' must not be in 'disable_functions'");
}

or something better.

In any case, the fatal error should be avoided somehow.

@fritzmg
Copy link
Collaborator

fritzmg commented Sep 12, 2016

The Contao Check is supposed to be able to run on most configurations without generating a Fatal Error (or die for that matter…) - since it is used to determine whether the respective environment meets the minimum requirements for Contao amongst other things (like installing Contao and validating an existing installation).

Thus, instead of generating a fatal error (current situation), a warning or just a die(), maybe the disable_functions check could be done inside file-permissions.php or wherever, i.e. where the posix_getpwuid function is needed. This way the Contao Check will generally work and it can tell you that posix_getpwuid is disabled and thus the Contao Check cannot test the file permissions.

This way, a regular User using the Contao Check will more likely know what to do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants