Skip to content

Commit 5b0a469

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #52093: openssl_csr_sign truncates $serial
2 parents 540fed1 + 334387b commit 5b0a469

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ PHP NEWS
1919
(cmb)
2020
. Fixed bug #68471 (IntlDateFormatter fails for "GMT+00:00" timezone). (cmb)
2121

22+
- OpenSSL:
23+
. Fixed bug #52093 (openssl_csr_sign truncates $serial). (cmb)
24+
2225
- PCRE:
2326
. Fixed bug #81101 (PCRE2 10.37 shows unexpected result). (Anatol)
2427

ext/openssl/openssl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,8 +3236,11 @@ PHP_FUNCTION(openssl_csr_sign)
32363236
goto cleanup;
32373237
}
32383238

3239-
3240-
ASN1_INTEGER_set(X509_get_serialNumber(new_cert), (long)serial);
3239+
#if PHP_OPENSSL_API_VERSION >= 0x10100
3240+
ASN1_INTEGER_set_int64(X509_get_serialNumber(new_cert), serial);
3241+
#else
3242+
ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial);
3243+
#endif
32413244

32423245
X509_set_subject_name(new_cert, X509_REQ_get_subject_name(csr));
32433246

ext/openssl/tests/bug52093.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #52093 (openssl_csr_sign truncates $serial)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("openssl")) print "skip";
6+
if (PHP_INT_SIZE !== 8) die("skip this test is for 64bit platforms only");
7+
?>
8+
--FILE--
9+
<?php
10+
$dn = array(
11+
"countryName" => "BR",
12+
"stateOrProvinceName" => "Rio Grande do Sul",
13+
"localityName" => "Porto Alegre",
14+
"commonName" => "Henrique do N. Angelo",
15+
"emailAddress" => "[email protected]"
16+
);
17+
18+
$privkey = openssl_pkey_new();
19+
$csr = openssl_csr_new($dn, $privkey);
20+
$cert = openssl_csr_sign($csr, null, $privkey, 365, [], PHP_INT_MAX);
21+
var_dump(openssl_x509_parse($cert)['serialNumber']);
22+
?>
23+
--EXPECT--
24+
string(19) "9223372036854775807"

0 commit comments

Comments
 (0)