Skip to content

Commit 58ca47a

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #52093: openssl_csr_sign truncates $serial
2 parents d3deb82 + 5b0a469 commit 58ca47a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

ext/openssl/openssl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,8 +3220,11 @@ PHP_FUNCTION(openssl_csr_sign)
32203220
goto cleanup;
32213221
}
32223222

3223-
3224-
ASN1_INTEGER_set(X509_get_serialNumber(new_cert), (long)serial);
3223+
#if PHP_OPENSSL_API_VERSION >= 0x10100
3224+
ASN1_INTEGER_set_int64(X509_get_serialNumber(new_cert), serial);
3225+
#else
3226+
ASN1_INTEGER_set(X509_get_serialNumber(new_cert), serial);
3227+
#endif
32253228

32263229
X509_set_subject_name(new_cert, X509_REQ_get_subject_name(csr));
32273230

ext/openssl/tests/bug52093.phpt

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

0 commit comments

Comments
 (0)