]> granicus.if.org Git - php/commitdiff
Promote ArrayObject modification during sorting to Error exception
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 28 Aug 2020 08:42:14 +0000 (10:42 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 28 Aug 2020 08:42:14 +0000 (10:42 +0200)
ext/spl/spl_array.c
ext/spl/tests/ArrayObject_exchange_array_during_sorting.phpt
ext/spl/tests/bug67539.phpt

index e527f9e4f311ed92c113a590193c7cae4b0bc36d..e307177feaf19d2abc0abac1ef5e4d0bb78d4bff 100644 (file)
@@ -287,7 +287,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, spl_array_object *
        }
 
        if ((type == BP_VAR_W || type == BP_VAR_RW) && intern->nApplyCount > 0) {
-               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+               zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
                return &EG(error_zval);
        }
 
@@ -456,7 +456,7 @@ static void spl_array_write_dimension_ex(int check_inherited, zend_object *objec
        }
 
        if (intern->nApplyCount > 0) {
-               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+               zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
                return;
        }
 
@@ -524,7 +524,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec
        }
 
        if (intern->nApplyCount > 0) {
-               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+               zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
                return;
        }
 
@@ -1285,7 +1285,7 @@ PHP_METHOD(ArrayObject, exchangeArray)
        }
 
        if (intern->nApplyCount > 0) {
-               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+               zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
                return;
        }
 
@@ -1675,7 +1675,7 @@ PHP_METHOD(ArrayObject, unserialize)
        }
 
        if (intern->nApplyCount > 0) {
-               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+               zend_throw_error(NULL, "Modification of ArrayObject during sorting is prohibited");
                return;
        }
 
index 225d42c1ed030c443beda393058f98152d05d4dd..b563c2c84d08d3a874c24c7461d9c5d09796e6c8 100644 (file)
@@ -7,15 +7,19 @@ $ao = new ArrayObject([1, 2, 3]);
 $i = 0;
 $ao->uasort(function($a, $b) use ($ao, &$i) {
     if ($i++ == 0) {
-        $ao->exchangeArray([4, 5, 6]);
+        try {
+            $ao->exchangeArray([4, 5, 6]);
+        } catch (Error $e) {
+            echo $e->getMessage(), "\n";
+        }
         var_dump($ao);
     }
     return $a <=> $b;
 });
 
 ?>
---EXPECTF--
-Warning: Modification of ArrayObject during sorting is prohibited in %s on line %d
+--EXPECT--
+Modification of ArrayObject during sorting is prohibited
 object(ArrayObject)#1 (1) {
   ["storage":"ArrayObject":private]=>
   array(3) {
index 97d8199e48f6b987cbb0c56a31115172c1d85e5f..61f70cf459bdf21936f5fb00a39f8b496279a876 100644 (file)
@@ -6,11 +6,15 @@ Bug #67539 (ArrayIterator use-after-free due to object change during sorting)
 $it = new ArrayIterator(array_fill(0,2,'X'), 1 );
 
 function badsort($a, $b) {
+    try {
         $GLOBALS['it']->unserialize($GLOBALS['it']->serialize());
-        return 0;
+    } catch (Error $e) {
+        echo $e->getMessage(), "\n";
+    }
+    return 0;
 }
 
 $it->uksort('badsort');
 ?>
---EXPECTF--
-Warning: Modification of ArrayObject during sorting is prohibited in %sbug67539.php on line %d
+--EXPECT--
+Modification of ArrayObject during sorting is prohibited