uint32_t eos = 0;
size_t off = 0;
size_t len = 0;
+ size_t diff;
const unsigned char *q;
long slen;
ERR_clear_error();
for (;;) {
- if (want >= (len - off)) {
- want -= (len - off);
+ diff = len - off;
+ if (want >= diff) {
+ want -= diff;
if (len + want < len || !BUF_MEM_grow_clean(b, len + want)) {
ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
goto err;
}
i = BIO_read(in, &(b->data[len]), want);
- if ((i < 0) && ((len - off) == 0)) {
+ if (i < 0 && diff == 0) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_NOT_ENOUGH_DATA);
goto err;
}
p = (unsigned char *)&(b->data[off]);
q = p;
- inf = ASN1_get_object(&q, &slen, &tag, &xclass, len - off);
+ diff = len - off;
+ if (diff == 0)
+ goto err;
+ inf = ASN1_get_object(&q, &slen, &tag, &xclass, diff);
if (inf & 0x80) {
unsigned long e;
e = ERR_GET_REASON(ERR_peek_error());
if (e != ASN1_R_TOO_LONG)
goto err;
- else
- ERR_clear_error(); /* clear error */
+ ERR_clear_error();
}
i = q - p; /* header length */
off += i; /* end of data */
int tag, xclass, inf;
long max = omax;
- if (!max)
- goto err;
+ if (omax <= 0) {
+ ERR_raise(ERR_LIB_ASN1, ASN1_R_TOO_SMALL);
+ return 0x80;
+ }
ret = (*p & V_ASN1_CONSTRUCTED);
xclass = (*p & V_ASN1_PRIVATE);
i = *p & V_ASN1_PRIMITIVE_TAG;
ERR_raise(ERR_LIB_ASN1, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
+ if (len <= 0) {
+ ERR_raise(ERR_LIB_ASN1, ASN1_R_TOO_SMALL);
+ return 0;
+ }
aux = it->funcs;
if (aux && aux->asn1_cb)
asn1_cb = aux->asn1_cb;
p = *in;
q = p;
+ if (len <= 0) {
+ ERR_raise(ERR_LIB_ASN1, ASN1_R_TOO_SMALL);
+ goto err;
+ }
if (ctx != NULL && ctx->valid) {
i = ctx->ret;
plen = ctx->plen;
*/
if ((i & 0x81) == 0 && (plen + ctx->hdrlen) > len) {
ERR_raise(ERR_LIB_ASN1, ASN1_R_TOO_LONG);
- asn1_tlc_clear(ctx);
- return 0;
+ goto err;
}
}
}
- if ((i & 0x80) != 0)
+ if ((i & 0x80) != 0) {
+ ERR_raise(ERR_LIB_ASN1, ASN1_R_BAD_OBJECT_HEADER);
goto err;
+ }
if (exptag >= 0) {
if (exptag != ptag || expclass != pclass) {
/*
*/
if (opt != 0)
return -1;
- asn1_tlc_clear(ctx);
ERR_raise(ERR_LIB_ASN1, ASN1_R_WRONG_TAG);
- return 0;
+ goto err;
}
/*
* We have a tag and class match: assume we are going to do something
return 1;
err:
- ERR_raise(ERR_LIB_ASN1, ASN1_R_BAD_OBJECT_HEADER);
asn1_tlc_clear(ctx);
return 0;
}