summaryrefslogtreecommitdiff
path: root/ext/openssl/openssl.c
diff options
context:
space:
mode:
authorHenrique do Nascimento Angelo <hnangelo@php.net>2008-07-15 02:46:26 +0000
committerHenrique do Nascimento Angelo <hnangelo@php.net>2008-07-15 02:46:26 +0000
commitf385e69fdbbba1a71ff29ae7643c0eec4f72ec0c (patch)
tree15dc46998ff9aab3d62e93d4025c802a30e94aa0 /ext/openssl/openssl.c
parent2ef07c40f51032aeb0b0ddc29a5ee19c6b496fdd (diff)
downloadphp-git-f385e69fdbbba1a71ff29ae7643c0eec4f72ec0c.tar.gz
Fix segfault caused by openssl_pkey_new() in ext/openssl/tests/006.phpt
Diffstat (limited to 'ext/openssl/openssl.c')
-rw-r--r--ext/openssl/openssl.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 4f653921c1..e1f4bb56de 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -2950,8 +2950,10 @@ PHP_FUNCTION(openssl_pkey_new)
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, dmp1);
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, dmq1);
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), rsa, iqmp);
- if (EVP_PKEY_assign_RSA(pkey, rsa)) {
- RETURN_RESOURCE(zend_list_insert(pkey, le_key));
+ if (rsa->n && rsa->d) {
+ if (EVP_PKEY_assign_RSA(pkey, rsa)) {
+ RETURN_RESOURCE(zend_list_insert(pkey, le_key));
+ }
}
RSA_free(rsa);
}
@@ -2969,11 +2971,13 @@ PHP_FUNCTION(openssl_pkey_new)
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dsa, g);
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dsa, priv_key);
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dsa, pub_key);
- if (!dsa->priv_key && !dsa->pub_key) {
- DSA_generate_key(dsa);
- }
- if (EVP_PKEY_assign_DSA(pkey, dsa)) {
- RETURN_RESOURCE(zend_list_insert(pkey, le_key));
+ if (dsa->p && dsa->q && dsa->g) {
+ if (!dsa->priv_key && !dsa->pub_key) {
+ DSA_generate_key(dsa);
+ }
+ if (EVP_PKEY_assign_DSA(pkey, dsa)) {
+ RETURN_RESOURCE(zend_list_insert(pkey, le_key));
+ }
}
DSA_free(dsa);
}
@@ -2990,11 +2994,13 @@ PHP_FUNCTION(openssl_pkey_new)
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dh, g);
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dh, priv_key);
OPENSSL_PKEY_SET_BN(Z_ARRVAL_PP(data), dh, pub_key);
- if (!dh->pub_key) {
- DH_generate_key(dh);
- }
- if (EVP_PKEY_assign_DH(pkey, dh)) {
- RETURN_RESOURCE(zend_list_insert(pkey, le_key));
+ if (dh->p && dh->g) {
+ if (!dh->pub_key) {
+ DH_generate_key(dh);
+ }
+ if (EVP_PKEY_assign_DH(pkey, dh)) {
+ RETURN_RESOURCE(zend_list_insert(pkey, le_key));
+ }
}
DH_free(dh);
}