fate0 / xmark

A PHP7 extension that can hook most functions/classes and parts of opcodes
BSD 3-Clause "New" or "Revised" License
239 stars 32 forks source link

xmark rename_class后 类的部分属性无法访问 #5

Closed hex0wn closed 5 years ago

hex0wn commented 5 years ago

配置好prvd后发现数据库的server_info属性无法获取到,并且打印link时会触发段错误

php > $link = new prvd_mysqli('localhost','root','123456');
php > var_dump($link->server_info);
NULL
php > var_dump($link);
Segmentation fault

xmark配置如下:

xmark.rename_classes = "
    SQLite3:prvd_SQLite3,
    mysqli:prvd_mysqli,
    PDO:prvd_PDO,
"
fate0 commented 5 years ago

原因是在 mysqli 扩展中会以 class name 作为 key 存储部分 properties

REGISTER_MYSQLI_CLASS_ENTRY("mysqli_driver", mysqli_driver_class_entry, mysqli_driver_methods);
    ce = mysqli_driver_class_entry;
    zend_hash_init(&mysqli_driver_properties, 0, NULL, free_prop_handler, 1);
    MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
    zend_declare_property_null(ce, "client_info",       sizeof("client_info") - 1, ZEND_ACC_PUBLIC);
    zend_declare_property_null(ce, "client_version",    sizeof("client_version") - 1, ZEND_ACC_PUBLIC);
    zend_declare_property_null(ce, "driver_version",    sizeof("driver_version") - 1, ZEND_ACC_PUBLIC);
    zend_declare_property_null(ce, "embedded",          sizeof("embedded") - 1, ZEND_ACC_PUBLIC);
    zend_declare_property_null(ce, "reconnect",         sizeof("reconnect") - 1, ZEND_ACC_PUBLIC);
    zend_declare_property_null(ce, "report_mode",       sizeof("report_mode") - 1, ZEND_ACC_PUBLIC);
    ce->ce_flags |= ZEND_ACC_FINAL;
    zend_hash_add_ptr(&classes, ce->name, &mysqli_driver_properties);

因为之前修复和 opcache 冲突的 bug #3 所以选择了既更改了 hash 表内的 key 名字,也更改了 functions/classes 内部的名字,这里需要考虑以下如何修复。。。

fate0 commented 5 years ago

简单过了一下 opcache 扩展,应该不需要修改 ce->name,所以将之前的修过给删除了,目前应该没有问题了,@hex0wn 感谢提交 issue,如果还有问题可以继续提交。