Skip to content

Commit d105257

Browse files
committed
Merge branch 'PHP-8.3'
2 parents 7699534 + ac07b6e commit d105257

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

ext/openssl/openssl.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5986,12 +5986,15 @@ PHP_FUNCTION(openssl_cms_verify)
59865986
goto clean_exit;
59875987
}
59885988
if (sigfile && (flags & CMS_DETACHED)) {
5989-
sigbio = php_openssl_bio_new_file(sigfile, sigfile_len, 1, PHP_OPENSSL_BIO_MODE_R(flags));
59905989
if (encoding == ENCODING_SMIME) {
59915990
php_error_docref(NULL, E_WARNING,
59925991
"Detached signatures not possible with S/MIME encoding");
59935992
goto clean_exit;
59945993
}
5994+
sigbio = php_openssl_bio_new_file(sigfile, sigfile_len, 1, PHP_OPENSSL_BIO_MODE_R(flags));
5995+
if (sigbio == NULL) {
5996+
goto clean_exit;
5997+
}
59955998
} else {
59965999
sigbio = in; /* non-detached signature */
59976000
}

ext/openssl/tests/gh12489.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
GH-12489: Missing sigbio creation checking in openssl_cms_verify
3+
--EXTENSIONS--
4+
openssl
5+
--FILE--
6+
<?php
7+
$infile = __DIR__ . "/plain.txt";
8+
$outfile = __DIR__ . "/out.cms";;
9+
$vout = $outfile . '.vout';
10+
11+
$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
12+
$single_cert = "file://" . __DIR__ . "/cert.crt";
13+
$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_cms_sign()");
14+
$headers = array("test@test", "testing openssl_cms_sign()");
15+
16+
var_dump(openssl_cms_sign($infile, $outfile, openssl_x509_read($single_cert), $privkey, $headers,
17+
OPENSSL_CMS_DETACHED|OPENSSL_CMS_BINARY,OPENSSL_ENCODING_PEM));
18+
ini_set('open_basedir', __DIR__);
19+
var_dump(openssl_cms_verify($infile,OPENSSL_CMS_NOVERIFY|OPENSSL_CMS_DETACHED|OPENSSL_CMS_BINARY,
20+
NULL, array(), NULL, $vout, NULL, "../test.cms", OPENSSL_ENCODING_PEM));
21+
var_dump(openssl_error_string());
22+
?>
23+
--CLEAN--
24+
<?php
25+
$outfile = __DIR__ . "/out.cms";;
26+
$vout = $outfile . '.vout';
27+
28+
@unlink($outfile);
29+
@unlink($vout);
30+
?>
31+
--EXPECTF--
32+
bool(true)
33+
34+
Warning: openssl_cms_verify(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
35+
bool(false)
36+
bool(false)

0 commit comments

Comments
 (0)