@@ -971,7 +971,9 @@ static int php_openssl_parse_config(struct php_x509_request * req, zval * option
971971 if (str != NULL && php_openssl_check_path_ex (str , strlen (str ), path , 0 , false, false, "oid_file" )) {
972972 BIO * oid_bio = BIO_new_file (path , PHP_OPENSSL_BIO_MODE_R (PKCS7_BINARY ));
973973 if (oid_bio ) {
974- OBJ_create_objects (oid_bio );
974+ if (OBJ_create_objects (oid_bio ) == 0 ) {
975+ php_openssl_store_errors ();
976+ }
975977 BIO_free (oid_bio );
976978 php_openssl_store_errors ();
977979 }
@@ -1299,7 +1301,10 @@ PHP_MINIT_FUNCTION(openssl)
12991301 OSSL_PROVIDER_load (NULL , "legacy" );
13001302 OSSL_PROVIDER_load (NULL , "default" );
13011303#endif
1302- OPENSSL_init_ssl (OPENSSL_INIT_LOAD_CONFIG , NULL );
1304+ if (OPENSSL_init_ssl (OPENSSL_INIT_LOAD_CONFIG , NULL ) != 1 ) {
1305+ php_error_docref (NULL , E_WARNING , "Failed to initialize OpenSSL" );
1306+ return FAILURE ;
1307+ }
13031308#endif
13041309
13051310 /* register a resource id number with OpenSSL so that we can map SSL -> stream structures in
@@ -2064,22 +2069,34 @@ static int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
20642069 name = sk_GENERAL_NAME_value (names , i );
20652070 switch (name -> type ) {
20662071 case GEN_EMAIL :
2067- BIO_puts (bio , "email:" );
2072+ if (BIO_puts (bio , "email:" ) < 0 ) {
2073+ php_openssl_store_errors ();
2074+ }
20682075 as = name -> d .rfc822Name ;
2069- BIO_write (bio , ASN1_STRING_get0_data (as ),
2070- ASN1_STRING_length (as ));
2076+ if (BIO_write (bio , ASN1_STRING_get0_data (as ),
2077+ ASN1_STRING_length (as )) < 0 ) {
2078+ php_openssl_store_errors ();
2079+ }
20712080 break ;
20722081 case GEN_DNS :
2073- BIO_puts (bio , "DNS:" );
2082+ if (BIO_puts (bio , "DNS:" ) < 0 ) {
2083+ php_openssl_store_errors ();
2084+ }
20742085 as = name -> d .dNSName ;
2075- BIO_write (bio , ASN1_STRING_get0_data (as ),
2076- ASN1_STRING_length (as ));
2086+ if (BIO_write (bio , ASN1_STRING_get0_data (as ),
2087+ ASN1_STRING_length (as )) < 0 ) {
2088+ php_openssl_store_errors ();
2089+ }
20772090 break ;
20782091 case GEN_URI :
2079- BIO_puts (bio , "URI:" );
2092+ if (BIO_puts (bio , "URI:" ) < 0 ) {
2093+ php_openssl_store_errors ();
2094+ }
20802095 as = name -> d .uniformResourceIdentifier ;
2081- BIO_write (bio , ASN1_STRING_get0_data (as ),
2082- ASN1_STRING_length (as ));
2096+ if (BIO_write (bio , ASN1_STRING_get0_data (as ),
2097+ ASN1_STRING_length (as )) < 0 ) {
2098+ php_openssl_store_errors ();
2099+ }
20832100 break ;
20842101 default :
20852102 /* use builtin print for GEN_OTHERNAME, GEN_X400,
@@ -2317,7 +2334,10 @@ static STACK_OF(X509) *php_openssl_load_all_certs_from_file(
23172334 while (sk_X509_INFO_num (sk )) {
23182335 xi = sk_X509_INFO_shift (sk );
23192336 if (xi -> x509 != NULL ) {
2320- sk_X509_push (stack ,xi -> x509 );
2337+ if (sk_X509_push (stack ,xi -> x509 ) == 0 ) {
2338+ php_openssl_store_errors ();
2339+ X509_free (xi -> x509 );
2340+ }
23212341 xi -> x509 = NULL ;
23222342 }
23232343 X509_INFO_free (xi );
@@ -2582,6 +2602,7 @@ static STACK_OF(X509) *php_array_to_X509_sk(zval * zcerts, uint32_t arg_num, con
25822602
25832603 }
25842604 if (sk_X509_push (sk , cert ) <= 0 ) {
2605+ php_openssl_store_errors ();
25852606 X509_free (cert );
25862607 goto push_fail_exit ;
25872608 }
@@ -2603,6 +2624,7 @@ static STACK_OF(X509) *php_array_to_X509_sk(zval * zcerts, uint32_t arg_num, con
26032624 }
26042625 }
26052626 if (sk_X509_push (sk , cert ) <= 0 ) {
2627+ php_openssl_store_errors ();
26062628 X509_free (cert );
26072629 goto push_fail_exit ;
26082630 }
@@ -3381,7 +3403,10 @@ PHP_FUNCTION(openssl_csr_sign)
33813403 PHP_OPENSSL_ASN1_INTEGER_set (X509_get_serialNumber (new_cert ), serial );
33823404 }
33833405
3384- X509_set_subject_name (new_cert , X509_REQ_get_subject_name (csr ));
3406+ if (!X509_set_subject_name (new_cert , X509_REQ_get_subject_name (csr ))) {
3407+ php_openssl_store_errors ();
3408+ goto cleanup ;
3409+ }
33853410
33863411 if (cert == NULL ) {
33873412 cert = new_cert ;
@@ -5853,6 +5878,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt)
58535878 }
58545879 }
58555880 if (sk_X509_push (recipcerts , cert ) <= 0 ) {
5881+ php_openssl_store_errors ();
58565882 X509_free (cert );
58575883 goto clean_exit ;
58585884 }
@@ -5877,6 +5903,7 @@ PHP_FUNCTION(openssl_pkcs7_encrypt)
58775903 }
58785904 }
58795905 if (sk_X509_push (recipcerts , cert ) <= 0 ) {
5906+ php_openssl_store_errors ();
58805907 X509_free (cert );
58815908 goto clean_exit ;
58825909 }
0 commit comments