Commit:    42f91d6ac6e4c359313ddc90b86067ab9be6a80f
Author:    Xinchen Hui <larue...@php.net>         Thu, 23 Aug 2012 23:21:25 
+0800
Parents:   9a72b52a1f36d8eacf122d2bc52be6b792fbb18a
Branches:  PHP-5.4

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=42f91d6ac6e4c359313ddc90b86067ab9be6a80f

Log:
Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)

Bugs:
https://bugs.php.net/62904

Changed paths:
  M  NEWS
  M  ext/spl/spl_fixedarray.c
  A  ext/spl/tests/bug62904.phpt


Diff:
diff --git a/NEWS b/NEWS
index 4420988..b51f28e 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@ PHP                                                           
             NEWS
     when close handler call exit). (Laruence)
 
 - SPL:
+  . Fixed bug #62904 (Crash when cloning an object which inherits 
SplFixedArray)
+    (Laruence)
   . Implemented FR #62840 (Add sort flag to ArrayObject::ksort). (Laruence)
 
 - Standard:
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 1124285..244bd3e 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -223,10 +223,14 @@ static zend_object_value 
spl_fixedarray_object_new_ex(zend_class_entry *class_ty
        if (orig && clone_orig) {
                spl_fixedarray_object *other = 
(spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC);
                intern->ce_get_iterator = other->ce_get_iterator;
-
-               intern->array = emalloc(sizeof(spl_fixedarray));
-               spl_fixedarray_init(intern->array, other->array->size 
TSRMLS_CC);
-               spl_fixedarray_copy(intern->array, other->array TSRMLS_CC);
+               if (!other->array) {
+                       /* leave a empty object, will be dtor later by CLONE 
handler */
+                       zend_throw_exception(spl_ce_RuntimeException, "The 
instance wasn't initialized properly", 0 TSRMLS_CC);
+               } else {
+                       intern->array = emalloc(sizeof(spl_fixedarray));
+                       spl_fixedarray_init(intern->array, other->array->size 
TSRMLS_CC);
+                       spl_fixedarray_copy(intern->array, other->array 
TSRMLS_CC);
+               }
        }
 
        while (parent) {
diff --git a/ext/spl/tests/bug62904.phpt b/ext/spl/tests/bug62904.phpt
new file mode 100644
index 0000000..7e392da
--- /dev/null
+++ b/ext/spl/tests/bug62904.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #62904 (Crash when cloning an object which inherits SplFixedArray)
+--FILE--
+<?php
+
+class foo extends SplFixedArray {       
+    public function __construct($size) {
+    }
+}
+
+$x = new foo(2);
+
+try {
+    $z = clone $x;
+} catch (Exception $e) {
+    var_dump($e->getMessage());
+}
+--EXPECTF--
+string(40) "The instance wasn't initialized properly"


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to