Commit:    9973658a44090cbf67cb8a1d93f00d46a4330356
Author:    Mark Jones <m...@zedwood.com>         Wed, 14 Aug 2013 11:26:45 -0600
Committer: Stanislav Malyshev <s...@php.net>      Sun, 18 Aug 2013 15:42:37 
-0700
Parents:   0154db1c5fcfd0c4030a0aefb2861dc8386b4a1c
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=9973658a44090cbf67cb8a1d93f00d46a4330356

Log:
Fix for php bug #64802 includes test case

Bugs:
https://bugs.php.net/64802

Changed paths:
  M  NEWS
  M  ext/openssl/openssl.c
  A  ext/openssl/tests/bug64802.pem
  A  ext/openssl/tests/bug64802.phpt


Diff:
diff --git a/NEWS b/NEWS
index 0d0a053..1e4e0fb 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,10 @@ PHP                                                          
              NEWS
   . Fixed bug #61268 (--enable-dtrace leads make to clobber
     Zend/zend_dtrace.d) (Chris Jones)
 
+- Openssl:
+  . Fixed bug #64802 (openssl_x509_parse fails to parse subject properly in 
+    some cases). (Mark Jones)
+
 - Session:
   . Fixed bug #62129 (rfc1867 crashes php even though turned off). (gxd305 at
     gmail dot com)
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 68be86f..fc10e31 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -561,6 +561,7 @@ static EVP_PKEY * php_openssl_generate_private_key(struct 
php_x509_request * req
 
 static void add_assoc_name_entry(zval * val, char * key, X509_NAME * name, int 
shortname TSRMLS_DC) /* {{{ */
 {
+       zval **data;
        zval *subitem, *subentries;
        int i, j = -1, last = -1, obj_cnt = 0;
        char *sname;
@@ -592,39 +593,27 @@ static void add_assoc_name_entry(zval * val, char * key, 
X509_NAME * name, int s
                        sname = (char *) OBJ_nid2ln(nid);
                }
 
-               MAKE_STD_ZVAL(subentries);
-               array_init(subentries);
+               str = X509_NAME_ENTRY_get_data(ne);
+               if (ASN1_STRING_type(str) != V_ASN1_UTF8STRING) {
+                       to_add_len = ASN1_STRING_to_UTF8(&to_add, str);
+               } else {
+                       to_add = ASN1_STRING_data(str);
+                       to_add_len = ASN1_STRING_length(str);
+               }
 
-               last = -1;
-               for (;;) {
-                       j = X509_NAME_get_index_by_OBJ(name, obj, last);
-                       if (j < 0) {
-                               if (last != -1) break;
-                       } else {
-                               obj_cnt++;
-                               ne  = X509_NAME_get_entry(name, j);
-                               str = X509_NAME_ENTRY_get_data(ne);
-                               if (ASN1_STRING_type(str) != V_ASN1_UTF8STRING) 
{
-                                       to_add_len = 
ASN1_STRING_to_UTF8(&to_add, str);
-                                       if (to_add_len != -1) {
-                                               
add_next_index_stringl(subentries, (char *)to_add, to_add_len, 1);
-                                       }
-                               } else {
-                                       to_add = ASN1_STRING_data(str);
-                                       to_add_len = ASN1_STRING_length(str);
+               if (to_add_len != -1) {
+                       if (zend_hash_find(Z_ARRVAL_P(subitem), sname, 
strlen(sname)+1, (void**)&data) == SUCCESS) {
+                               if (Z_TYPE_PP(data) == IS_ARRAY) {
+                                       subentries = *data;
                                        add_next_index_stringl(subentries, 
(char *)to_add, to_add_len, 1);
+                               } else if (Z_TYPE_PP(data) == IS_STRING) {
+                                       MAKE_STD_ZVAL(subentries);
+                                       array_init(subentries);
+                                       add_next_index_stringl(subentries, 
Z_STRVAL_PP(data), Z_STRLEN_PP(data), 1);
+                                       add_next_index_stringl(subentries, 
(char *)to_add, to_add_len, 1);
+                                       zend_hash_update(Z_ARRVAL_P(subitem), 
sname, strlen(sname)+1, &subentries, sizeof(zval*), NULL);
                                }
-                       }
-                       last = j;
-               }
-               i = last;
-
-               if (obj_cnt > 1) {
-                       add_assoc_zval_ex(subitem, sname, strlen(sname) + 1, 
subentries);
-               } else {
-                       zval_dtor(subentries);
-                       FREE_ZVAL(subentries);
-                       if (obj_cnt && str && to_add_len > -1) {
+                       } else {
                                add_assoc_stringl(subitem, sname, (char 
*)to_add, to_add_len, 1);
                        }
                }
diff --git a/ext/openssl/tests/bug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ZlVMRN+67rK+qfY5sTeijFcudV3/i0PDtOFRwP
+6yYVD2uZmYkxfPiW309HPmDF+EzhxpVjWlTQEOwkfFLTmJmwl3Qu2Kffp8F1ENXW
+OTVNvj5VtMghvzu68PpzKl1VjlOR4Ej9NCwh1dUjNKEoTPzvpehXsIZ7jHSpX/T1
+wSSt9ckiechDdpgZXTzHgbxHNibK0Uhh+QhkBgYMj5F8qj5BlBhWAWqQa/VnEdmr
+Pfo7U+QmadoqQd7qt06hE2hG1nfZ0vPJDbWV3oVSwG2Yt7I=
+-----END CERTIFICATE-----
diff --git a/ext/openssl/tests/bug64802.phpt b/ext/openssl/tests/bug64802.phpt
new file mode 100644
index 0000000..9a59701
--- /dev/null
+++ b/ext/openssl/tests/bug64802.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Bug #64802: openssl_x509_parse fails to parse subject properly in some cases
+--SKIPIF--
+<?php
+if (!extension_loaded("openssl")) die("skip");
+?>
+--FILE--
+<?php
+$cert = file_get_contents(__DIR__.'/bug64802.pem');
+$r = openssl_x509_parse($cert,$use_short_names=true);
+sort($r['subject']);
+var_dump( $r['subject'] );
+?>
+--EXPECTF--
+array(11) {
+  [0]=>
+  string(14) "1550 Bryant st"
+  [1]=>
+  string(5) "94103"
+  [2]=>
+  string(7) "4586007"
+  [3]=>
+  string(2) "CA"
+  [4]=>
+  string(26) "COMODO EV Multi-Domain SSL"
+  [5]=>
+  string(20) "Private Organization"
+  [6]=>
+  string(10) "Rdio, Inc."
+  [7]=>
+  string(13) "San Francisco"
+  [8]=>
+  string(2) "US"
+  [9]=>
+  array(2) {
+    [0]=>
+    string(2) "US"
+    [1]=>
+    string(8) "Delaware"
+  }
+  [10]=>
+  array(6) {
+    [0]=>
+    string(9) "www.rd.io"
+    [1]=>
+    string(8) "rdio.com"
+    [2]=>
+    string(5) "rd.io"
+    [3]=>
+    string(12) "api.rdio.com"
+    [4]=>
+    string(9) "api.rd.io"
+    [5]=>
+    string(12) "www.rdio.com"
+  }
+}


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

Reply via email to