#34810 [NEW]: mysqli::init() and others use wrong $this pointer without checks

2005-10-10 Thread antony at zend dot com
From: antony at zend dot com
Operating system: Linux
PHP version:  5.1.0RC1
PHP Bug Type: Reproducible crash
Bug description:  mysqli::init() and others use wrong $this pointer without 
checks

Description:

mysqli::init(), mysqli::connect() and mysqli_warning::__construct() use
wrong inherited $this pointer without checking if this_ptr really points
to the mysqli_object.
In particular conditions this can lead to segfault.

Reproduce code:
---
class DbConnection { 
private $link = NULL; 

public function connect() { 
$this-link = mysqli::init();
var_dump($this-link); 
} 
} 

$db = new DbConnection(); 
$db-connect();

Actual result:
--
*** glibc detected *** free(): invalid pointer: 0xbfffece4 ***

Program received signal SIGABRT, Aborted.
[Switching to Thread 1076990336 (LWP 24078)]
0xe410 in ?? ()
(gdb) bt
#0  0xe410 in ?? ()
#1  0xbfffe224 in ?? ()
#2  0x0006 in ?? ()
#3  0x5e0e in ?? ()
#4  0x400ec2c1 in raise () from /lib/tls/libc.so.6
#5  0x400edb75 in abort () from /lib/tls/libc.so.6
#6  0x401207aa in __libc_message () from /lib/tls/libc.so.6
#7  0x40126007 in malloc_printerr () from /lib/tls/libc.so.6
#8  0x401276cb in free () from /lib/tls/libc.so.6
#9  0x080c1364 in mysqli_objects_destroy_object (object=0x85585a8,
handle=3) at /usr/src/dev/orig/php-src_5_1/ext/mysqli/mysqli.c:152
#10 0x0826ed46 in zend_objects_store_call_destructors (objects=0x84b36ec)
at /usr/src/dev/orig/php-src_5_1/Zend/zend_objects_API.c:55
#11 0x08249416 in shutdown_destructors () at
/usr/src/dev/orig/php-src_5_1/Zend/zend_execute_API.c:190
#12 0x082559a6 in zend_call_destructors () at
/usr/src/dev/orig/php-src_5_1/Zend/zend.c:817
#13 0x08214b38 in php_request_shutdown (dummy=0x0) at
/usr/src/dev/orig/php-src_5_1/main/main.c:1210
#14 0x082c1093 in main (argc=2, argv=0xbfffefb4) at
/usr/src/dev/orig/php-src_5_1/sapi/cli/php_cli.c:1142


-- 
Edit bug report at http://bugs.php.net/?id=34810edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=34810r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=34810r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=34810r=trysnapshot51
Fixed in CVS:http://bugs.php.net/fix.php?id=34810r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=34810r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=34810r=needtrace
Need Reproduce Script:   http://bugs.php.net/fix.php?id=34810r=needscript
Try newer version:   http://bugs.php.net/fix.php?id=34810r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34810r=support
Expected behavior:   http://bugs.php.net/fix.php?id=34810r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=34810r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=34810r=submittedtwice
register_globals:http://bugs.php.net/fix.php?id=34810r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=34810r=php3
Daylight Savings:http://bugs.php.net/fix.php?id=34810r=dst
IIS Stability:   http://bugs.php.net/fix.php?id=34810r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34810r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=34810r=float
No Zend Extensions:  http://bugs.php.net/fix.php?id=34810r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=34810r=mysqlcfg


#33389 [NEW]: double free() when exporting a ReflectionClass

2005-06-17 Thread antony at zend dot com
From: antony at zend dot com
Operating system: Linux
PHP version:  5CVS-2005-06-18 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description:  double free() when exporting a ReflectionClass

Description:

Memory related errors while freeing resources after export()ing certain
ReflectionClass object.
Tested with latest 5.1-CVS and 5.0.5-CVS.
See details below.

Reproduce code:
---
?php
class Test {
function foo($arg2=false) {
}
function bar() {
}
}

Reflection::export(new ReflectionClass('Test'));
?

Expected result:

.

Actual result:
--
With Zend MM enabled:

Warning: String is not zero-terminated (Z*Z*) (source:
/usr/src/dev/php-src_head/Zend/zend_variables.h:35) in Unknown on line 0
[Sat Jun 18 02:20:58 2005]  Script:  'index.php'
---
/usr/src/dev/php-src_head/Zend/zend_variables.h(35) : Block 0x0845EAE8
status:
/usr/src/dev/php-src_head/Zend/zend_variables.c(36) : Actual location
(location was relayed)
Beginning:  Cached (allocated on
/usr/src/dev/php-src_head/Zend/zend.c:205, 1 bytes)
  End:  OK
---

With Zend MM disabled:

Warning: String is not zero-terminated #65533;#65533;@) (source:
/usr/src/dev/clean/php-src_head/Zend/zend_variables.h:35) in Unknown on
line 0
*** glibc detected *** double free or corruption (!prev): 0x08382470 ***

Valgrind output:

==17469== Invalid read of size 1
==17469==at 0x81AC287: _zval_dtor_func (zend_variables.c:35)
==17469==by 0x81A5ED0: _zval_dtor (zend_variables.h:35)
==17469==by 0x81A58B4: destroy_op_array (zend_opcode.c:236)
==17469==by 0x81A54ED: destroy_zend_function (zend_opcode.c:109)
==17469==by 0x81A5503: zend_function_dtor (zend_opcode.c:121)
==17469==by 0x81B4FCB: zend_hash_destroy (zend_hash.c:519)
==17469==by 0x81A5628: destroy_zend_class (zend_opcode.c:164)
==17469==by 0x81B4F05: zend_hash_del_key_or_index (zend_hash.c:490)
==17469==by 0x81B55C6: zend_hash_reverse_apply (zend_hash.c:736)
==17469==by 0x81A1828: shutdown_executor (zend_execute_API.c:264)
==17469==  Address 0x1BDA99C5 is 5 bytes inside a block of size 6 free'd
==17469==at 0x1B9060B1: free (in
/usr/lib/valgrind/vgpreload_memcheck.so)
==17469==by 0x81A1DBD: zval_update_constant (zend_execute_API.c:442)
==17469==by 0x81C76D9: _parameter_string (zend_reflection_api.c:565)
==17469==by 0x81C7884: _function_parameter_string
(zend_reflection_api.c:601)
==17469==by 0x81C7B39: _function_string (zend_reflection_api.c:670)
==17469==by 0x81C741D: _class_string (zend_reflection_api.c:486)
==17469==by 0x81CC8FF: zif_reflection_class___toString
(zend_reflection_api.c:2477)
==17469==by 0x81A31BE: zend_call_function (zend_execute_API.c:867)
==17469==by 0x81A2279: call_user_function_ex (zend_execute_API.c:555)
==17469==by 0x81C8E62: zif_reflection_export
(zend_reflection_api.c:1127)
==17469==
==17469== Invalid free() / delete / delete[]
==17469==at 0x1B9060B1: free (in
/usr/lib/valgrind/vgpreload_memcheck.so)
==17469==by 0x81AC2BD: _zval_dtor_func (zend_variables.c:36)
==17469==by 0x81A5ED0: _zval_dtor (zend_variables.h:35)
==17469==by 0x81A58B4: destroy_op_array (zend_opcode.c:236)
==17469==by 0x81A54ED: destroy_zend_function (zend_opcode.c:109)
==17469==by 0x81A5503: zend_function_dtor (zend_opcode.c:121)
==17469==by 0x81B4FCB: zend_hash_destroy (zend_hash.c:519)
==17469==by 0x81A5628: destroy_zend_class (zend_opcode.c:164)
==17469==by 0x81B4F05: zend_hash_del_key_or_index (zend_hash.c:490)
==17469==by 0x81B55C6: zend_hash_reverse_apply (zend_hash.c:736)
==17469==  Address 0x1BDA99C0 is 0 bytes inside a block of size 6 free'd
==17469==at 0x1B9060B1: free (in
/usr/lib/valgrind/vgpreload_memcheck.so)
==17469==by 0x81A1DBD: zval_update_constant (zend_execute_API.c:442)
==17469==by 0x81C76D9: _parameter_string (zend_reflection_api.c:565)
==17469==by 0x81C7884: _function_parameter_string
(zend_reflection_api.c:601)
==17469==by 0x81C7B39: _function_string (zend_reflection_api.c:670)
==17469==by 0x81C741D: _class_string (zend_reflection_api.c:486)
==17469==by 0x81CC8FF: zif_reflection_class___toString
(zend_reflection_api.c:2477)
==17469==by 0x81A31BE: zend_call_function (zend_execute_API.c:867)
==17469==by 0x81A2279: call_user_function_ex (zend_execute_API.c:555)
==17469==by 0x81C8E62: zif_reflection_export
(zend_reflection_api.c:1127)



-- 
Edit bug report at http://bugs.php.net/?id=33389edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=33389r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=33389r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=33389r=trysnapshot51
Fixed in CVS:http://bugs.php.net/fix.php?id=33389r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=33389r