3333/* true global; readonly after module startup */
3434static char default_ssl_conf_filename [MAXPATHLEN ];
3535
36- void php_openssl_add_assoc_name_entry (zval * val , char * key , X509_NAME * name , int shortname )
36+ void php_openssl_add_assoc_name_entry (zval * val , char * key , const X509_NAME * name , int shortname )
3737{
3838 zval * data ;
3939 zval subitem , tmp ;
4040 int i ;
4141 char * sname ;
4242 int nid ;
43- X509_NAME_ENTRY * ne ;
44- ASN1_STRING * str = NULL ;
45- ASN1_OBJECT * obj ;
43+ const X509_NAME_ENTRY * ne ;
44+ const ASN1_STRING * str = NULL ;
45+ const ASN1_OBJECT * obj ;
4646
4747 if (key != NULL ) {
4848 array_init (& subitem );
@@ -106,7 +106,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, X509_NAME * name,
106106 }
107107}
108108
109- void php_openssl_add_assoc_asn1_string (zval * val , char * key , ASN1_STRING * str )
109+ void php_openssl_add_assoc_asn1_string (zval * val , char * key , const ASN1_STRING * str )
110110{
111111 add_assoc_stringl (val , key , (const char * )ASN1_STRING_get0_data (str ), ASN1_STRING_length (str ));
112112}
@@ -622,11 +622,11 @@ zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, bool r
622622/* Special handling of subjectAltName, see CVE-2013-4073
623623 * Christian Heimes
624624 */
625- int openssl_x509v3_subjectAltName (BIO * bio , X509_EXTENSION * extension )
625+ int openssl_x509v3_subjectAltName (BIO * bio , PHP_OPENSSL_X509_EXTENSION * extension )
626626{
627627 GENERAL_NAMES * names ;
628628 const X509V3_EXT_METHOD * method = NULL ;
629- ASN1_OCTET_STRING * extension_data ;
629+ const ASN1_OCTET_STRING * extension_data ;
630630 long i , length , num ;
631631 const unsigned char * p ;
632632
@@ -982,7 +982,12 @@ zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr,
982982 zval * item , * subitem ;
983983 zend_string * strindex = NULL ;
984984
985- subj = X509_REQ_get_subject_name (csr );
985+ subj = X509_NAME_new ();
986+ if (subj == NULL ) {
987+ php_openssl_store_errors ();
988+ return FAILURE ;
989+ }
990+
986991 /* apply values from the dn hash */
987992 ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (dn ), strindex , item ) {
988993 if (strindex ) {
@@ -991,10 +996,12 @@ zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr,
991996 if (Z_TYPE_P (item ) == IS_ARRAY ) {
992997 ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (item ), i , subitem ) {
993998 if (php_openssl_csr_add_subj_entry (subitem , subj , nid ) == FAILURE ) {
999+ X509_NAME_free (subj );
9941000 return FAILURE ;
9951001 }
9961002 } ZEND_HASH_FOREACH_END ();
9971003 } else if (php_openssl_csr_add_subj_entry (item , subj , nid ) == FAILURE ) {
1004+ X509_NAME_free (subj );
9981005 return FAILURE ;
9991006 }
10001007 } else {
@@ -1045,13 +1052,23 @@ zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr,
10451052 if (!X509_NAME_add_entry_by_txt (subj , type , MBSTRING_UTF8 , (unsigned char * )v -> value , -1 , -1 , 0 )) {
10461053 php_openssl_store_errors ();
10471054 php_error_docref (NULL , E_WARNING , "add_entry_by_txt %s -> %s (failed)" , type , v -> value );
1055+ X509_NAME_free (subj );
10481056 return FAILURE ;
10491057 }
10501058 if (!X509_NAME_entry_count (subj )) {
10511059 php_error_docref (NULL , E_WARNING , "No objects specified in config file" );
1060+ X509_NAME_free (subj );
10521061 return FAILURE ;
10531062 }
10541063 }
1064+
1065+ if (!X509_REQ_set_subject_name (csr , subj )) {
1066+ php_openssl_store_errors ();
1067+ X509_NAME_free (subj );
1068+ return FAILURE ;
1069+ }
1070+ X509_NAME_free (subj );
1071+
10551072 if (attribs ) {
10561073 ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (attribs ), strindex , item ) {
10571074 int nid ;
0 commit comments