Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from php:master #181

Merged
merged 4 commits into from
Dec 21, 2024
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ PHP NEWS
(David Carlier)
. Added TCP_FUNCTION_BLK to change the TCP stack algorithm on FreeBSD.
(David Carlier)
. socket_set_option() catches possible overflow with SO_RCVTIMEO/SO_SNDTIMEO
with timeout setting on windows. (David Carlier)

- Standard:
. Fixed crypt() tests on musl when using --with-external-libcrypt
Expand Down
22 changes: 22 additions & 0 deletions Zend/tests/named_params/gh17216.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-17216 (Trampoline crash on error)
--FILE--
<?php
class TrampolineTest {
public function __call(string $name, array $arguments) {
var_dump($name, $arguments);
}
}
$o = new TrampolineTest();
$callback = [$o, 'trampoline'];
$array = ["a" => "b", 1];
try {
forward_static_call_array($callback, $array);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
echo "Done\n";
?>
--EXPECT--
Cannot use positional argument after named argument
Done
4 changes: 4 additions & 0 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,11 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
ZEND_CALL_NUM_ARGS(call) = i;
cleanup_args:
zend_vm_stack_free_args(call);
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
zend_free_extra_named_params(call->extra_named_params);
}
zend_vm_stack_free_call_frame(call);
zend_release_fcall_info_cache(fci_cache);
return SUCCESS;
}
}
Expand Down
35 changes: 25 additions & 10 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,8 @@ PHP_FUNCTION(socket_get_option)
struct timeval tv;
#ifdef PHP_WIN32
DWORD timeout = 0;
#else
struct timeval timeout;
#endif
socklen_t optlen;
php_socket *php_sock;
Expand Down Expand Up @@ -1749,23 +1751,19 @@ PHP_FUNCTION(socket_get_option)

case SO_RCVTIMEO:
case SO_SNDTIMEO:
#ifndef PHP_WIN32
optlen = sizeof(tv);

if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&tv, &optlen) != 0) {
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
RETURN_FALSE;
}
#else
optlen = sizeof(timeout);

if (getsockopt(php_sock->bsd_socket, level, optname, (char*)&timeout, &optlen) != 0) {
PHP_SOCKET_ERROR(php_sock, "Unable to retrieve socket option", errno);
RETURN_FALSE;
}

#ifndef PHP_WIN32
tv.tv_sec = timeout.tv_sec;
tv.tv_usec = timeout.tv_usec;
#else
tv.tv_sec = timeout ? (long)(timeout / 1000) : 0;
tv.tv_usec = timeout ? (long)((timeout * 1000) % 1000000) : 0;
tv.tv_usec = timeout ? (long)((timeout % 1000) * 1000) : 0;
#endif

array_init(return_value);
Expand Down Expand Up @@ -2046,7 +2044,24 @@ PHP_FUNCTION(socket_set_option)
optlen = sizeof(tv);
opt_ptr = &tv;
#else
timeout = Z_LVAL_P(sec) * 1000 + Z_LVAL_P(usec) / 1000;
if (valsec < 0 || valsec > ULONG_MAX / 1000) {
zend_argument_value_error(4, "\"%s\" must be between 0 and %u", sec_key, (ULONG_MAX / 1000));
RETURN_THROWS();
}

timeout = valsec * 1000;


/*
* We deliberately throw if (valusec / 1000) > ULONG_MAX, treating it as a programmer error.
* On Windows, ULONG_MAX = 2^32, unlike ZEND_LONG_MAX = 2^63.
*/
if (valusec < 0 || timeout > ULONG_MAX - (valusec / 1000)) {
zend_argument_value_error(4, "\"%s\" must be between 0 and %u", usec_key, (DWORD)(ULONG_MAX - (valusec / 1000)));
RETURN_THROWS();
}

timeout += valusec / 1000;
optlen = sizeof(timeout);
opt_ptr = &timeout;
#endif
Expand Down
Loading