Skip to content

Commit 40052b3

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-16357: openssl may modify member types of certificate arrays
2 parents 9402121 + 33fab73 commit 40052b3

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

ext/openssl/openssl.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,11 +1524,13 @@ static X509 *php_openssl_x509_from_zval(
15241524

15251525
*free_cert = 1;
15261526

1527-
if (!try_convert_to_string(val)) {
1527+
zend_string *str = zval_try_get_string(val);
1528+
if (str == NULL) {
15281529
return NULL;
15291530
}
1530-
1531-
return php_openssl_x509_from_str(Z_STR_P(val), arg_num, is_from_array, option_name);
1531+
X509 *cert = php_openssl_x509_from_str(str, arg_num, is_from_array, option_name);
1532+
zend_string_release(str);
1533+
return cert;
15321534
}
15331535
/* }}} */
15341536

ext/openssl/tests/gh16357.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-16357 (openssl may modify member types of certificate arrays)
3+
--EXTENSIONS--
4+
openssl
5+
--FILE--
6+
<?php
7+
$infile = __DIR__ . "/cert.crt";
8+
$outfile = __DIR__ . "/gh16357.txt";
9+
$certs = [123];
10+
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $certs, null));
11+
var_dump($certs);
12+
?>
13+
--CLEAN--
14+
<?php
15+
unlink(__DIR__ . "/gh16357.txt");
16+
?>
17+
--EXPECT--
18+
bool(false)
19+
array(1) {
20+
[0]=>
21+
int(123)
22+
}

0 commit comments

Comments
 (0)