Skip to content

Commit 4a16d22

Browse files
authored
openssl: Fix error propagation in csr exports (#21403)
If the print fails, then the write is still executed, resulting in a partial export without any way of the user knowing this happened. Fix this by only returning true if all writes succeed.
1 parent 7831244 commit 4a16d22

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

ext/openssl/openssl.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,9 +3176,9 @@ PHP_FUNCTION(openssl_csr_export_to_file)
31763176
bio_out = BIO_new_file(file_path, PHP_OPENSSL_BIO_MODE_W(PKCS7_BINARY));
31773177
if (bio_out != NULL) {
31783178
if (!notext && !X509_REQ_print(bio_out, csr)) {
3179+
/* TODO: warn? */
31793180
php_openssl_store_errors();
3180-
}
3181-
if (!PEM_write_bio_X509_REQ(bio_out, csr)) {
3181+
} else if (!PEM_write_bio_X509_REQ(bio_out, csr)) {
31823182
php_error_docref(NULL, E_WARNING, "Error writing PEM to file %s", file_path);
31833183
php_openssl_store_errors();
31843184
} else {
@@ -3227,9 +3227,7 @@ PHP_FUNCTION(openssl_csr_export)
32273227
bio_out = BIO_new(BIO_s_mem());
32283228
if (!notext && !X509_REQ_print(bio_out, csr)) {
32293229
php_openssl_store_errors();
3230-
}
3231-
3232-
if (PEM_write_bio_X509_REQ(bio_out, csr)) {
3230+
} else if (PEM_write_bio_X509_REQ(bio_out, csr)) {
32333231
BUF_MEM *bio_buf;
32343232

32353233
BIO_get_mem_ptr(bio_out, &bio_buf);

0 commit comments

Comments
 (0)