summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2013-02-17 13:28:42 -0800
committerStanislav Malyshev <stas@php.net>2013-02-17 13:28:42 -0800
commit7b0107cc5d3d90655957680ef9cf916dce6875a7 (patch)
treeb4bd1686995829fd8c696f0e89c6e51252ce2648 /ext/openssl
parent92b1cb3ca0b4a62c33a6a15b0e50762cac67fc5d (diff)
downloadphp-git-7b0107cc5d3d90655957680ef9cf916dce6875a7.tar.gz
fix bug #61930: openssl corrupts ssl key resource when using openssl_get_publickey()
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/openssl.c2
-rw-r--r--ext/openssl/tests/bug61930.phpt24
2 files changed, 26 insertions, 0 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 328c1ee937..d7ac117e51 100644
--- a/ext/openssl/openssl.c
+++ b/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));
}
/* }}} */
diff --git a/ext/openssl/tests/bug61930.phpt b/ext/openssl/tests/bug61930.phpt
new file mode 100644
index 0000000000..55dc42fded
--- /dev/null
+++ b/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)
+