hnangelo                Tue Jul 15 02:46:26 2008 UTC

  Modified files:              
    /php-src/ext/openssl        openssl.c 
    /php-src/ext/openssl/tests  006.phpt 
  Log:
  Fix segfault caused by openssl_pkey_new() in ext/openssl/tests/006.phpt
  
http://cvs.php.net/viewvc.cgi/php-src/ext/openssl/openssl.c?r1=1.161&r2=1.162&diff_format=u
Index: php-src/ext/openssl/openssl.c
diff -u php-src/ext/openssl/openssl.c:1.161 php-src/ext/openssl/openssl.c:1.162
--- php-src/ext/openssl/openssl.c:1.161 Sat Jun 28 09:24:18 2008
+++ php-src/ext/openssl/openssl.c       Tue Jul 15 02:46:26 2008
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: openssl.c,v 1.161 2008/06/28 09:24:18 hnangelo Exp $ */
+/* $Id: openssl.c,v 1.162 2008/07/15 02:46:26 hnangelo Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -2950,8 +2950,10 @@
                                        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 @@
                                        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 @@
                                        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);
                                }
http://cvs.php.net/viewvc.cgi/php-src/ext/openssl/tests/006.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/openssl/tests/006.phpt
diff -u /dev/null php-src/ext/openssl/tests/006.phpt:1.2
--- /dev/null   Tue Jul 15 02:46:26 2008
+++ php-src/ext/openssl/tests/006.phpt  Tue Jul 15 02:46:26 2008
@@ -0,0 +1,25 @@
+--TEST--
+openssl_pkey_new() with an empty sub-array arg generates a malformed resource
+--SKIPIF--
+<?php if (!extension_loaded("openssl")) print "skip"; ?>
+--FILE--
+<?php
+/* openssl_pkey_get_details() segfaults when getting the information
+       from openssl_pkey_new() with an empty sub-array arg             */
+
+$rsa = array(b"rsa" => array());
+$dsa = array(b"dsa" => array());
+$dh = array(b"dh" => array());
+
+openssl_pkey_get_details(openssl_pkey_new($rsa));
+openssl_pkey_get_details(openssl_pkey_new($dsa));
+openssl_pkey_get_details(openssl_pkey_new($dh));
+?>
+--EXPECTF--
+
+Warning: openssl_pkey_get_details() expects parameter 1 to be resource, 
boolean given in %s on line %d
+
+Warning: openssl_pkey_get_details() expects parameter 1 to be resource, 
boolean given in %s on line %d
+
+Warning: openssl_pkey_get_details() expects parameter 1 to be resource, 
boolean given in %s on line %d
+



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to