Skip to content

Commit 0841eca

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: fix bug #61930: openssl corrupts ssl key resource when using openssl_get_publickey()
2 parents 432d59a + 7b0107c commit 0841eca

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/openssl/openssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,6 +3214,7 @@ PHP_FUNCTION(openssl_pkey_get_public)
32143214
if (pkey == NULL) {
32153215
RETURN_FALSE;
32163216
}
3217+
zend_list_addref(Z_LVAL_P(return_value));
32173218
}
32183219
/* }}} */
32193220

@@ -3250,6 +3251,7 @@ PHP_FUNCTION(openssl_pkey_get_private)
32503251
if (pkey == NULL) {
32513252
RETURN_FALSE;
32523253
}
3254+
zend_list_addref(Z_LVAL_P(return_value));
32533255
}
32543256

32553257
/* }}} */

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)