Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault in extension's protect #181

Merged
merged 1 commit into from Jul 30, 2015
Merged

Fix segfault in extension's protect #181

merged 1 commit into from Jul 30, 2015

Conversation

jbboehr
Copy link
Contributor

@jbboehr jbboehr commented Jul 30, 2015

Fixes a segfault in the extension. The function being protected seems to need to have the refcount incremented.

php --version
PHP 5.5.9-1ubuntu4.11 (cli) (built: Jul  2 2015 15:23:08) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

tests/015.mem

==32129== Invalid read of size 1
==32129==    at 0x6DDE55: zval_call_destructor (zend_execute_API.c:203)
==32129==    by 0x6FBE63: zend_hash_reverse_apply (zend_hash.c:799)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)
==32129==    by 0x79EF49: do_cli (php_cli.c:1177)
==32129==    by 0x461E0F: main (php_cli.c:1378)
==32129==  Address 0x77d5b74 is 20 bytes inside a block of size 32 free'd
==32129==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32129==    by 0x750C508: pimple_bucket_dtor (pimple.c:490)
==32129==    by 0x6FB977: zend_hash_destroy (zend_hash.c:560)
==32129==    by 0x750CEE1: pimple_free_object_storage (pimple.c:189)
==32129==    by 0x715E3B: zend_objects_store_del_ref_by_handle_ex (zend_objects_API.c:226)
==32129==    by 0x715E62: zend_objects_store_del_ref (zend_objects_API.c:178)
==32129==    by 0x6DDEBF: _zval_ptr_dtor (zend_variables.h:35)
==32129==    by 0x6FA334: zend_hash_apply_deleter (zend_hash.c:650)
==32129==    by 0x6FBE78: zend_hash_reverse_apply (zend_hash.c:804)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)
==32129== 
==32129== Invalid read of size 4
==32129==    at 0x6DDE62: zval_call_destructor (zend_execute_API.c:203)
==32129==    by 0x6FBE63: zend_hash_reverse_apply (zend_hash.c:799)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)
==32129==    by 0x79EF49: do_cli (php_cli.c:1177)
==32129==    by 0x461E0F: main (php_cli.c:1378)
==32129==  Address 0x77d5b70 is 16 bytes inside a block of size 32 free'd
==32129==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32129==    by 0x750C508: pimple_bucket_dtor (pimple.c:490)
==32129==    by 0x6FB977: zend_hash_destroy (zend_hash.c:560)
==32129==    by 0x750CEE1: pimple_free_object_storage (pimple.c:189)
==32129==    by 0x715E3B: zend_objects_store_del_ref_by_handle_ex (zend_objects_API.c:226)
==32129==    by 0x715E62: zend_objects_store_del_ref (zend_objects_API.c:178)
==32129==    by 0x6DDEBF: _zval_ptr_dtor (zend_variables.h:35)
==32129==    by 0x6FA334: zend_hash_apply_deleter (zend_hash.c:650)
==32129==    by 0x6FBE78: zend_hash_reverse_apply (zend_hash.c:804)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)

@fabpot
Copy link
Member

fabpot commented Jul 30, 2015

ping @jpauli

@stof
Copy link
Contributor

stof commented Jul 30, 2015

shouldn't you decrement it somewhere too ?

@jpauli
Copy link

jpauli commented Jul 30, 2015

👍 merge it please

@fabpot fabpot merged commit 8476b1f into silexphp:master Jul 30, 2015
fabpot added a commit that referenced this pull request Jul 30, 2015
This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Fix segfault in extension's protect

Fixes a segfault in the extension. The function being protected seems to need to have the refcount incremented.

```
php --version
PHP 5.5.9-1ubuntu4.11 (cli) (built: Jul  2 2015 15:23:08)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
```

tests/015.mem
```
==32129== Invalid read of size 1
==32129==    at 0x6DDE55: zval_call_destructor (zend_execute_API.c:203)
==32129==    by 0x6FBE63: zend_hash_reverse_apply (zend_hash.c:799)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)
==32129==    by 0x79EF49: do_cli (php_cli.c:1177)
==32129==    by 0x461E0F: main (php_cli.c:1378)
==32129==  Address 0x77d5b74 is 20 bytes inside a block of size 32 free'd
==32129==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32129==    by 0x750C508: pimple_bucket_dtor (pimple.c:490)
==32129==    by 0x6FB977: zend_hash_destroy (zend_hash.c:560)
==32129==    by 0x750CEE1: pimple_free_object_storage (pimple.c:189)
==32129==    by 0x715E3B: zend_objects_store_del_ref_by_handle_ex (zend_objects_API.c:226)
==32129==    by 0x715E62: zend_objects_store_del_ref (zend_objects_API.c:178)
==32129==    by 0x6DDEBF: _zval_ptr_dtor (zend_variables.h:35)
==32129==    by 0x6FA334: zend_hash_apply_deleter (zend_hash.c:650)
==32129==    by 0x6FBE78: zend_hash_reverse_apply (zend_hash.c:804)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)
==32129==
==32129== Invalid read of size 4
==32129==    at 0x6DDE62: zval_call_destructor (zend_execute_API.c:203)
==32129==    by 0x6FBE63: zend_hash_reverse_apply (zend_hash.c:799)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)
==32129==    by 0x79EF49: do_cli (php_cli.c:1177)
==32129==    by 0x461E0F: main (php_cli.c:1378)
==32129==  Address 0x77d5b70 is 16 bytes inside a block of size 32 free'd
==32129==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==32129==    by 0x750C508: pimple_bucket_dtor (pimple.c:490)
==32129==    by 0x6FB977: zend_hash_destroy (zend_hash.c:560)
==32129==    by 0x750CEE1: pimple_free_object_storage (pimple.c:189)
==32129==    by 0x715E3B: zend_objects_store_del_ref_by_handle_ex (zend_objects_API.c:226)
==32129==    by 0x715E62: zend_objects_store_del_ref (zend_objects_API.c:178)
==32129==    by 0x6DDEBF: _zval_ptr_dtor (zend_variables.h:35)
==32129==    by 0x6FA334: zend_hash_apply_deleter (zend_hash.c:650)
==32129==    by 0x6FBE78: zend_hash_reverse_apply (zend_hash.c:804)
==32129==    by 0x6DE290: shutdown_destructors (zend_execute_API.c:217)
==32129==    by 0x6EDD23: zend_call_destructors (zend.c:919)
==32129==    by 0x68E2A4: php_request_shutdown (main.c:1750)

```

Commits
-------

8476b1f Fix segfault in extension's protect
@fabpot
Copy link
Member

fabpot commented Jul 30, 2015

Thanks you @jbboehr

@stof
Copy link
Contributor

stof commented Jul 30, 2015

@jpauli what about my comment ?

@jpauli
Copy link

jpauli commented Jul 30, 2015

Refcount is already decremented in destructor, an addref was missing though

@jbboehr jbboehr deleted the ext-protect-fix branch July 30, 2015 16:19
@jbboehr
Copy link
Contributor Author

jbboehr commented Jul 30, 2015

I'm guessing this probably fixes #177 and #148

@jpauli
Copy link

jpauli commented Jul 30, 2015

Yes, same bug

glensc added a commit to pld-linux/php-ext-pimple that referenced this pull request Jul 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants