Skip to content

Commit 83a242e

Browse files
committedOct 22, 2023
Fix GH-12489: Missing sigbio creation checking in openssl_cms_verify
Closes GH-12490
1 parent 01d6160 commit 83a242e

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ PHP NEWS
2121
. Fixed bug GH-8143 (Crashes in zend_accel_inheritance_cache_find since
2222
upgrading to 8.1.3 due to corrupt on-disk file cache). (turchanov)
2323

24+
- OpenSSL:
25+
Fixed bug GH-12489 (Missing sigbio creation checking in openssl_cms_verify).
26+
(Jakub Zelenka)
27+
2428
- SOAP:
2529
. Fixed bug GH-12392 (Segmentation fault on SoapClient::__getTypes).
2630
(nielsdos)

‎ext/openssl/openssl.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -5900,12 +5900,15 @@ PHP_FUNCTION(openssl_cms_verify)
59005900
goto clean_exit;
59015901
}
59025902
if (sigfile && (flags & CMS_DETACHED)) {
5903-
sigbio = php_openssl_bio_new_file(sigfile, sigfile_len, 1, PHP_OPENSSL_BIO_MODE_R(flags));
59045903
if (encoding == ENCODING_SMIME) {
59055904
php_error_docref(NULL, E_WARNING,
59065905
"Detached signatures not possible with S/MIME encoding");
59075906
goto clean_exit;
59085907
}
5908+
sigbio = php_openssl_bio_new_file(sigfile, sigfile_len, 1, PHP_OPENSSL_BIO_MODE_R(flags));
5909+
if (sigbio == NULL) {
5910+
goto clean_exit;
5911+
}
59095912
} else {
59105913
sigbio = in; /* non-detached signature */
59115914
}

‎ext/openssl/tests/gh12489.phpt

+36
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)