php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50399 garbage collection crashes
Submitted: 2009-12-07 13:56 UTC Modified: 2009-12-07 20:12 UTC
From: ikickdogsforfun at hotmail dot com Assigned: dmitry (profile)
Status: Closed Package: Reproducible crash
PHP Version: 5.3.1 OS: Debian 5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ikickdogsforfun at hotmail dot com
New email:
PHP Version: OS:

 

 [2009-12-07 13:56 UTC] ikickdogsforfun at hotmail dot com
Description:
------------
When using PHP SAPI and values have been added to the global $_SERVER variable, shutdown segfaults in zend_gc. If I remove the setting of the global variables it doesn't seg fault.
This is possibly not a fault the SAPI, but I've been unable to resolve, removing the destroy and free commands in shutdown function doesn't stop it from segfaulting.

Reproduce code:
---------------
The entire source code file is available at https://crispycrisp.org/php.txt this is the function that causes a segfault in shutdown if it has been called:
void php_set_superglobal_server(char *name, char *val)
{
    zend_first_try {
		HashTable* locals = &EG(symbol_table);

        zval *type;

        /* Fetch $_SERVER from the global scope */
        zend_hash_find(locals, "_SERVER", sizeof("_SERVER"),
                                                     (void**)&SERVER);

        ALLOC_INIT_ZVAL(type);
        ZVAL_STRING(type, val, 1);
        ZEND_SET_SYMBOL(Z_ARRVAL_PP(SERVER), name, type);
    } zend_end_try();
}

Expected result:
----------------
No segfault

Actual result:
--------------
==17605== Thread 2:
==17605== Invalid read of size 4
==17605==    at 0x43B4BB9: gc_remove_zval_from_buffer (zend_gc.h:189)
==17605==    by 0x438E18F: _zval_ptr_dtor (zend_execute_API.c:434)
==17605==    by 0x43A4C7D: zend_hash_destroy (zend_hash.c:526)
==17605==    by 0x804A88A: php_shutdown (php.c:143)
==17605==    by 0x804A955: php (php.c:168)
==17605==    by 0x8049D94: parsing_request (handler.c:180)
==17605==    by 0x80496FE: handle (handler.c:25)
==17605==    by 0x4032F3A: start_thread (in /lib/libpthread-2.7.so)
==17605==    by 0x4793BED: clone (in /lib/libc-2.7.so)
==17605==  Address 0x1c is not stack'd, malloc'd or (recently) free'd
==17605==
==17605== Process terminating with default action of signal 11 (SIGSEGV)
==17605==  Access not within mapped region at address 0x1C
==17605==    at 0x43B4BB9: gc_remove_zval_from_buffer (zend_gc.h:189)
==17605==    by 0x438E18F: _zval_ptr_dtor (zend_execute_API.c:434)
==17605==    by 0x43A4C7D: zend_hash_destroy (zend_hash.c:526)
==17605==    by 0x804A88A: php_shutdown (php.c:143)
==17605==    by 0x804A955: php (php.c:168)
==17605==    by 0x8049D94: parsing_request (handler.c:180)
==17605==    by 0x80496FE: handle (handler.c:25)
==17605==    by 0x4032F3A: start_thread (in /lib/libpthread-2.7.so)
==17605==    by 0x4793BED: clone (in /lib/libc-2.7.so)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-07 14:20 UTC] pajoye@php.net
Can you try with:

zend.enable_gc=Off

In your php.ini please?
 [2009-12-07 15:28 UTC] ikickdogsforfun at hotmail dot com
I added that line to my php.ini and checked phpinfo(); which showed zend.gc=off
Still having the same problem I'm afraid and valgrind output shows segfault at the same location.
 [2009-12-07 15:33 UTC] pajoye@php.net
Dmitry, can you take a look at it pls?
 [2009-12-07 17:36 UTC] scottmac@php.net
Can you try using the following within php_set_superglobal_server as the way to modify the _SERVER value.

php_register_variable_ex("name", type, PG(http_globals)[TRACK_VARS_SERVER]);


Also you don't need to destroy the servers zval, it will be handled by php_embed_shutdown()
 [2009-12-07 18:46 UTC] jani@php.net
See also bug #50382
 [2009-12-07 20:11 UTC] ikickdogsforfun at hotmail dot com
Thanks guys that fixed it. I replaced:
ZEND_SET_SYMBOL(Z_ARRVAL_PP(SERVER), name, type);
with:
php_register_variable_ex(name, type, PG(http_globals)[TRACK_VARS_SERVER]);
No segfault. I assume that method is either incorrect or not properly supported via the embedded SAPI. Nevermind, fixed and I'll just replace the other methods with this method using the track vars :)
 [2009-12-07 20:12 UTC] ikickdogsforfun at hotmail dot com
Sorry, have to provide a comment to close ;)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC