Bug #71129 [Com]: Segmentation fault on ZTS Embed SAPI

From: Date: Mon, 16 Jan 2017 23:01:26 +0000
Subject: Bug #71129 [Com]: Segmentation fault on ZTS Embed SAPI
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206697@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71129&edit=1

 ID:                 71129
 Comment by:         ejrx7753 at gmail dot com
 Reported by:        maroszek at gmx dot net
 Summary:            Segmentation fault on ZTS Embed SAPI
 Status:             Re-Opened
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   OS X 10.11
 PHP Version:        7.0.0
 Block user comment: N
 Private report:     N

 New Comment:

Adding the lines

    php_embed_module.ub_write = php_embed_ub_write;
    php_embed_module.flush = php_embed_flush;

after

php_embed_init

works so long as nothing is done with the output. Uncommenting "std::cout << str;"
inside of php_embed_ub_write causes a segmentation fault "pointer being freed was not
allocated" reliably inside the shutdown executor.


Previous Comments:
------------------------------------------------------------------------
[2017-01-16 22:06:11] ejrx7753 at gmail dot com

Looking through the "php_embed_init" function, it is more or less exactly the same as the
code provided, with the clear exception of a few signalling changes.

In particular,

signal(SIGPIPE, SIG_IGN);

and

zend_signal_startup();

A minor difference is the code

  (void)ts_resource(0);
  ZEND_TSRMLS_CACHE_UPDATE();

and a malloc on ini_entries.

Does this not suggest that the embed module should get its own initializer, ie.
php_embed_init(&php_embed_module) to init the signals, or that embed_init() [no args} should be
created to run before sapi startup to call the private signalling code and whatever other steps will
arise?

------------------------------------------------------------------------
[2017-01-16 16:43:54] ejrx7753 at gmail dot com

Confirmed that using the code

    int argc2 = 1;
    char* text = "embed4";
    char *argv2[2] = { text, NULL };
    php_embed_init(argc2, argv2);

to replace sapi_startup and php_embed_module.startup and deleting the "php_embed_module"
struct (duplicate symbol error) allows the code to work.

I have created a sample file which can test both versions (http://pastebin.com/8sHjP9Jy).

When run with

#define TEST1 0

the test fails, but when run with

#define TEST1 1

it passses. In my case, the script was "echo 1" and proceeded to give an infinite loop of
1s to the std out. The question also needs addressing whether or not we can set the embed module
elements and use embed init. I think so, but it is another difference between the code peices.

------------------------------------------------------------------------
[2017-01-16 16:27:53] ejrx7753 at gmail dot com

I forgot to write the result -> "I tested the code sample" and found that it still
segfaults.

------------------------------------------------------------------------
[2017-01-16 16:26:03] ejrx7753 at gmail dot com

I have tested the code sample (https://gist.github.com/paresy/b4babb919a86e9764bc4) with OS X 10.12
and PHP 7.1.0, built with embed as a static library.

I posted previously another bug report (https://bugs.php.net/bug.php?id=73826) which might contain
some useful information because I was able to get ZTS working by a number of somewhat random steps.
To give a short summary, "php_embed_init" function works, but
"php_embed_module.startup" doesn't. It appears therefore to be some kind of
initialization process problem.

I tried "php_embed_module.ini_entries = "max_execution_time=0\n\0";" as
mentioned in this thread, but with a seg fault.

------------------------------------------------------------------------
[2016-07-21 07:24:48] davey@php.net

Closed accidentally. Reopening.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=71129


--
Edit this bug report at https://bugs.php.net/bug.php?id=71129&edit=1


Thread (32 messages)

« previous php.bugs (#206697) next »