|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68230 OpenSSL tests spawn PHP processes without preserving the test environment
Submitted: 2014-10-15 07:38 UTC Modified: 2017-10-24 04:33 UTC
Avg. Score:3.7 ± 1.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: gm dot outside+php at gmail dot com Assigned:
Status: Open Package: Testing related
PHP Version: 5.6.1 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-10-15 07:38 UTC] gm dot outside+php at gmail dot com
In the test suite for the OpenSSL extension (ext/openssl) some tests require the server/client architecture.  Therefore they spawn two processes (a server and a client) to perform the tests.

Unfortunately, the way it's currently implemented does not provide reliable testing environment since the spawned instances are not preserving the environment the original test suite was launched in.

In the ext/openssl/tests/ file there is a function called "spawnWorkerProcess()" and it simply executes the PHP binary followed by the script file name and script's arguments.  This picks up the system-wide PHP configuration files and can mess the testing up a lot, especially if the system-wide PHP is much older or configured significantly different than the one we are trying to build and test.

For example, this is how the PHP test suite is executed in our package builder:
sapi/cli/php -n -c ./php-tests.ini -d extension_dir=modules \
        ../run-tests.php -p "$PWD/sapi/cli/php" -q --offline \
                -n -c "$PWD/php-tests.ini" -d "extension_dir=$PWD/modules"

As you can see, "-n" ensures that we are not picking up any default configuration files, followed by "-c" that specifies explicitly which configuration file to use for the test purposes.  Then we define the location of modules.  This is done for both the PHP/CLI executing the test suite and as the arguments to the test suite script itself.

The latter ensures that when the test suite generates test scripts it produces something like the following:
/php-5.6.1/ext/openssl/tests $ cat

/php-5.6.1/build-cgi/sapi/cli/php  -n -c '/php-5.6.1/build-cgi/php-tests.ini'  -d "output_handler=" -d "open_basedir=" -d "safe_mode=0" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=1" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "magic_quotes_runtime=0" -d "ignore_repeated_errors=0" -d "precision=14" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "extension_dir=/php-5.6.1/build-cgi/modules" -d "session.auto_start=0" -d "zlib.output_compression=Off" -d "mbstring.func_overload=0" -f "/php-5.6.1/ext/openssl/tests/bug48182.php"  2>&1

Now, all these settings are NOT honoured by the client/server OpenSSL tests since they are spawned via the spawnWorkerProcess() routine which does not prepare the test environment correctly.

Test script:
It's enough to disable the extension in /etc/php (i.e. in the system-wide configuration), but enable it in the custom configuration file that is provided to the test suite run.

Expected result:
All OpenSSL test pass their checks.

Actual result:
Tests are failing with the following output:
/php-5.6.1/ext/openssl/tests $ ./
Running bug48182

Warning: stream_socket_client(): SSL: Connection refused in /php-5.6.1/ext/openssl/tests/ : eval()'d code on line 9

Warning: stream_socket_client(): Failed to enable crypto in /php-5.6.1/ext/openssl/tests/ : eval()'d code on line 9

Warning: stream_socket_client(): unable to connect to ssl:// (Unknown error) in /php-5.6.1/ext/openssl/tests/ : eval()'d code on line 9

Warning: fwrite() expects parameter 1 to be resource, boolean given in /php-5.6.1/ext/openssl/tests/ : eval()'d code on line 13

Warning: fread() expects parameter 1 to be resource, boolean given in /php-5.6.1/ext/openssl/tests/ : eval()'d code on line 14

But the real error can be seen by strace'ing the script:
28460 write(1, "\nWarning: stream_socket_server(): unable to connect to ssl:// (Unable to find the socket transport \"ssl\" - did you forget to enable it when you configured PHP?) in /php-5.6.1/ext/openssl/tests/ : eval()'d code on line 7\n", 290) = 290


php-5.6.1-owlx-tests-openssl.diff (last revision 2014-10-15 08:09 UTC by gm dot outside+php at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-15 08:15 UTC] gm dot outside+php at gmail dot com
I've just added a patch that partially fixes the test suite.  My patch extracts the name of the configuration file and/or additional configuration files provided to testsuite's PHP binary and executes the spawned PHP binary with the same set of files.  It also extracts the extension_dir and supplies it to the spawned process.

NOTE: This patch is just to fix our build environment so we can build PHP.  This patch does NOT address the real issue of picking up the system-wide configuration files and it misses any custom configuration supplied to the test suite.

To properly solve the issue a new mechanism needs to be invented to ensure that the tests which require spawned children get the proper environment inherited from the primary test suite process.
 [2014-10-17 13:37 UTC]
-Assigned To: +Assigned To: tyrael
 [2015-12-06 16:26 UTC] rainer dot jung at kippdata dot de
This worked for me (and was needed) for PHP 7. I also had to add 

$custom_ini .= " -d ''";

to load the openssl extension (which I had build as a dynamically loadable one).
 [2017-10-24 04:33 UTC]
-Status: Assigned +Status: Open -Assigned To: tyrael +Assigned To:
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:28 2019 UTC