3535/* true global; readonly after module startup */
3636static char default_ssl_conf_filename [MAXPATHLEN ];
3737
38- void php_openssl_add_assoc_name_entry (zval * val , char * key , X509_NAME * name , int shortname )
38+ void php_openssl_add_assoc_name_entry (zval * val , char * key , const X509_NAME * name , int shortname )
3939{
4040 zval * data ;
4141 zval subitem , tmp ;
4242 int i ;
4343 char * sname ;
4444 int nid ;
45- X509_NAME_ENTRY * ne ;
46- ASN1_STRING * str = NULL ;
47- ASN1_OBJECT * obj ;
45+ const X509_NAME_ENTRY * ne ;
46+ const ASN1_STRING * str = NULL ;
47+ const ASN1_OBJECT * obj ;
4848
4949 if (key != NULL ) {
5050 array_init (& subitem );
@@ -108,7 +108,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, X509_NAME * name,
108108 }
109109}
110110
111- void php_openssl_add_assoc_asn1_string (zval * val , char * key , ASN1_STRING * str )
111+ void php_openssl_add_assoc_asn1_string (zval * val , char * key , const ASN1_STRING * str )
112112{
113113 add_assoc_stringl (val , key , (const char * )ASN1_STRING_get0_data (str ), ASN1_STRING_length (str ));
114114}
@@ -618,11 +618,11 @@ zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, bool r
618618/* Special handling of subjectAltName, see CVE-2013-4073
619619 * Christian Heimes
620620 */
621- int openssl_x509v3_subjectAltName (BIO * bio , X509_EXTENSION * extension )
621+ int openssl_x509v3_subjectAltName (BIO * bio , PHP_OPENSSL_X509_EXTENSION * extension )
622622{
623623 GENERAL_NAMES * names ;
624624 const X509V3_EXT_METHOD * method = NULL ;
625- ASN1_OCTET_STRING * extension_data ;
625+ const ASN1_OCTET_STRING * extension_data ;
626626 long i , length , num ;
627627 const unsigned char * p ;
628628
@@ -978,7 +978,12 @@ zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr,
978978 zval * item , * subitem ;
979979 zend_string * strindex = NULL ;
980980
981- subj = X509_REQ_get_subject_name (csr );
981+ subj = X509_NAME_new ();
982+ if (subj == NULL ) {
983+ php_openssl_store_errors ();
984+ return FAILURE ;
985+ }
986+
982987 /* apply values from the dn hash */
983988 ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (dn ), strindex , item ) {
984989 if (strindex ) {
@@ -987,10 +992,12 @@ zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr,
987992 if (Z_TYPE_P (item ) == IS_ARRAY ) {
988993 ZEND_HASH_FOREACH_NUM_KEY_VAL (Z_ARRVAL_P (item ), i , subitem ) {
989994 if (php_openssl_csr_add_subj_entry (subitem , subj , nid ) == FAILURE ) {
995+ X509_NAME_free (subj );
990996 return FAILURE ;
991997 }
992998 } ZEND_HASH_FOREACH_END ();
993999 } else if (php_openssl_csr_add_subj_entry (item , subj , nid ) == FAILURE ) {
1000+ X509_NAME_free (subj );
9941001 return FAILURE ;
9951002 }
9961003 } else {
@@ -1041,13 +1048,23 @@ zend_result php_openssl_csr_make(struct php_x509_request * req, X509_REQ * csr,
10411048 if (!X509_NAME_add_entry_by_txt (subj , type , MBSTRING_UTF8 , (unsigned char * )v -> value , -1 , -1 , 0 )) {
10421049 php_openssl_store_errors ();
10431050 php_error_docref (NULL , E_WARNING , "add_entry_by_txt %s -> %s (failed)" , type , v -> value );
1051+ X509_NAME_free (subj );
10441052 return FAILURE ;
10451053 }
10461054 if (!X509_NAME_entry_count (subj )) {
10471055 php_error_docref (NULL , E_WARNING , "No objects specified in config file" );
1056+ X509_NAME_free (subj );
10481057 return FAILURE ;
10491058 }
10501059 }
1060+
1061+ if (!X509_REQ_set_subject_name (csr , subj )) {
1062+ php_openssl_store_errors ();
1063+ X509_NAME_free (subj );
1064+ return FAILURE ;
1065+ }
1066+ X509_NAME_free (subj );
1067+
10511068 if (attribs ) {
10521069 ZEND_HASH_FOREACH_STR_KEY_VAL (Z_ARRVAL_P (attribs ), strindex , item ) {
10531070 int nid ;
0 commit comments