Skip to content

Commit 7b0107c

Browse files
committed
fix bug #61930: openssl corrupts ssl key resource when using openssl_get_publickey()
1 parent 92b1cb3 commit 7b0107c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PHP NEWS
1212
- Mbstring:
1313
. mb_split() can now handle empty matches like preg_split() does. (Moriyoshi)
1414

15+
- OpenSSL:
16+
. Fixed bug #61930 (openssl corrupts ssl key resource when using
17+
openssl_get_publickey()). (Stas)
18+
1519
- SPL:
1620
. Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS).
1721
(patch by kriss@krizalys.com, Laruence)

ext/openssl/openssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,7 @@ PHP_FUNCTION(openssl_pkey_get_public)
32043204
if (pkey == NULL) {
32053205
RETURN_FALSE;
32063206
}
3207+
zend_list_addref(Z_LVAL_P(return_value));
32073208
}
32083209
/* }}} */
32093210

@@ -3240,6 +3241,7 @@ PHP_FUNCTION(openssl_pkey_get_private)
32403241
if (pkey == NULL) {
32413242
RETURN_FALSE;
32423243
}
3244+
zend_list_addref(Z_LVAL_P(return_value));
32433245
}
32443246

32453247
/* }}} */

ext/openssl/tests/bug61930.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #61930: openssl corrupts ssl key resource when using openssl_get_publickey()
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("openssl")) die("skip");
6+
?>
7+
--FILE--
8+
<?php
9+
$cert = file_get_contents(__DIR__.'/cert.crt');
10+
11+
$data = <<<DATA
12+
Please verify me
13+
DATA;
14+
15+
$sig = 'f9Gyb6NV/ENn7GUa37ygTLcF93XHf5fbFTnoYF/O+fXbq3iChGUbET0RuhOsptlAODi6JsDLnJO4ikcVZo0tC1fFTj3LyCuPy3ZdgJbbVxQ/rviROCmuMFTqUW/Xa2LQYiapeCCgLQeWTLg7TM/BoHEkKbKLG/XT5jHvep1758A=';
16+
17+
$key = openssl_get_publickey($cert);
18+
var_dump(openssl_get_publickey($key));
19+
var_dump(openssl_verify($data, base64_decode($sig), $key));
20+
?>
21+
--EXPECTF--
22+
resource(%d) of type (OpenSSL key)
23+
int(1)
24+

0 commit comments

Comments
 (0)