Skip to content

Commit d2ef156

Browse files
committed
Add missing error check on i2d_PKCS12_bio()
This function returns 0 on error and 1 on success. The error case was not checked and the function therefore would've returned true. The only other caller of i2d_PKCS12_bio() in the file has a correct error check. Closes GH-10761.
1 parent 30ebecb commit d2ef156

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ext/openssl/openssl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,11 +2716,13 @@ PHP_FUNCTION(openssl_pkcs12_export_to_file)
27162716
if (p12 != NULL) {
27172717
bio_out = BIO_new_file(file_path, PHP_OPENSSL_BIO_MODE_W(PKCS7_BINARY));
27182718
if (bio_out != NULL) {
2719-
2720-
i2d_PKCS12_bio(bio_out, p12);
2719+
if (i2d_PKCS12_bio(bio_out, p12) == 0) {
2720+
php_openssl_store_errors();
2721+
php_error_docref(NULL, E_WARNING, "Error writing to file %s", file_path);
2722+
} else {
2723+
RETVAL_TRUE;
2724+
}
27212725
BIO_free(bio_out);
2722-
2723-
RETVAL_TRUE;
27242726
} else {
27252727
php_openssl_store_errors();
27262728
php_error_docref(NULL, E_WARNING, "Error opening file %s", file_path);

0 commit comments

Comments
 (0)