Conversation
A preload script runs during server startup, before any request, so SG(server_context) is NULL. Several apache2handler functions and SAPI hooks that opcache does not swap out during preloading dereferenced it unconditionally: apache_getenv(), apache_setenv(), apache_note(), apache_request_headers()/getallheaders(), apache_response_headers(), php_apache_sapi_get_stat() (reached by getmyuid()) and php_apache_sapi_read_post() (reached by php://input). Calling any of them from a preload script crashed the server at startup. The cli-server's own apache_request_headers() has the same pattern. Make each of them tolerate a NULL context: the array-returning functions return an empty array, the bool/string-returning ones warn and return false, and the two SAPI hooks return the neutral value their contract already allows for a failure (NULL for get_stat(), 0 bytes read for read_post()), the same way php_apache_lookup_uri() and php_apache_sapi_getenv() already did. The phpinfo() module info section (PHP_MINFO_FUNCTION(apache)) has the same unchecked dereference but needs a broader change to stay useful without a request; left out of this fix. Fixes #2493
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A preload script runs before any request, so
SG(server_context)isNULL. Several apache2handler functions and SAPI hooks that opcache does not swap out during preloading dereferenced it unconditionally (apache_getenv(),apache_setenv(),apache_note(),apache_request_headers()/getallheaders(),apache_response_headers(),php_apache_sapi_get_stat(),php_apache_sapi_read_post()), crashing the server at startup. The cli-server's ownapache_request_headers()has the same pattern.Make each of them tolerate a NULL context, returning the neutral value their contract already allows, the same way
php_apache_lookup_uri()andphp_apache_sapi_getenv()already did.PHP_MINFO_FUNCTION(apache)has the same issue but needs a broader change; left out of this fix.