@@ -710,14 +710,18 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
710710 num = sk_GENERAL_NAME_num (names );
711711 for (i = 0 ; i < num ; i ++ ) {
712712 GENERAL_NAME * name ;
713- ASN1_STRING * as ;
714713 zval entry ;
715714 array_init (& entry );
716715 name = sk_GENERAL_NAME_value (names , i );
717- switch (name -> type ) {
718- case GEN_EMAIL :
716+ int type ;
717+ void * value = GENERAL_NAME_get0_value (name , & type );
718+ if (value == NULL ) {
719+ type = -1 ;
720+ }
721+ switch (type ) {
722+ case GEN_EMAIL : {
719723 BIO_puts (bio , "email:" );
720- as = name -> d . rfc822Name ;
724+ ASN1_IA5STRING * as = ( ASN1_IA5STRING * ) value ;
721725 BIO_write (bio , ASN1_STRING_get0_data (as ),
722726 ASN1_STRING_length (as ));
723727 if (altname != NULL ) {
@@ -726,9 +730,10 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
726730 add_index_zval (altname , index ++ , & entry );
727731 }
728732 break ;
729- case GEN_DNS :
733+ }
734+ case GEN_DNS : {
730735 BIO_puts (bio , "DNS:" );
731- as = name -> d . dNSName ;
736+ ASN1_IA5STRING * as = ( ASN1_IA5STRING * ) value ;
732737 BIO_write (bio , ASN1_STRING_get0_data (as ),
733738 ASN1_STRING_length (as ));
734739 if (altname != NULL ) {
@@ -737,9 +742,10 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
737742 add_index_zval (altname , index ++ , & entry );
738743 }
739744 break ;
740- case GEN_URI :
745+ }
746+ case GEN_URI : {
741747 BIO_puts (bio , "URI:" );
742- as = name -> d . uniformResourceIdentifier ;
748+ ASN1_IA5STRING * as = ( ASN1_IA5STRING * ) value ;
743749 BIO_write (bio , ASN1_STRING_get0_data (as ),
744750 ASN1_STRING_length (as ));
745751 if (altname != NULL ) {
@@ -748,32 +754,40 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
748754 add_index_zval (altname , index ++ , & entry );
749755 }
750756 break ;
751- case GEN_DIRNAME :
757+ }
758+ case GEN_DIRNAME : {
752759 GENERAL_NAME_print (bio , name );
753760 if (altname != NULL ) {
754761 add_assoc_string (& entry , "type" , "DirName" );
755- php_openssl_add_assoc_name_entry (& entry , "value" , name -> d .dirn , PHP_OPENSSL_OID );
762+ X509_NAME * as = (X509_NAME * )value ;
763+ php_openssl_add_assoc_name_entry (& entry , "value" , as , PHP_OPENSSL_OID );
756764 add_index_zval (altname , index ++ , & entry );
757765 }
758766 break ;
759- case GEN_RID :
767+ }
768+ case GEN_RID : {
760769 GENERAL_NAME_print (bio , name );
761770 if (altname != NULL ) {
762771 char buf [1024 ];
763- OBJ_obj2txt (buf , sizeof (buf )- 1 , name -> d .rid , 1 );
772+ ASN1_OBJECT * as = (ASN1_OBJECT * )value ;
773+ OBJ_obj2txt (buf , sizeof (buf )- 1 , as , 1 );
764774 add_assoc_string (& entry , "type" , "Registered ID" );
765775 add_assoc_string (& entry , "value" , buf );
766776 add_index_zval (altname , index ++ , & entry );
767777 }
768778 break ;
769- case GEN_IPADD :
779+ }
780+ case GEN_IPADD : {
770781 GENERAL_NAME_print (bio , name );
771782 if (altname != NULL ) {
772783 char buf [1024 ];
773- if (name -> d .ip -> length == 4 ) {
774- inet_ntop (AF_INET , name -> d .ip -> data , buf , sizeof (buf )- 1 );
775- } else if (name -> d .ip -> length == 16 ) {
776- inet_ntop (AF_INET6 , name -> d .ip -> data , buf , sizeof (buf )- 1 );
784+ ASN1_OCTET_STRING * as = (ASN1_OCTET_STRING * )value ;
785+ int length = ASN1_STRING_length ((ASN1_STRING * )as );
786+ const unsigned char * ip = ASN1_STRING_get0_data ((ASN1_STRING * )as );
787+ if (length == 4 ) {
788+ inet_ntop (AF_INET , ip , buf , sizeof (buf )- 1 );
789+ } else if (length == 16 ) {
790+ inet_ntop (AF_INET6 , ip , buf , sizeof (buf )- 1 );
777791 } else {
778792 sprintf (buf , "<invalid>" );
779793 }
@@ -782,37 +796,41 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
782796 add_index_zval (altname , index ++ , & entry );
783797 }
784798 break ;
785- case GEN_OTHERNAME :
799+ }
800+ case GEN_OTHERNAME : {
786801 GENERAL_NAME_print (bio , name );
787802 if (altname != NULL ) {
788803 char oid [1024 ];
789- zval value ;
790- array_init (& value );
804+ zval other_zval ;
805+ array_init (& other_zval );
806+
807+ OTHERNAME * as = (OTHERNAME * )value ;
791808
792- OBJ_obj2txt (oid , sizeof (oid )- 1 , name -> d . otherName -> type_id , 1 );
809+ OBJ_obj2txt (oid , sizeof (oid )- 1 , as -> type_id , 1 );
793810
794811 BIO * bio_out ;
795812 BUF_MEM * bio_buf ;
796813 bio_out = BIO_new (BIO_s_mem ());
797- print_asn1_type (bio_out , name -> d . otherName -> value );
814+ print_asn1_type (bio_out , as -> value );
798815 BIO_get_mem_ptr (bio_out , & bio_buf );
799816
800- add_assoc_stringl (& value , oid , bio_buf -> data , bio_buf -> length );
817+ add_assoc_stringl (& other_zval , oid , bio_buf -> data , bio_buf -> length );
801818 add_assoc_string (& entry , "type" , "othername" );
802- add_assoc_zval (& entry , "value" , & value );
819+ add_assoc_zval (& entry , "value" , & other_zval );
803820 add_index_zval (altname , index ++ , & entry );
804821 BIO_free (bio_out );
805822 }
806823 break ;
807- default :
824+ }
825+ default : {
808826 GENERAL_NAME_print (bio , name );
809827 if (altname != NULL ) {
810828 BIO * bio_out ;
811829 BUF_MEM * bio_buf ;
812830 bio_out = BIO_new (BIO_s_mem ());
813831 GENERAL_NAME_print (bio_out , name );
814832 BIO_get_mem_ptr (bio_out , & bio_buf );
815- switch (name -> type ) {
833+ switch (type ) {
816834 case GEN_X400 :
817835 add_assoc_string (& entry , "type" , "X400Name" );
818836 break ;
@@ -827,6 +845,7 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
827845 add_index_zval (altname , index ++ , & entry );
828846 BIO_free (bio_out );
829847 }
848+ }
830849 }
831850 /* trailing ', ' except for last element */
832851 if (i < (num - 1 )) {
0 commit comments