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
Show file tree
Hide file tree
Changes from 2 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
9 changes: 2 additions & 7 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7642,12 +7642,8 @@ 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
) {
zend_argument_value_error(1, "must be greater than 0");
if (buffer_length <= 0 || ZEND_LONG_INT_OVFL(buffer_length)) {
zend_argument_value_error(1, "must be greater than 0 and less than 2147483648");
return NULL;
}
buffer = zend_string_alloc(buffer_length, 0);
Expand All @@ -7663,7 +7659,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
2 changes: 1 addition & 1 deletion ext/openssl/tests/openssl_random_pseudo_bytes_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ try {
}
?>
--EXPECT--
openssl_random_pseudo_bytes(): Argument #1 ($length) must be greater than 0
openssl_random_pseudo_bytes(): Argument #1 ($length) must be greater than 0 and less than 2147483648