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
3 changes: 2 additions & 1 deletion ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,8 @@ PHP_FUNCTION(socket_recvfrom)

/* overflow check */
/* Shouldthrow ? */
if ((arg3 + 2) < 3) {

if (arg3 <= 0 || arg3 > ZEND_LONG_MAX - 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code also intended to disallow ZEND_LONG_MAX-1, not sure why. I think what you did is fine though.

RETURN_FALSE;
}

Expand Down
19 changes: 19 additions & 0 deletions ext/sockets/tests/socket_recv_overflow.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
socket_recvfrom overflow on length argument
--EXTENSIONS--
sockets
--SKIPIF--
<?php
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
die('skip not valid for Windows.');
}
--FILE--
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test fails on Windows, also a bit of a weird indentation: normally we don't indent tests outer scope?

Copy link
Member Author

@devnexen devnexen Oct 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that was just quick copy paste from my local messy test :)

$s = socket_create(AF_UNIX, SOCK_DGRAM, 0);
$buf = $end = "";
var_dump(socket_recvfrom($s, $buf, PHP_INT_MAX, 0, $end));
var_dump(socket_recvfrom($s, $buf, -1, 0, $end));
?>
--EXPECT--
bool(false)
bool(false)
Loading