Skip to content

Commit 5a19e25

Browse files
committed
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
2 parents a39725b + a6e76ac commit 5a19e25

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

ext/openssl/openssl.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4472,17 +4472,15 @@ PHP_FUNCTION(openssl_random_pseudo_bytes)
44724472
RETURN_THROWS();
44734473
}
44744474

4475-
if (zstrong_result_returned) {
4476-
ZEND_TRY_ASSIGN_REF_FALSE(zstrong_result_returned);
4477-
}
4478-
44794475
if ((buffer = php_openssl_random_pseudo_bytes(buffer_length))) {
44804476
ZSTR_VAL(buffer)[buffer_length] = 0;
44814477
RETVAL_NEW_STR(buffer);
4482-
}
44834478

4484-
if (zstrong_result_returned) {
4485-
ZEND_TRY_ASSIGN_REF_TRUE(zstrong_result_returned);
4479+
if (zstrong_result_returned) {
4480+
ZEND_TRY_ASSIGN_REF_TRUE(zstrong_result_returned);
4481+
}
4482+
} else if (zstrong_result_returned) {
4483+
ZEND_TRY_ASSIGN_REF_FALSE(zstrong_result_returned);
44864484
}
44874485
}
44884486
/* }}} */

ext/openssl/openssl_backend_common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,11 +2123,10 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le
21232123
PHP_OPENSSL_CHECK_LONG_TO_INT_NULL_RETURN(buffer_length, length);
21242124
PHP_OPENSSL_RAND_ADD_TIME();
21252125
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
2126+
php_openssl_store_errors();
21262127
zend_string_release_ex(buffer, 0);
21272128
zend_throw_exception(zend_ce_exception, "Error reading from source device", 0);
21282129
return NULL;
2129-
} else {
2130-
php_openssl_store_errors();
21312130
}
21322131

21332132
return buffer;

0 commit comments

Comments
 (0)