@@ -703,7 +703,7 @@ static void php_openssl_add_assoc_name_entry(zval * val, char * key, const X509_
703703 } else {
704704 /* ASN1_STRING_get0_data(3): Since this is an internal pointer it should not be freed or modified in any way */
705705 to_add = ASN1_STRING_get0_data (str );
706- to_add_len = ASN1_STRING_length (str );
706+ to_add_len = ASN1_STRING_get_length (str );
707707 }
708708
709709 if (to_add_len != -1 ) {
@@ -739,7 +739,7 @@ static void php_openssl_add_assoc_name_entry(zval * val, char * key, const X509_
739739
740740static void php_openssl_add_assoc_asn1_string (zval * val , char * key , const ASN1_STRING * str ) /* {{{ */
741741{
742- add_assoc_stringl (val , key , (const char * )ASN1_STRING_get0_data (str ), ASN1_STRING_length (str ));
742+ add_assoc_stringl (val , key , (const char * )ASN1_STRING_get0_data (str ), ASN1_STRING_get_length (str ));
743743}
744744/* }}} */
745745
@@ -756,6 +756,7 @@ static time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
756756 struct tm thetime ;
757757 char * strbuf ;
758758 char * thestr ;
759+ const char * timestr_data ;
759760 long gmadjust = 0 ;
760761 size_t timestr_len ;
761762
@@ -764,24 +765,25 @@ static time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr) /* {{{ */
764765 return (time_t )- 1 ;
765766 }
766767
767- timestr_len = (size_t )ASN1_STRING_length (timestr );
768+ timestr_len = ASN1_STRING_get_length (timestr );
769+ timestr_data = timestr_len ? (const char * )ASN1_STRING_get0_data (timestr ) : "" ;
768770
769- if (timestr_len != strlen (( const char * ) ASN1_STRING_get0_data ( timestr )) ) {
771+ if (memchr ( timestr_data , '\0' , timestr_len ) != NULL ) {
770772 php_error_docref (NULL , E_WARNING , "Illegal length in timestamp" );
771773 return (time_t )- 1 ;
772774 }
773775
774776 if (timestr_len < 13 ) {
775- php_error_docref (NULL , E_WARNING , "Unable to parse time string %s correctly" , ASN1_STRING_get0_data ( timestr ) );
777+ php_error_docref (NULL , E_WARNING , "Unable to parse time string %.* s correctly" , ( int ) timestr_len , timestr_data );
776778 return (time_t )- 1 ;
777779 }
778780
779781 if (ASN1_STRING_type (timestr ) == V_ASN1_GENERALIZEDTIME && timestr_len < 15 ) {
780- php_error_docref (NULL , E_WARNING , "Unable to parse time string %s correctly" , ASN1_STRING_get0_data ( timestr ) );
782+ php_error_docref (NULL , E_WARNING , "Unable to parse time string %.* s correctly" , ( int ) timestr_len , timestr_data );
781783 return (time_t )- 1 ;
782784 }
783785
784- strbuf = estrdup (( const char * ) ASN1_STRING_get0_data ( timestr ) );
786+ strbuf = estrndup ( timestr_data , timestr_len );
785787
786788 memset (& thetime , 0 , sizeof (thetime ));
787789
@@ -1632,7 +1634,7 @@ PHP_FUNCTION(openssl_spki_new)
16321634 }
16331635
16341636 if (challenge ) {
1635- if (!ASN1_STRING_set (spki -> spkac -> challenge , challenge , ( int ) challenge_len )) {
1637+ if (!ASN1_STRING_set1_data (spki -> spkac -> challenge , ( const unsigned char * ) challenge , challenge_len )) {
16361638 php_openssl_store_errors ();
16371639 php_error_docref (NULL , E_WARNING , "Unable to set challenge data" );
16381640 goto cleanup ;
@@ -1824,7 +1826,8 @@ PHP_FUNCTION(openssl_spki_export_challenge)
18241826 goto cleanup ;
18251827 }
18261828
1827- RETVAL_STRING ((const char * )ASN1_STRING_get0_data (spki -> spkac -> challenge ));
1829+ RETVAL_STRINGL_FAST ((const char * )ASN1_STRING_get0_data (spki -> spkac -> challenge ),
1830+ ASN1_STRING_get_length (spki -> spkac -> challenge ));
18281831 goto cleanup ;
18291832
18301833cleanup :
@@ -2041,7 +2044,7 @@ static int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *e
20412044
20422045 extension_data = X509_EXTENSION_get_data (extension );
20432046 p = ASN1_STRING_get0_data (extension_data );
2044- length = ASN1_STRING_length (extension_data );
2047+ length = ASN1_STRING_get_length (extension_data );
20452048 if (method -> it ) {
20462049 names = (GENERAL_NAMES * ) (ASN1_item_d2i (NULL , & p , length ,
20472050 ASN1_ITEM_ptr (method -> it )));
@@ -2063,19 +2066,19 @@ static int openssl_x509v3_subjectAltName(BIO *bio, PHP_OPENSSL_X509_EXTENSION *e
20632066 BIO_puts (bio , "email:" );
20642067 as = name -> d .rfc822Name ;
20652068 BIO_write (bio , ASN1_STRING_get0_data (as ),
2066- ASN1_STRING_length (as ));
2069+ ASN1_STRING_get_length (as ));
20672070 break ;
20682071 case GEN_DNS :
20692072 BIO_puts (bio , "DNS:" );
20702073 as = name -> d .dNSName ;
20712074 BIO_write (bio , ASN1_STRING_get0_data (as ),
2072- ASN1_STRING_length (as ));
2075+ ASN1_STRING_get_length (as ));
20732076 break ;
20742077 case GEN_URI :
20752078 BIO_puts (bio , "URI:" );
20762079 as = name -> d .uniformResourceIdentifier ;
20772080 BIO_write (bio , ASN1_STRING_get0_data (as ),
2078- ASN1_STRING_length (as ));
2081+ ASN1_STRING_get_length (as ));
20792082 break ;
20802083 default :
20812084 /* use builtin print for GEN_OTHERNAME, GEN_X400,
0 commit comments