2010-10-12 51 views
2

我正在開發自己的PHP擴展,其中有一個類。我最近從Ubuntu 9.04升級到9.10,擴展功能破裂了。我自從嘗試更新到10.04,看看它是否修復它,因爲我的開發環境是10.04,它在那裏工作正常。從我能理解的唯一的主要區別是服務器是64位和我的筆記本電腦32位體系結構。我有PHP版本5.3.2-1ubuntu4.5(Zend build 20090626)。Segfault實例化類中的自定義PHP擴展C

我試圖運行我的測試PHP文件:

 
<?php 
$server = "http://localhost/"; 
$port = 1214; 
$f = new PPKeyClient($server, $port); 
var_dump($f); 

在GDB:

 
[email protected]:/etc/php5/conf.d# gdb php 
GNU gdb (GDB) 7.1-ubuntu 
Copyright (C) 2010 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "x86_64-linux-gnu". 
For bug reporting instructions, please see: 
... 
Reading symbols from /usr/bin/php...Reading symbols from /usr/lib/debug/usr/bin/php5...done. 
done. 
(gdb) run -f /var/www/test.php 
Starting program: /usr/bin/php -f /var/www/test.php 
[Thread debugging using libthread_db enabled] 
[New Thread 0x7fffef15b710 (LWP 9228)] 
[Thread 0x7fffef15b710 (LWP 9228) exited] 
1 
Program received signal SIGSEGV, Segmentation fault. 
0x00000000006e7767 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fff00000000) 
    at /build/buildd/php5-5.3.2/Zend/zend_vm_execute.h:371 
371 /build/buildd/php5-5.3.2/Zend/zend_vm_execute.h: No such file or directory. 
in /build/buildd/php5-5.3.2/Zend/zend_vm_execute.h 
(gdb) bt 
#0 0x00000000006e7767 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fff00000000) 
    at /build/buildd/php5-5.3.2/Zend/zend_vm_execute.h:371 
#1 0x00000000006bec20 in execute (op_array=0xfef1b0) at /build/buildd/php5-5.3.2/Zend/zend_vm_execute.h:104 
#2 0x000000000069694d in zend_execute_scripts (type=0, retval=0x7fffffffbf90, file_count=3) 
    at /build/buildd/php5-5.3.2/Zend/zend.c:1266 
#3 0x0000000000642598 in php_execute_script (primary_file=0x2) at /build/buildd/php5-5.3.2/main/main.c:2288 
#4 0x0000000000727a56 in main (argc=0, argv=0x1) at /build/buildd/php5-5.3.2/sapi/cli/php_cli.c:1196 
(gdb) 

而且從擴展相關位:

 
PHP_MINIT_FUNCTION(pp) 
{ 
     // Register PPKeyClient class 
     zend_class_entry ce; 
     INIT_CLASS_ENTRY(ce, "PPKeyClient", pp_functions); 
     PPKeyClient_ce = zend_register_internal_class(&ce TSRMLS_CC); 
     PPKeyClient_ce->create_object = PPKeyClient_object_new; 
     memcpy(&PPKeyClient_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 
     PPKeyClient_handlers.clone_obj = NULL; 
     return SUCCESS; 
} 

zend_object_value PPKeyClient_object_new(zend_class_entry *ce TSRMLS_DC) 
{ 
     zend_object_value retval; 
     PPKeyClient_object *intern; 

     // TODO - only instantiate look at 
     // http://stackoverflow.com/questions/1906565/php-extension-library-accessing-php-superglobals 
     // or google for http://www.google.co.uk/search?hl=en&safe=off&q=superglobals+in+php+extensions&aq=f&aqi=&aql=&oq=&gs_rfai= 

     intern = ecalloc(1, sizeof(PPKeyClient_object)); 
     zend_object_std_init(&(intern->std), ce TSRMLS_CC); 
     zend_hash_copy(intern->std.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); 

     intern->last_curl_result = PPKC_NO_REQUEST; 

     retval.handle = zend_objects_store_put(intern, PPKeyClient_object_dtor, NULL, NULL TSRMLS_CC); 
     retval.handlers = &PPKeyClient_handlers; 
     return retval; 
} 

PHP_METHOD(PPKeyClient, __construct) 
{ 
     PPKeyClient_object *intern; 
     char *url, *ssl_ca_crt = NULL; 
     int port = 80, url_len, ssl_ca_crt_len = 0, ua_len = 0; 

     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &url, &url_len, &port, &ssl_ca_crt, &ssl_ca_crt_len) == SUCCES$ 
     { 
       intern = (PPKeyClient_object*)zend_object_store_get_object(getThis() TSRMLS_CC); 
//    intern->port = port; 

//    intern->baseurl = estrndup(url, url_len); 
//    intern->baseurl_len = url_len; 
//    intern->ssl_ca_crt = estrndup(ssl_ca_crt, ssl_ca_crt_len); 
//    intern->ssl_ca_crt_len = ssl_ca_crt_len; 
//    intern->useragent = "PP KeyClient (PPExt#" PHP_PRIVATE_PASSWORDS_EXTNAME " v" PHP_PRIVATE_PASSWORDS_VERSION ")"; 
     } 
} 

我知道,在註釋中intern = (PPKeyClient_object*)zend_object_store_get_object...行使它的工作,但顯然我不能設置從構造函數的值沒有臨時工噸。

我很失落,並會感謝任何幫助發現什麼!

+0

指針在32位系統上長4個字節,在64位系統上長8個。 – SlappyTheFish 2011-02-16 11:02:52

回答

0

我完全記不清我是如何解決這個問題的 - 我認爲@SlappyTheFish是正確的 - 與64 bitness有關。我後來重新安裝服務器爲32位,我相信修復它,所以基本上這個問題沒有解決,但我解決了它。

0

只見帶來了libsafe安裝了一些Ubuntu的版本中,如果是這樣與Ubuntu 9.04的情況下,也許錯誤一直存在......

這是因爲libsafe的可以「避免」一些緩衝區溢出,雙自由一些其他的錯誤。

我不熟悉PHP擴展...... getThis()是PHP API的一個函數還是你的?如果這是你的,你可以發送它?

+1

哦,這是舊的... – Fernando 2011-02-17 02:33:29