@@ -75,7 +75,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, const X509_NAME *
7575 } else {
7676 /* ASN1_STRING_get0_data(3): Since this is an internal pointer it should not be freed or modified in any way */
7777 to_add = ASN1_STRING_get0_data (str );
78- to_add_len = ASN1_STRING_length (str );
78+ to_add_len = ASN1_STRING_get_length (str );
7979 }
8080
8181 if (to_add_len != -1 ) {
@@ -110,7 +110,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, const X509_NAME *
110110
111111void php_openssl_add_assoc_asn1_string (zval * val , char * key , const ASN1_STRING * str )
112112{
113- add_assoc_stringl (val , key , (const char * )ASN1_STRING_get0_data (str ), ASN1_STRING_length (str ));
113+ add_assoc_stringl (val , key , (const char * )ASN1_STRING_get0_data (str ), ASN1_STRING_get_length (str ));
114114}
115115
116116time_t php_openssl_asn1_time_to_time_t (ASN1_UTCTIME * timestr )
@@ -126,6 +126,7 @@ time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
126126 struct tm thetime ;
127127 char * strbuf ;
128128 char * thestr ;
129+ const char * timestr_data ;
129130 long gmadjust = 0 ;
130131 size_t timestr_len ;
131132
@@ -134,24 +135,25 @@ time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
134135 return (time_t )- 1 ;
135136 }
136137
137- timestr_len = (size_t )ASN1_STRING_length (timestr );
138+ timestr_len = ASN1_STRING_get_length (timestr );
139+ timestr_data = timestr_len ? (const char * )ASN1_STRING_get0_data (timestr ) : "" ;
138140
139- if (timestr_len != strlen (( const char * ) ASN1_STRING_get0_data ( timestr )) ) {
141+ if (memchr ( timestr_data , '\0' , timestr_len ) != NULL ) {
140142 php_error_docref (NULL , E_WARNING , "Illegal length in timestamp" );
141143 return (time_t )- 1 ;
142144 }
143145
144146 if (timestr_len < 13 ) {
145- php_error_docref (NULL , E_WARNING , "Unable to parse time string %s correctly" , ASN1_STRING_get0_data ( timestr ) );
147+ php_error_docref (NULL , E_WARNING , "Unable to parse time string %.* s correctly" , ( int ) timestr_len , timestr_data );
146148 return (time_t )- 1 ;
147149 }
148150
149151 if (ASN1_STRING_type (timestr ) == V_ASN1_GENERALIZEDTIME && timestr_len < 15 ) {
150- php_error_docref (NULL , E_WARNING , "Unable to parse time string %s correctly" , ASN1_STRING_get0_data ( timestr ) );
152+ php_error_docref (NULL , E_WARNING , "Unable to parse time string %.* s correctly" , ( int ) timestr_len , timestr_data );
151153 return (time_t )- 1 ;
152154 }
153155
154- strbuf = estrdup (( const char * ) ASN1_STRING_get0_data ( timestr ) );
156+ strbuf = estrndup ( timestr_data , timestr_len );
155157
156158 memset (& thetime , 0 , sizeof (thetime ));
157159
@@ -633,7 +635,7 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
633635
634636 extension_data = X509_EXTENSION_get_data (extension );
635637 p = ASN1_STRING_get0_data (extension_data );
636- length = ASN1_STRING_length (extension_data );
638+ length = ASN1_STRING_get_length (extension_data );
637639 if (method -> it ) {
638640 names = (GENERAL_NAMES * ) (ASN1_item_d2i (NULL , & p , length ,
639641 ASN1_ITEM_ptr (method -> it )));
@@ -655,19 +657,19 @@ int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *extensio
655657 BIO_puts (bio , "email:" );
656658 as = name -> d .rfc822Name ;
657659 BIO_write (bio , ASN1_STRING_get0_data (as ),
658- ASN1_STRING_length (as ));
660+ ASN1_STRING_get_length (as ));
659661 break ;
660662 case GEN_DNS :
661663 BIO_puts (bio , "DNS:" );
662664 as = name -> d .dNSName ;
663665 BIO_write (bio , ASN1_STRING_get0_data (as ),
664- ASN1_STRING_length (as ));
666+ ASN1_STRING_get_length (as ));
665667 break ;
666668 case GEN_URI :
667669 BIO_puts (bio , "URI:" );
668670 as = name -> d .uniformResourceIdentifier ;
669671 BIO_write (bio , ASN1_STRING_get0_data (as ),
670- ASN1_STRING_length (as ));
672+ ASN1_STRING_get_length (as ));
671673 break ;
672674 default :
673675 /* use builtin print for GEN_OTHERNAME, GEN_X400,
0 commit comments