Memory corruption in midgard-php

Posted on 2008-01-18 12:00:11 EET.

Just two days ago I blamed Suhosin patch, and this morning I found probably the source of the problem.

Log entry is clear:

PHP Fatal error:  Cannot instantiate abstract class \x85\xd7\xe9\x84\x1d

I found that mgd_get_object_by_guid is not aware of Zend2 (PHP5), and code "focuses" on Zend1 (PHP4). I can not say that code uses ZE1 or ZE2 API. The issue is hard to find and it's never noticed when code is being compiled.

If you need to write code for ZE1 and ZE2, keep it in mind:

ZE1: zend_class_entry *ce;
object_init_ex(return_value, ce TSRMLS_CC);

ZE2: zend_class_entry **ce;
object_init_ex(return_value, *ce TSRMLS_CC);

But when you look for class pointer you always pass (void **) &ce) as zend_hash_find parameter. So when you use ZE1 class pointer and code is being compiled against ZE2, you get no single notice or warning. And it's very easy to omit such case, especially that code itself runs almost correctly. Almost means that sometimes it fails.

I will make 1.8.6 release next week because the issue is very serious. Meantime if you used to notice random Segfaults in error.log, please change your code and use ( recommended anyway ) midgard_object_class::get_object_by_guid instead of mgd_get_object_by_guid.

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS