Bug #71596 [NEW]: Segmentation fault on ZTS with date function (setlocale)

From: Date: Mon, 15 Feb 2016 09:38:38 +0000
Subject: Bug #71596 [NEW]: Segmentation fault on ZTS with date function (setlocale)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199223@lists.php.net to get a copy of this message
From: maroszek at gmx dot net Operating system: Windows PHP version: 7.0.3 Package: Date/time related Bug Type: Bug Bug description:Segmentation fault on ZTS with date function (setlocale) Description: ------------ Description: ------------ PHP 7 is current stable (Also reproducable with 5.6.18) PHP 7 is used as Embed (Also reproducable with 5.6.18) Visual Studio 2013 I build a simple example to demonstrate the threading problem. It crashes nearly instatly. Running only one thread works fine. Expected result: ---------------- No crash. Endless loop doing the work. Actual result: -------------- Crash. I attached a backtrace which shows the concurrent access to setlocale which causes the crash Test script: --------------- #include <stdio.h> #include <iostream> #include <thread> #include <main/php.h> #include <main/SAPI.h> #include <main/php_main.h> #include <main/php_variables.h> #include <main/php_ini.h> #include <zend_ini.h> #ifdef ZTS ZEND_TSRMLS_CACHE_EXTERN(); #endif zend_module_entry ips_module_entry = { STANDARD_MODULE_HEADER, "XYZ", NULL, NULL, NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; static size_t php_embed_read_post(char *str, size_t str_length) { return 0; } static char* php_embed_read_cookies() { return NULL; } static size_t php_embed_ub_write(const char *str, size_t str_length) { std::cout << str; return str_length; } static void php_embed_flush(void *server_context) { // } static void php_embed_send_header(sapi_header_struct *sapi_header, void *server_context) { // } static void php_embed_log_message(char *message) { fprintf(stderr, "%s\n", message); } static void php_embed_register_variables(zval *track_vars_array) { // } static int php_embed_startup(sapi_module_struct *sapi_module) { if (php_module_startup(sapi_module, NULL, 0) == FAILURE) { return FAILURE; } return SUCCESS; } sapi_module_struct php_embed_module = { "XYZ", /* name */ "PHP for XYZ", /* pretty name */ php_embed_startup, /* startup */ php_module_shutdown_wrapper, /* shutdown */ NULL, /* activate */ NULL, /* deactivate */ php_embed_ub_write, /* unbuffered write */ php_embed_flush, /* flush */ NULL, /* get uid */ NULL, /* getenv */ php_error, /* error handler */ NULL, /* header handler */ NULL, /* send headers handler */ php_embed_send_header, /* send header handler */ php_embed_read_post, /* read POST data */ php_embed_read_cookies, /* read Cookies */ php_embed_register_variables, /* register server variables */ php_embed_log_message, /* Log message */ NULL, /* Get request time */ NULL, /* Child terminate */ STANDARD_SAPI_MODULE_PROPERTIES }; int main(int argc, const char * argv[]) { tsrm_startup(128, 1, 0, NULL); sapi_startup(&php_embed_module); php_embed_module.ini_entries = "date.timezone=Europe/Berlin\n\0"; if (php_embed_module.startup(&php_embed_module) == FAILURE) { throw std::runtime_error("Could not start PHP!"); } for (int i = 0; i < 10; i++) { std::thread([&argv]{ ts_resource(0); while (true){ zend_file_handle file_handle; file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = "date.php"; file_handle.handle.fp = NULL; file_handle.opened_path = NULL; file_handle.free_filename = 0; if (php_request_startup() == FAILURE) { //std::cout << "ERR" << std::endl; php_request_shutdown(NULL); continue; } if (php_execute_script(&file_handle) == FAILURE) break; //std::cout << "RUN" << std::endl; php_request_shutdown(NULL); } std::cout << "DIED" << std::endl; }).detach(); } while (true); return 0; } -- Edit bug report at https://bugs.php.net/bug.php?id=71596&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71596&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71596&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71596&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71596&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71596&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71596&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71596&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71596&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71596&r=support Expected behavior: https://bugs.php.net/fix.php?id=71596&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71596&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71596&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71596&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71596&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71596&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71596&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71596&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71596&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71596&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71596&r=mysqlcfg

« previous php.bugs (#199223) next »