Skip to content

Commit 15163de

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/sockets: socket_sendto() add max addr length control for AF_UNIX.
2 parents 6c8a71b + b6495c1 commit 15163de

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ext/sockets/sockets.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,12 @@ PHP_FUNCTION(socket_sendto)
17161716
switch (php_sock->type) {
17171717
case AF_UNIX:
17181718
memset(&s_un, 0, sizeof(s_un));
1719+
1720+
if (addr_len >= sizeof(s_un.sun_path)) {
1721+
zend_argument_value_error(5, "must be less than %d", sizeof(s_un.sun_path));
1722+
RETURN_THROWS();
1723+
}
1724+
17191725
s_un.sun_family = AF_UNIX;
17201726
snprintf(s_un.sun_path, sizeof(s_un.sun_path), "%s", ZSTR_VAL(addr));
17211727

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
socket_sendto() with AF_UNIX rejects address exceeding sun_path limit
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+
$socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
14+
if (!$socket) {
15+
die('Unable to create AF_UNIX socket');
16+
}
17+
18+
$long_addr = str_repeat('a', 512);
19+
20+
try {
21+
socket_sendto($socket, "data", 4, 0, $long_addr);
22+
} catch (\ValueError $e) {
23+
echo $e->getMessage() . PHP_EOL;
24+
}
25+
26+
socket_close($socket);
27+
?>
28+
--EXPECTF--
29+
socket_sendto(): Argument #5 ($address) must be less than %d

0 commit comments

Comments
 (0)