Skip to content

Commit a13cca8

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: 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 256d23c + 22c9e7e commit a13cca8

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ PHP NEWS
1212
- Opcache:
1313
. Fixed build for macOS to cater with pkg-config settings. (David Carlier)
1414

15+
- OpenSSL:
16+
. Add missing error checks on file writing functions. (nielsdos)
17+
1518
- Phar:
1619
. Fixed bug GH-10766 (PharData archive created with Phar::Zip format does
1720
not keep files metadata (datetime)). (nielsdos)
21+
. Add missing error checks on EVP_MD_CTX_create() and EVP_VerifyInit().
22+
(nielsdos)
1823

1924
16 Mar 2023, PHP 8.2.4
2025

ext/openssl/openssl.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,11 +2600,13 @@ PHP_FUNCTION(openssl_pkcs12_export_to_file)
26002600
if (p12 != NULL) {
26012601
bio_out = BIO_new_file(file_path, PHP_OPENSSL_BIO_MODE_W(PKCS7_BINARY));
26022602
if (bio_out != NULL) {
2603-
2604-
i2d_PKCS12_bio(bio_out, p12);
2603+
if (i2d_PKCS12_bio(bio_out, p12) == 0) {
2604+
php_openssl_store_errors();
2605+
php_error_docref(NULL, E_WARNING, "Error writing to file %s", file_path);
2606+
} else {
2607+
RETVAL_TRUE;
2608+
}
26052609
BIO_free(bio_out);
2606-
2607-
RETVAL_TRUE;
26082610
} else {
26092611
php_openssl_store_errors();
26102612
php_error_docref(NULL, E_WARNING, "Error opening file %s", file_path);
@@ -5288,7 +5290,11 @@ PHP_FUNCTION(openssl_pkcs7_verify)
52885290
}
52895291

52905292
if (p7bout) {
5291-
PEM_write_bio_PKCS7(p7bout, p7);
5293+
if (PEM_write_bio_PKCS7(p7bout, p7) == 0) {
5294+
php_error_docref(NULL, E_WARNING, "Failed to write PKCS7 to file");
5295+
php_openssl_store_errors();
5296+
RETVAL_FALSE;
5297+
}
52925298
}
52935299
}
52945300
} else {
@@ -5873,7 +5879,11 @@ PHP_FUNCTION(openssl_cms_verify)
58735879
}
58745880

58755881
if (p7bout) {
5876-
PEM_write_bio_CMS(p7bout, cms);
5882+
if (PEM_write_bio_CMS(p7bout, cms) == 0) {
5883+
php_error_docref(NULL, E_WARNING, "Failed to write CMS to file");
5884+
php_openssl_store_errors();
5885+
RETVAL_FALSE;
5886+
}
58775887
}
58785888
}
58795889
} else {

ext/phar/util.c

Lines changed: 9 additions & 1 deletion
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)