Skip to content

Commit 19ee3e6

Browse files
committed
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
1 parent 7c6f089 commit 19ee3e6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ PHP NEWS
3434
. Fixed bug GH-21055 (connection attribute status typo for GSS negotiation).
3535
(lsaos)
3636

37+
- Sockets:
38+
. Fixed bug GH-21161 (socket_set_option() crash with array 'addr'
39+
entry as null). (David Carlier)
40+
3741
- Windows:
3842
. Fixed compilation with clang (missing intrin.h include). (Kévin Dunglas)
3943

ext/sockets/conversions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static void from_zval_write_sin6_addr(const zval *zaddr_str, char *addr6, ser_co
611611
} else {
612612
/* error already emitted, but let's emit another more relevant */
613613
do_from_zval_err(ctx, "could not resolve address '%s' to get an AF_INET6 "
614-
"address", Z_STRVAL_P(zaddr_str));
614+
"address", ZSTR_VAL(addr_str));
615615
}
616616

617617
zend_tmp_string_release(tmp_addr_str);

ext/sockets/tests/gh21161.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-21161 (IPV6_PKTINFO socket option crash with null addr array entry)
3+
--EXTENSIONS--
4+
sockets
5+
--SKIPIF--
6+
<?php
7+
if (substr(PHP_OS, 0, 3) == 'WIN') {
8+
die('skip.. Not valid for Windows');
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
$sock = socket_create(AF_INET6, SOCK_DGRAM, 0);
14+
socket_set_option($sock, IPPROTO_IPV6, IPV6_PKTINFO, ['addr' => null, 'ifindex' => 0]);
15+
?>
16+
--EXPECTF--
17+
Warning: socket_set_option(): Host lookup failed [%i]: %s on line %d
18+
19+
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

0 commit comments

Comments
 (0)