Skip to content

Commit 33fab73

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-16357: openssl may modify member types of certificate arrays
2 parents 42f8776 + 76a819e commit 33fab73

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ PHP NEWS
3030
. Fixed bug GH-16361 (mb_substr overflow on start/length arguments).
3131
(David Carlier)
3232

33+
- OpenSSL:
34+
. Fixed bug GH-16357 (openssl may modify member types of certificate arrays).
35+
(cmb)
36+
3337
- PHPDBG:
3438
. Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb)
3539

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)