Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix inverted call to php_openssl_store_errors()
  Fix openssl_random_pseudo_bytes() always setting strong_result to true
This commit is contained in:
Niels Dossche 2025-04-02 20:27:28 +02:00
commit 5a19e25347
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
2 changed files with 6 additions and 9 deletions

View file

@ -4472,17 +4472,15 @@ PHP_FUNCTION(openssl_random_pseudo_bytes)
RETURN_THROWS();
}
if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_FALSE(zstrong_result_returned);
}
if ((buffer = php_openssl_random_pseudo_bytes(buffer_length))) {
ZSTR_VAL(buffer)[buffer_length] = 0;
RETVAL_NEW_STR(buffer);
}
if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_TRUE(zstrong_result_returned);
if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_TRUE(zstrong_result_returned);
}
} else if (zstrong_result_returned) {
ZEND_TRY_ASSIGN_REF_FALSE(zstrong_result_returned);
}
}
/* }}} */

View file

@ -2123,11 +2123,10 @@ 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();
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
php_openssl_store_errors();
zend_string_release_ex(buffer, 0);
zend_throw_exception(zend_ce_exception, "Error reading from source device", 0);
return NULL;
} else {
php_openssl_store_errors();
}
return buffer;