Commit 4f4345df5c1 for php

commit 4f4345df5c1c10d7740e6ce12d94e21aeb28d7b8
Author: David Carlier <devnexen@gmail.com>
Date:   Wed Nov 18 18:25:03 2026 +0000

    Zend: ZEND_CLONE null dereference when the clone handler returns NULL.

    ZEND_CLONE stored the clone handler's return value unchecked. A handler
    that threw and returned NULL, as zend_ffi_free_clone_obj() does, left
    an IS_OBJECT result with a null pointer that ZEND_HANDLE_EXCEPTION
    released. The uri clone handler hit it once GH-25408 kept the opline of
    a delayed OOM, which caused its revert. The result is now left undefined.

    Close GH-25565

diff --git a/NEWS b/NEWS
index 58a922cb2f0..2f861f17f54 100644
--- a/NEWS
+++ b/NEWS
@@ -47,6 +47,8 @@ PHP                                                                        NEWS
     opcache preload). (sanklamm, lazerg)
   . Fixed NULL dereference at startup when the ini file found in the search
     path has an absolute path exceeding MAXPATHLEN. (Jorg Sowa)
+  . Fixed null dereference in ZEND_CLONE when the clone handler throws and
+    returns NULL. (David Carlier)

 - Curl:
   . Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 74d3a33f6cf..b199885ec82 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -6073,7 +6073,14 @@ ZEND_VM_COLD_CONST_HANDLER(110, ZEND_CLONE, CONST|TMPVAR|UNUSED|THIS|CV, ANY)
 		}
 	}

-	ZVAL_OBJ(EX_VAR(opline->result.var), clone_call(zobj));
+	zend_object *cloned = clone_call(zobj);
+	if (UNEXPECTED(!cloned)) {
+		ZEND_ASSERT(EG(exception));
+		FREE_OP1();
+		ZVAL_UNDEF(EX_VAR(opline->result.var));
+		HANDLE_EXCEPTION();
+	}
+	ZVAL_OBJ(EX_VAR(opline->result.var), cloned);

 	FREE_OP1();
 	ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index cb4520d8565..a1fcfe7edae 100644
Binary files a/Zend/zend_vm_execute.h and b/Zend/zend_vm_execute.h differ
diff --git a/ext/ffi/tests/clone_handler_returning_null.phpt b/ext/ffi/tests/clone_handler_returning_null.phpt
new file mode 100644
index 00000000000..bf68c5fc6db
--- /dev/null
+++ b/ext/ffi/tests/clone_handler_returning_null.phpt
@@ -0,0 +1,21 @@
+--TEST--
+clone of an object whose clone handler throws and returns NULL
+--EXTENSIONS--
+ffi
+--INI--
+ffi.enable=1
+--FILE--
+<?php
+$ffi = FFI::cdef();
+$p = $ffi->new("int[2]", false);
+FFI::free($p);
+try {
+    $q = clone $p;
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
+}
+echo "done", PHP_EOL;
+?>
+--EXPECT--
+FFI\Exception: Use after free()
+done