Don't shift serial number into sign bit

Reviewed-by: Rich Salz <rsalz@openssl.org>
(cherry picked from commit 01c32b5e44)
This commit is contained in:
Dr. Stephen Henson 2016-03-04 18:04:46 +00:00
parent 298d823bf8
commit 0199251318

View file

@ -140,7 +140,8 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
goto err;
bs = X509_get_serialNumber(x);
if (bs->length <= (int)sizeof(long)) {
if (bs->length < (int)sizeof(long)
|| (bs->length == sizeof(long) && (bs->data[0] & 0x80) == 0)) {
l = ASN1_INTEGER_get(bs);
if (bs->type == V_ASN1_NEG_INTEGER) {
l = -l;