Skip to content

Commit 2004b70

Browse files
committed
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.
1 parent 20903a8 commit 2004b70

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

ext/openssl/openssl.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,14 +1567,11 @@ PHP_FUNCTION(openssl_x509_export_to_file)
15671567

15681568
bio_out = BIO_new_file(file_path, PHP_OPENSSL_BIO_MODE_W(PKCS7_BINARY));
15691569
if (bio_out) {
1570-
if (!notext && !X509_print(bio_out, cert)) {
1571-
php_openssl_store_errors();
1572-
}
1573-
if (!PEM_write_bio_X509(bio_out, cert)) {
1570+
if ((notext || X509_print(bio_out, cert)) && PEM_write_bio_X509(bio_out, cert)) {
1571+
RETVAL_TRUE;
1572+
} else {
15741573
php_openssl_store_errors();
15751574
}
1576-
1577-
RETVAL_TRUE;
15781575
} else {
15791576
php_openssl_store_errors();
15801577
php_error_docref(NULL, E_WARNING, "Error opening file %s", file_path);

0 commit comments

Comments
 (0)