From: Richard Levitte Date: Fri, 11 Oct 2002 09:39:06 +0000 (+0000) Subject: BN_bn2hex() returns "0" instead of "00" for zero. This disrputs the X-Git-Tag: OpenSSL_0_9_6h~77 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cd9a79eae1c07728e6139627d3e61026208e94f2;p=oweals%2Fopenssl.git BN_bn2hex() returns "0" instead of "00" for zero. This disrputs the requirement that the serial number always be an even amount of characters. PR: 248 --- diff --git a/apps/ca.c b/apps/ca.c index d1fcf5228a..1563d99317 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -829,9 +829,14 @@ bad: } if (verbose) { - if ((f=BN_bn2hex(serial)) == NULL) goto err; - BIO_printf(bio_err,"next serial number is %s\n",f); - OPENSSL_free(f); + if (BN_is_zero(serial)) + BIO_printf(bio_err,"next serial number is 00\n"); + else + { + if ((f=BN_bn2hex(serial)) == NULL) goto err; + BIO_printf(bio_err,"next serial number is %s\n",f); + OPENSSL_free(f); + } } if ((attribs=CONF_get_section(conf,policy)) == NULL) @@ -1728,7 +1733,10 @@ again2: BIO_printf(bio_err,"The subject name appears to be ok, checking data base for clashes\n"); row[DB_name]=X509_NAME_oneline(subject,NULL,0); - row[DB_serial]=BN_bn2hex(serial); + if (BN_is_zero(serial)) + row[DB_serial]=BUF_strdup("00"); + else + row[DB_serial]=BN_bn2hex(serial); if ((row[DB_name] == NULL) || (row[DB_serial] == NULL)) { BIO_printf(bio_err,"Memory allocation failure\n"); @@ -2142,7 +2150,10 @@ static int do_revoke(X509 *x509, TXT_DB *db) row[i]=NULL; row[DB_name]=X509_NAME_oneline(X509_get_subject_name(x509),NULL,0); bn = ASN1_INTEGER_to_BN(X509_get_serialNumber(x509),NULL); - row[DB_serial]=BN_bn2hex(bn); + if (BN_is_zero(bn)) + row[DB_serial]=BUF_strdup("00"); + else + row[DB_serial]=BN_bn2hex(bn); BN_free(bn); if ((row[DB_name] == NULL) || (row[DB_serial] == NULL)) {