]> granicus.if.org Git - php/commitdiff
Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
authorXinchen Hui <laruence@php.net>
Thu, 23 Aug 2012 15:21:25 +0000 (23:21 +0800)
committerXinchen Hui <laruence@php.net>
Thu, 23 Aug 2012 15:21:25 +0000 (23:21 +0800)
NEWS
ext/spl/spl_fixedarray.c
ext/spl/tests/bug62904.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 44209888394fd745449adf14ab41238af7b3d867..b51f28e821cb6cd3dbec8ab72b8601a8fd5cc980 100644 (file)
--- 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:
index 1124285545140aa4757c8ed88ceb6b197de0c1aa..244bd3e0df2bc00f1303823bdc1dde4dfab00bbc 100644 (file)
@@ -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 (file)
index 0000000..7e392da
--- /dev/null
@@ -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"