Commit 19ee3e6697d for php.net
commit 19ee3e6697d6f470df07f9b31fecd255f45e842f
Author: David Carlier <devnexen@gmail.com>
Date: Sun Feb 8 14:34:48 2026 +0000
Fix GH-21161: socket_set_option() crash with array 'addr' entry as null.
in the ipv6 address creation helper we need to use, for the error
message, the converted data rather than assuming the original
is a proper zend_string().
close GH-21166
diff --git a/NEWS b/NEWS
index cda0658d87c..10a3dd00f2f 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,10 @@ PHP NEWS
. Fixed bug GH-21055 (connection attribute status typo for GSS negotiation).
(lsaos)
+- Sockets:
+ . Fixed bug GH-21161 (socket_set_option() crash with array 'addr'
+ entry as null). (David Carlier)
+
- Windows:
. Fixed compilation with clang (missing intrin.h include). (Kévin Dunglas)
diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c
index 60ed970e896..a419a20c873 100644
--- a/ext/sockets/conversions.c
+++ b/ext/sockets/conversions.c
@@ -611,7 +611,7 @@ static void from_zval_write_sin6_addr(const zval *zaddr_str, char *addr6, ser_co
} else {
/* error already emitted, but let's emit another more relevant */
do_from_zval_err(ctx, "could not resolve address '%s' to get an AF_INET6 "
- "address", Z_STRVAL_P(zaddr_str));
+ "address", ZSTR_VAL(addr_str));
}
zend_tmp_string_release(tmp_addr_str);
diff --git a/ext/sockets/tests/gh21161.phpt b/ext/sockets/tests/gh21161.phpt
new file mode 100644
index 00000000000..8a3958a583d
--- /dev/null
+++ b/ext/sockets/tests/gh21161.phpt
@@ -0,0 +1,19 @@
+--TEST--
+GH-21161 (IPV6_PKTINFO socket option crash with null addr array entry)
+--EXTENSIONS--
+sockets
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip.. Not valid for Windows');
+}
+?>
+--FILE--
+<?php
+$sock = socket_create(AF_INET6, SOCK_DGRAM, 0);
+socket_set_option($sock, IPPROTO_IPV6, IPV6_PKTINFO, ['addr' => null, 'ifindex' => 0]);
+?>
+--EXPECTF--
+Warning: socket_set_option(): Host lookup failed [%i]: %s on line %d
+
+Warning: socket_set_option(): error converting user data (path: in6_pktinfo > addr): could not resolve address '' to get an AF_INET6 address in %s on line %d