Skip to content

Conversation

@devnexen
Copy link
Member

No description provided.

@devnexen devnexen marked this pull request as ready for review November 28, 2025 20:26
@devnexen devnexen requested a review from bukka as a code owner November 28, 2025 20:26
@devnexen devnexen linked an issue Nov 28, 2025 that may be closed by this pull request
struct timeval *timeout)
{
gettimeofday(limit_time, NULL);
const double timeoutmax = (double) PHP_TIMEOUT_ULL_MAX / 1000000.0;
Copy link
Member

Choose a reason for hiding this comment

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

I'm just checking the whole logic here and I wonder why PHP_TIMEOUT_ULL_MAX is unsigned int 64? The time_t is signed int 64 (or 32 on 32bit arch) if I'm not mistakend. And in this case this is later converted to int (see php_pollfd_for and mainly php_tvtoto). So what am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it s unsigned but my sense since it s that way because this constant is never used directly but converted from microseconds value to seconds (so yes unsigned int64 > double > time_t or int).

Copy link
Member

@bukka bukka Nov 30, 2025

Choose a reason for hiding this comment

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

But how is this covering the lower type overflows? I mean if it gets converted in php_tvtoto, then it will still overflow on conversion to int, right?

main/network.c Outdated
gettimeofday(limit_time, NULL);
const double timeoutmax = (double) PHP_TIMEOUT_ULL_MAX / 1000000.0;

if (limit_time->tv_sec > (timeoutmax - timeout->tv_sec)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't that be be >=?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes it should

main/network.c Outdated
php_network_set_limit_time(&limit_time, &working_timeout);
if (UNEXPECTED(php_network_set_limit_time(&limit_time, &working_timeout) == FAILURE)) {
php_network_freeaddresses(psal);
zend_value_error("timeout value overflow");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about throwing error here even though it already triggers normal errors in some cases.

Why is this even checked here and not in the actual function as it has been case before?

main/network.c Outdated
Comment on lines 324 to 327
if (limit_time->tv_sec >= (timeoutmax - timeout->tv_sec)) {
zend_value_error("timeout value overflow");
return FAILURE;
}
Copy link
Member

Choose a reason for hiding this comment

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

I would rather have this be an assertion and make it the responsibility of the calling code to ensure this is respected. So move the check to ftp_connect(), especially as you get better error messages and you can pin point to the exact argument is causing an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok done, note that I purposely kept separated the check for <= 0 and the new one since it s stable branch.

Comment on lines 863 to 868
#if HAVE_GETTIMEOFDAY
php_network_set_limit_time(&limit_time, &working_timeout);
if (UNEXPECTED(php_network_set_limit_time(&limit_time, &working_timeout) == FAILURE)) {
php_network_freeaddresses(psal);
return -1;
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines 401 to 407
#if HAVE_GETTIMEOFDAY
php_network_set_limit_time(&limit_time, &working_timeout);
if (UNEXPECTED(php_network_set_limit_time(&limit_time, &working_timeout) == FAILURE)) {
error = ERANGE;
ret = -1;
goto ok;
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines +5 to +9
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip: 64-bit only");
if (PHP_OS_FAMILY === 'Windows') die("skip not for windows");
?>
Copy link
Member

Choose a reason for hiding this comment

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

This an issue that cannot appear on 32 bit nor Windows?

Copy link
Member Author

@devnexen devnexen Nov 29, 2025

Choose a reason for hiding this comment

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

yes this test "failed" for both earlier.

Copy link
Member

Choose a reason for hiding this comment

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

Alright

@devnexen devnexen closed this in 4312a44 Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

integer overflow in network.c

3 participants