PHP kernel Bugs: Dynamic Link-compiled extensions that extend global space dtor lead to core dump

Source: Internet
Author: User
Tags extend

The global Space code for registering extensions is as follows:

#ifdef zts ts_allocate_id (&sample_globals_id, sizeof (Zend_sample_globals), (ts_allocate_ctor) Zend_module_ Globals_ctor_n (sample), (Ts_allocate_dtor) zend_module_globals_dtor_n (sample); #else Sample_globals_ctor (& Sample_globals tsrmls_cc); #endif

In the ts_allocate_id () function call, a record is written to the resource_types_table array.

In the process of Tsrm_shutdown (), the registered Dtor callback function is invoked.

But after I've coded the book, I'll run the test code with Coredump.

Following the discovery, the Dl_unload (Module->handle) has been called on the module during the Zend_shutdown () call process. The handle that was registered at that time (Dtor) was not accessible when executing tsrm_shutdown ().

At the same time, see the ext/standard/file.c in the standard extension also has this kind of registration method to use, however, it should be statically compiled so there is no problem. And my extension is compiled. So dynamic link.

The following is the call path to trace Zend_shutdown () eventually to Dl_unload ().

Zend_shutdown () => zend_desctroy_modules () => Zend_hash_graceful_reverse_destroy () => zend_hash_apply_ Deleter () => module_destructor () => dl_unload ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.