Skip to content
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
9 changes: 8 additions & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,14 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
}
internal_function->type = ZEND_INTERNAL_FUNCTION;
internal_function->module = EG(current_module);
internal_function->T = 0;
if (EG(active) && ZEND_OBSERVER_ENABLED) {
/* Add an observer temporary to store previous observed frames. This is
* normally handled by zend_observer_post_startup(), except for
* functions registered at runtime (EG(active)). */
internal_function->T = 1;
} else {
internal_function->T = 0;
}
memset(internal_function->reserved, 0, ZEND_MAX_RESERVED_RESOURCES * sizeof(void*));

while (ptr->fname) {
Expand Down
18 changes: 18 additions & 0 deletions ext/dl_test/dl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,27 @@ PHP_INI_BEGIN()
PHP_INI_END()
/* }}} */

PHP_METHOD(DlTest, test)
{
char *var = "World";
size_t var_len = sizeof("World") - 1;
zend_string *retval;

ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_STRING(var, var_len)
ZEND_PARSE_PARAMETERS_END();

retval = strpprintf(0, "Hello %s", var);

RETURN_STR(retval);
}

/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(dl_test)
{
register_class_DlTest();

/* Test backwards compatibility */
if (getenv("PHP_DL_TEST_USE_OLD_REGISTER_INI_ENTRIES")) {
zend_register_ini_entries(ini_entries, module_number);
Expand Down
4 changes: 4 additions & 0 deletions ext/dl_test/dl_test.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ function dl_test_test1(): void {}

function dl_test_test2(string $str = ""): string {}

class DlTest {
public function test(string $str = ""): string {}
}

/** @var int */
const DL_TEST_CONST = 42;
20 changes: 19 additions & 1 deletion ext/dl_test/dl_test_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
42 changes: 42 additions & 0 deletions ext/standard/tests/general_functions/gh17211.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
dl() / observer segfault
--EXTENSIONS--
zend_test
--SKIPIF--
<?php include dirname(__DIR__, 3) . "/dl_test/tests/skip.inc"; ?>
--INI--
zend_test.observer.enabled=1
zend_test.observer.observe_functions=1
zend_test.observer.show_output=1
--FILE--
<?php

if (PHP_OS_FAMILY === 'Windows') {
$loaded = dl('php_dl_test.dll');
} else {
$loaded = dl('dl_test.so');
}

var_dump(dl_test_test2("World!"));

$test = new DlTest();
var_dump($test->test("World!"));
?>
--EXPECTF--
<!-- init '%sgh17211.php' -->
<!-- init dl() -->
<dl>
</dl>
<!-- init dl_test_test2() -->
<dl_test_test2>
</dl_test_test2>
<!-- init var_dump() -->
<var_dump>
string(12) "Hello World!"
</var_dump>
<!-- init DlTest::test() -->
<DlTest::test>
</DlTest::test>
<var_dump>
string(12) "Hello World!"
</var_dump>
Loading