Skip to content

Restrict range of buffer_length on all platforms to INT_MAX #9126

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

Closed
wants to merge 3 commits into from
Closed
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
11 changes: 5 additions & 6 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7642,14 +7642,14 @@ PHP_FUNCTION(openssl_cipher_iv_length)
PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_length)
{
zend_string *buffer = NULL;
if (buffer_length <= 0
#ifndef PHP_WIN32
|| ZEND_LONG_INT_OVFL(buffer_length)
#endif
) {
if (buffer_length <= 0) {
zend_argument_value_error(1, "must be greater than 0");
return NULL;
}
if (ZEND_LONG_INT_OVFL(buffer_length)) {
zend_argument_value_error(1, "must be less than 2147483648");
return NULL;
}
buffer = zend_string_alloc(buffer_length, 0);

#ifdef PHP_WIN32
Expand All @@ -7663,7 +7663,6 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le

PHP_OPENSSL_CHECK_LONG_TO_INT_NULL_RETURN(buffer_length, length);
PHP_OPENSSL_RAND_ADD_TIME();
/* FIXME loop if requested size > INT_MAX */
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
zend_string_release_ex(buffer, 0);
zend_throw_exception(zend_ce_exception, "Error reading from source device", 0);
Expand Down