Skip to content

Commit aef5250

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Add missing error check on PEM_write_bio_PKCS7() Add missing error check on PEM_write_bio_CMS() Add missing error check on i2d_PKCS12_bio() Add missing error checks on EVP_MD_CTX_create() and EVP_VerifyInit()
2 parents 6a71153 + a13cca8 commit aef5250

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

ext/openssl/openssl.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -2597,11 +2597,13 @@ PHP_FUNCTION(openssl_pkcs12_export_to_file)
25972597
if (p12 != NULL) {
25982598
bio_out = BIO_new_file(file_path, PHP_OPENSSL_BIO_MODE_W(PKCS7_BINARY));
25992599
if (bio_out != NULL) {
2600-
2601-
i2d_PKCS12_bio(bio_out, p12);
2600+
if (i2d_PKCS12_bio(bio_out, p12) == 0) {
2601+
php_openssl_store_errors();
2602+
php_error_docref(NULL, E_WARNING, "Error writing to file %s", file_path);
2603+
} else {
2604+
RETVAL_TRUE;
2605+
}
26022606
BIO_free(bio_out);
2603-
2604-
RETVAL_TRUE;
26052607
} else {
26062608
php_openssl_store_errors();
26072609
php_error_docref(NULL, E_WARNING, "Error opening file %s", file_path);
@@ -5285,7 +5287,11 @@ PHP_FUNCTION(openssl_pkcs7_verify)
52855287
}
52865288

52875289
if (p7bout) {
5288-
PEM_write_bio_PKCS7(p7bout, p7);
5290+
if (PEM_write_bio_PKCS7(p7bout, p7) == 0) {
5291+
php_error_docref(NULL, E_WARNING, "Failed to write PKCS7 to file");
5292+
php_openssl_store_errors();
5293+
RETVAL_FALSE;
5294+
}
52895295
}
52905296
}
52915297
} else {
@@ -5870,7 +5876,11 @@ PHP_FUNCTION(openssl_cms_verify)
58705876
}
58715877

58725878
if (p7bout) {
5873-
PEM_write_bio_CMS(p7bout, cms);
5879+
if (PEM_write_bio_CMS(p7bout, cms) == 0) {
5880+
php_error_docref(NULL, E_WARNING, "Failed to write CMS to file");
5881+
php_openssl_store_errors();
5882+
RETVAL_FALSE;
5883+
}
58745884
}
58755885
}
58765886
} else {

ext/phar/util.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,15 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type,
15791579
}
15801580

15811581
md_ctx = EVP_MD_CTX_create();
1582-
EVP_VerifyInit(md_ctx, mdtype);
1582+
if (!md_ctx || !EVP_VerifyInit(md_ctx, mdtype)) {
1583+
if (md_ctx) {
1584+
EVP_MD_CTX_destroy(md_ctx);
1585+
}
1586+
if (error) {
1587+
spprintf(error, 0, "openssl signature could not be verified");
1588+
}
1589+
return FAILURE;
1590+
}
15831591
read_len = end_of_phar;
15841592

15851593
if ((size_t)read_len > sizeof(buf)) {

0 commit comments

Comments
 (0)