Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,12 @@ PHP_FUNCTION(socket_sendto)
switch (php_sock->type) {
case AF_UNIX:
memset(&s_un, 0, sizeof(s_un));

if (addr_len >= sizeof(s_un.sun_path)) {
zend_argument_value_error(5, "must be less than %d", sizeof(s_un.sun_path));
RETURN_THROWS();
}

s_un.sun_family = AF_UNIX;
snprintf(s_un.sun_path, sizeof(s_un.sun_path), "%s", addr);

Expand Down
29 changes: 29 additions & 0 deletions ext/sockets/tests/socket_sendto_unix_addr_too_long.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
socket_sendto() with AF_UNIX rejects address exceeding sun_path limit
--EXTENSIONS--
sockets
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip not valid for Windows');
}
?>
--FILE--
<?php
$socket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
if (!$socket) {
die('Unable to create AF_UNIX socket');
}

$long_addr = str_repeat('a', 512);

try {
socket_sendto($socket, "data", 4, 0, $long_addr);
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}

socket_close($socket);
?>
--EXPECTF--
socket_sendto(): Argument #5 ($address) must be less than %d
Loading