Skip to content

Commit 64b1085

Browse files
committed
Fixed bug #80747
If RSA key generation fails, actually report that failure.
1 parent 7b7d998 commit 64b1085

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PHP NEWS
1515
- OPcache:
1616
. Fixed bug #80682 (opcache doesn't honour pcre.jit option). (Remi)
1717

18+
- OpenSSL:
19+
. Fixed bug #80747 (Providing RSA key size < 512 generates key that crash
20+
PHP). (Nikita)
21+
1822
- Phar:
1923
. Fixed bug #75850 (Unclear error message wrt. __halt_compiler() w/o
2024
semicolon) (cmb)

ext/openssl/openssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,8 @@ static EVP_PKEY * php_openssl_generate_private_key(struct php_x509_request * req
40214021
PHP_OPENSSL_RAND_ADD_TIME();
40224022
if (rsaparam == NULL || !RSA_generate_key_ex(rsaparam, req->priv_key_bits, bne, NULL)) {
40234023
php_openssl_store_errors();
4024+
RSA_free(rsaparam);
4025+
rsaparam = NULL;
40244026
}
40254027
BN_free(bne);
40264028
}

ext/openssl/tests/bug80747.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #80747: Providing RSA key size < 512 generates key that crash PHP
3+
--FILE--
4+
--SKIPIF--
5+
<?php
6+
if (!extension_loaded("openssl")) die("skip");
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$conf = array(
12+
'config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf',
13+
'private_key_bits' => 511,
14+
);
15+
var_dump(openssl_pkey_new($conf));
16+
17+
?>
18+
--EXPECT--
19+
bool(false)

0 commit comments

Comments
 (0)