Remove unnecessary use of ASN1_const_CTX

Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Dr. Stephen Henson 2015-04-03 18:28:06 +01:00
parent cc5b6a03a3
commit 1880790e2e

View File

@ -146,12 +146,15 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
BUF_MEM *b; BUF_MEM *b;
unsigned char *p; unsigned char *p;
int i; int i;
ASN1_const_CTX c;
size_t want = HEADER_SIZE; size_t want = HEADER_SIZE;
int eos = 0; int eos = 0;
size_t off = 0; size_t off = 0;
size_t len = 0; size_t len = 0;
const unsigned char *q;
long slen;
int inf, tag, xclass;
b = BUF_MEM_new(); b = BUF_MEM_new();
if (b == NULL) { if (b == NULL) {
ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE); ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ERR_R_MALLOC_FAILURE);
@ -183,10 +186,9 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
/* else data already loaded */ /* else data already loaded */
p = (unsigned char *)&(b->data[off]); p = (unsigned char *)&(b->data[off]);
c.p = p; q = p;
c.inf = ASN1_get_object(&(c.p), &(c.slen), &(c.tag), &(c.xclass), inf = ASN1_get_object(&q, &slen, &tag, &xclass, len - off);
len - off); if (inf & 0x80) {
if (c.inf & 0x80) {
unsigned long e; unsigned long e;
e = ERR_GET_REASON(ERR_peek_error()); e = ERR_GET_REASON(ERR_peek_error());
@ -195,10 +197,10 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
else else
ERR_clear_error(); /* clear error */ ERR_clear_error(); /* clear error */
} }
i = c.p - p; /* header length */ i = q - p; /* header length */
off += i; /* end of data */ off += i; /* end of data */
if (c.inf & 1) { if (inf & 1) {
/* no data body so go round again */ /* no data body so go round again */
eos++; eos++;
if (eos < 0) { if (eos < 0) {
@ -206,7 +208,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
goto err; goto err;
} }
want = HEADER_SIZE; want = HEADER_SIZE;
} else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) { } else if (eos && (slen == 0) && (tag == V_ASN1_EOC)) {
/* eos value, so go back and read another header */ /* eos value, so go back and read another header */
eos--; eos--;
if (eos <= 0) if (eos <= 0)
@ -214,8 +216,8 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
else else
want = HEADER_SIZE; want = HEADER_SIZE;
} else { } else {
/* suck in c.slen bytes of data */ /* suck in slen bytes of data */
want = c.slen; want = slen;
if (want > (len - off)) { if (want > (len - off)) {
want -= (len - off); want -= (len - off);
if (want > INT_MAX /* BIO_read takes an int length */ || if (want > INT_MAX /* BIO_read takes an int length */ ||
@ -242,11 +244,11 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
want -= i; want -= i;
} }
} }
if (off + c.slen < off) { if (off + slen < off) {
ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG); ASN1err(ASN1_F_ASN1_D2I_READ_BIO, ASN1_R_TOO_LONG);
goto err; goto err;
} }
off += c.slen; off += slen;
if (eos <= 0) { if (eos <= 0) {
break; break;
} else } else