Permalink
Browse files

fix bug #61930: openssl corrupts ssl key resource when using openssl_…

…get_publickey()
  • Loading branch information...
1 parent 92b1cb3 commit 7b0107cc5d3d90655957680ef9cf916dce6875a7 @smalyshev smalyshev committed Feb 17, 2013
Showing with 30 additions and 0 deletions.
  1. +4 −0 NEWS
  2. +2 −0 ext/openssl/openssl.c
  3. +24 −0 ext/openssl/tests/bug61930.phpt
View
4 NEWS
@@ -12,6 +12,10 @@ PHP NEWS
- Mbstring:
. mb_split() can now handle empty matches like preg_split() does. (Moriyoshi)
+- OpenSSL:
+ . Fixed bug #61930 (openssl corrupts ssl key resource when using
+ openssl_get_publickey()). (Stas)
+
- SPL:
. Fixed bug #64228 (RecursiveDirectoryIterator always assumes SKIP_DOTS).
(patch by kriss@krizalys.com, Laruence)
View
2 ext/openssl/openssl.c
@@ -3204,6 +3204,7 @@ PHP_FUNCTION(openssl_pkey_get_public)
if (pkey == NULL) {
RETURN_FALSE;
}
+ zend_list_addref(Z_LVAL_P(return_value));
}
/* }}} */
@@ -3240,6 +3241,7 @@ PHP_FUNCTION(openssl_pkey_get_private)
if (pkey == NULL) {
RETURN_FALSE;
}
+ zend_list_addref(Z_LVAL_P(return_value));
}
/* }}} */
View
24 ext/openssl/tests/bug61930.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #61930: openssl corrupts ssl key resource when using openssl_get_publickey()
+--SKIPIF--
+<?php
+if (!extension_loaded("openssl")) die("skip");
+?>
+--FILE--
+<?php
+$cert = file_get_contents(__DIR__.'/cert.crt');
+
+$data = <<<DATA
+Please verify me
+DATA;
+
+$sig = 'f9Gyb6NV/ENn7GUa37ygTLcF93XHf5fbFTnoYF/O+fXbq3iChGUbET0RuhOsptlAODi6JsDLnJO4ikcVZo0tC1fFTj3LyCuPy3ZdgJbbVxQ/rviROCmuMFTqUW/Xa2LQYiapeCCgLQeWTLg7TM/BoHEkKbKLG/XT5jHvep1758A=';
+
+$key = openssl_get_publickey($cert);
+var_dump(openssl_get_publickey($key));
+var_dump(openssl_verify($data, base64_decode($sig), $key));
+?>
+--EXPECTF--
+resource(%d) of type (OpenSSL key)
+int(1)
+

0 comments on commit 7b0107c

Please sign in to comment.