Commit 2004b709c43 for php.net
commit 2004b709c43b396c8229a8dac9f8310fcfb515d3
Author: ndossche <nora.dossche@ugent.be>
Date: Thu Mar 5 13:27:03 2026 +0100
Fix missing error propagation in openssl_x509_export_to_file()
The file writes can have failed, but this error isn't visible for the
application, fix it by propagating the error properly.
Closes GH-21348.
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 1b04164df41..7e6638f7fd2 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -1567,14 +1567,11 @@ PHP_FUNCTION(openssl_x509_export_to_file)
bio_out = BIO_new_file(file_path, PHP_OPENSSL_BIO_MODE_W(PKCS7_BINARY));
if (bio_out) {
- if (!notext && !X509_print(bio_out, cert)) {
- php_openssl_store_errors();
- }
- if (!PEM_write_bio_X509(bio_out, cert)) {
+ if ((notext || X509_print(bio_out, cert)) && PEM_write_bio_X509(bio_out, cert)) {
+ RETVAL_TRUE;
+ } else {
php_openssl_store_errors();
}
-
- RETVAL_TRUE;
} else {
php_openssl_store_errors();
php_error_docref(NULL, E_WARNING, "Error opening file %s", file_path);