Skip to content

Commit 549bcdb

Browse files
committed
Fix GH-16357: openssl may modify member types of certificate arrays
We must not use `try_convert_to_string()` on members of unseparated array arguments; instead of separating, we use `zval_try_get_string()`. Closes GH-16370.
1 parent 2554640 commit 549bcdb

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
@@ -25,6 +25,10 @@ PHP NEWS
2525
. Fixed bug GH-16361 (mb_substr overflow on start/length arguments).
2626
(David Carlier)
2727

28+
- OpenSSL:
29+
. Fixed bug GH-16357 (openssl may modify member types of certificate arrays).
30+
(cmb)
31+
2832
- PHPDBG:
2933
. Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb)
3034

ext/openssl/openssl.c

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

14581458
*free_cert = 1;
14591459

1460-
if (!try_convert_to_string(val)) {
1460+
zend_string *str = zval_try_get_string(val);
1461+
if (str == NULL) {
14611462
return NULL;
14621463
}
1463-
1464-
return php_openssl_x509_from_str(Z_STR_P(val), arg_num, is_from_array, option_name);
1464+
X509 *cert = php_openssl_x509_from_str(str, arg_num, is_from_array, option_name);
1465+
zend_string_release(str);
1466+
return cert;
14651467
}
14661468
/* }}} */
14671469

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)