test/ct_test.c:497: error: BUFFER_OVERRUN_L3
  Offset: [2, +oo] Size: [1, 12] by call to `CTLOG_new_from_base64`.
Showing all 31 steps of the trace


test/ct_test.c:492:5: Array declaration
490.   {
491.       CTLOG *ctlogp = NULL;
492.       const char notb64[] = "\01\02\03\04";
           ^
493.       const char pad[] = "====";
494.       const char name[] = "name";

test/ct_test.c:497:10: Call
495.   
496.       /* We expect these to both fail! */
497.       if (!TEST_true(!CTLOG_new_from_base64(&ctlogp, notb64, name))
                ^
498.           || !TEST_true(!CTLOG_new_from_base64(&ctlogp, pad, name)))
499.           return 0;

crypto/ct/ct_b64.c:135:1: Parameter `pkey_base64->strlen`
  133.    * -1 on internal (malloc) failure
  134.    */
  135. > int CTLOG_new_from_base64(CTLOG **ct_log, const char *pkey_base64, const char *name)
  136.   {
  137.       unsigned char *pkey_der = NULL;

crypto/ct/ct_b64.c:147:20: Call
  145.       }
  146.   
  147.       pkey_der_len = ct_base64_decode(pkey_base64, &pkey_der);
                            ^
  148.       if (pkey_der_len < 0) {
  149.           CTerr(CT_F_CTLOG_NEW_FROM_BASE64, CT_R_LOG_CONF_INVALID_KEY);

crypto/ct/ct_b64.c:24:1: Parameter `**out`
    22.    * the caller. Do not provide a pre-allocated string in |out|.
    23.    */
    24. > static int ct_base64_decode(const char *in, unsigned char **out)
    25.   {
    26.       size_t inlen = strlen(in);

crypto/ct/ct_b64.c:153:5: Assignment
  151.       }
  152.   
  153.       p = pkey_der;
             ^
  154.       pkey = d2i_PUBKEY(NULL, &p, pkey_der_len);
  155.       OPENSSL_free(pkey_der);

crypto/ct/ct_b64.c:154:12: Call
  152.   
  153.       p = pkey_der;
  154.       pkey = d2i_PUBKEY(NULL, &p, pkey_der_len);
                    ^
  155.       OPENSSL_free(pkey_der);
  156.       if (pkey == NULL) {

crypto/x509/x_pubkey.c:181:1: Parameter `**pp`
    179.    */
    180.   
    181. > EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length)
    182.   {
    183.       X509_PUBKEY *xpk;

crypto/x509/x_pubkey.c:186:5: Assignment
    184.       EVP_PKEY *pktmp;
    185.       const unsigned char *q;
    186.       q = *pp;
               ^
    187.       xpk = d2i_X509_PUBKEY(NULL, &q, length);
    188.       if (!xpk)

crypto/x509/x_pubkey.c:187:11: Call
    185.       const unsigned char *q;
    186.       q = *pp;
    187.       xpk = d2i_X509_PUBKEY(NULL, &q, length);
                     ^
    188.       if (!xpk)
    189.           return NULL;

crypto/x509/x_pubkey.c:57:1: Parameter `**in`
      55.   } ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY)
      56.   
      57. > IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
      58.   
      59.   int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)

crypto/x509/x_pubkey.c:57:1: Call
      55.   } ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY)
      56.   
      57. > IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
      58.   
      59.   int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)

crypto/asn1/tasn_dec.c:95:1: Parameter `**in`
        93.    */
        94.   
        95. > ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
        96.                             const unsigned char **in, long len,
        97.                             const ASN1_ITEM *it)

crypto/asn1/tasn_dec.c:104:9: Call
        102.           pval = &ptmpval;
        103.       asn1_tlc_clear_nc(&c);
        104.       if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
                       ^
        105.           return *pval;
        106.       return NULL;

crypto/asn1/tasn_dec.c:109:1: Parameter `**in`
          107.   }
          108.   
          109. > int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
          110.                        const ASN1_ITEM *it,
          111.                        int tag, int aclass, char opt, ASN1_TLC *ctx)

crypto/asn1/tasn_dec.c:114:10: Call
          112.   {
          113.       int rv;
          114.       rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx);
                          ^
          115.       if (rv <= 0)
          116.           ASN1_item_ex_free(pval, it);

crypto/asn1/tasn_dec.c:125:1: Parameter `**in`
            123.    */
            124.   
            125. > static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
            126.                                  long len, const ASN1_ITEM *it,
            127.                                  int tag, int aclass, char opt, ASN1_TLC *ctx)

crypto/asn1/tasn_dec.c:169:9: Assignment
            167.   
            168.       case ASN1_ITYPE_MSTRING:
            169.           p = *in;
                           ^
            170.           /* Just read in tag and class */
            171.           ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,

crypto/asn1/tasn_dec.c:171:15: Call
            169.           p = *in;
            170.           /* Just read in tag and class */
            171.           ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
                                 ^
            172.                                 &p, len, -1, 0, 1, ctx);
            173.           if (!ret) {

crypto/asn1/tasn_dec.c:1060:1: Parameter `**in`
              1058.    */
              1059.   
              1060. > static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
              1061.                              char *inf, char *cst,
              1062.                              const unsigned char **in, long len,

crypto/asn1/tasn_dec.c:1069:5: Assignment
              1067.       long plen;
              1068.       const unsigned char *p, *q;
              1069.       p = *in;
                          ^
              1070.       q = p;
              1071.   

crypto/asn1/tasn_dec.c:1079:13: Call
              1077.           p += ctx->hdrlen;
              1078.       } else {
              1079.           i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
                                  ^
              1080.           if (ctx) {
              1081.               ctx->ret = i;

crypto/asn1/asn1_lib.c:44:1: Parameter `**pp`
                42.   }
                43.   
                44. > int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
                45.                       int *pclass, long omax)
                46.   {

crypto/asn1/asn1_lib.c:49:5: Assignment
                47.       int i, ret;
                48.       long l;
                49.       const unsigned char *p = *pp;
                          ^
                50.       int tag, xclass, inf;
                51.       long max = omax;

crypto/asn1/asn1_lib.c:78:9: Assignment
                76.       } else {
                77.           tag = i;
                78.           p++;
                              ^
                79.           if (--max == 0)
                80.               goto err;

crypto/asn1/asn1_lib.c:84:10: Call
                82.       *ptag = tag;
                83.       *pclass = xclass;
                84.       if (!asn1_get_length(&p, &inf, plength, max))
                               ^
                85.           goto err;
                86.   

crypto/asn1/asn1_lib.c:105:1: <Length trace>
103.   }
104.   
105. > static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
106.                              long max)
107.   {

crypto/asn1/asn1_lib.c:105:1: Parameter `**pp`
                  103.   }
                  104.   
                  105. > static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
                  106.                              long max)
                  107.   {

crypto/asn1/asn1_lib.c:108:5: Assignment
                  106.                              long max)
                  107.   {
                  108.       const unsigned char *p = *pp;
                             ^
                  109.       unsigned long ret = 0;
                  110.       unsigned long i;

crypto/asn1/asn1_lib.c:121:15: Assignment
                  119.           *inf = 0;
                  120.           i = *p & 0x7f;
                  121.           if (*(p++) & 0x80) {
                                       ^
                  122.               if (max < (long)i + 1)
                  123.                   return 0;

crypto/asn1/asn1_lib.c:125:25: Array access: Offset: [2, +oo] Size: [1, 12] by call to `CTLOG_new_from_base64` 
                  123.                   return 0;
                  124.               /* Skip leading zeroes */
                  125.               while (i && *p == 0) {
                                                 ^
                  126.                   p++;
                  127.                   i--;

static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
                           long max)
{
    const unsigned char *p = *pp;
    unsigned long ret = 0;
    unsigned long i;
    if (max-- < 1)
        return 0;
    if (*p == 0x80) {
        *inf = 1;
        ret = 0;
        p++;
    } else {
        *inf = 0;
        i = *p & 0x7f;
        if (*(p++) & 0x80) {
            if (max < (long)i + 1)
                return 0;
            while (i && *p == 0) {
                p++;
                i--;
            }
            if (i > sizeof(long))
                return 0;
            while (i-- > 0) {
                ret <<= 8L;
                ret |= *(p++);
            }
        } else
            ret = i;
    }
    if (ret > LONG_MAX)
        return 0;
    *pp = p;
    *rl = (long)ret;
    return 1;
}
['static int test_ctlog_from_base64(void)\n{\n    CTLOG *ctlogp = NULL;\n    const char notb64[] = "\\01\\02\\03\\04";\n    const char pad[] = "====";\n    const char name[] = "name";\n    if (!TEST_true(!CTLOG_new_from_base64(&ctlogp, notb64, name))\n        || !TEST_true(!CTLOG_new_from_base64(&ctlogp, pad, name)))\n        return 0;\n    return 1;\n}', 'int CTLOG_new_from_base64(CTLOG **ct_log, const char *pkey_base64, const char *name)\n{\n    unsigned char *pkey_der = NULL;\n    int pkey_der_len;\n    const unsigned char *p;\n    EVP_PKEY *pkey = NULL;\n    if (ct_log == NULL) {\n        CTerr(CT_F_CTLOG_NEW_FROM_BASE64, ERR_R_PASSED_INVALID_ARGUMENT);\n        return 0;\n    }\n    pkey_der_len = ct_base64_decode(pkey_base64, &pkey_der);\n    if (pkey_der_len < 0) {\n        CTerr(CT_F_CTLOG_NEW_FROM_BASE64, CT_R_LOG_CONF_INVALID_KEY);\n        return 0;\n    }\n    p = pkey_der;\n    pkey = d2i_PUBKEY(NULL, &p, pkey_der_len);\n    OPENSSL_free(pkey_der);\n    if (pkey == NULL) {\n        CTerr(CT_F_CTLOG_NEW_FROM_BASE64, CT_R_LOG_CONF_INVALID_KEY);\n        return 0;\n    }\n    *ct_log = CTLOG_new(pkey, name);\n    if (*ct_log == NULL) {\n        EVP_PKEY_free(pkey);\n        return 0;\n    }\n    return 1;\n}', "static int ct_base64_decode(const char *in, unsigned char **out)\n{\n    size_t inlen = strlen(in);\n    int outlen, i;\n    unsigned char *outbuf = NULL;\n    if (inlen == 0) {\n        *out = NULL;\n        return 0;\n    }\n    outlen = (inlen / 4) * 3;\n    outbuf = OPENSSL_malloc(outlen);\n    if (outbuf == NULL) {\n        CTerr(CT_F_CT_BASE64_DECODE, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);\n    if (outlen < 0) {\n        CTerr(CT_F_CT_BASE64_DECODE, CT_R_BASE64_DECODE_ERROR);\n        goto err;\n    }\n    i = 0;\n    while (in[--inlen] == '=') {\n        --outlen;\n        if (++i > 2)\n            goto err;\n    }\n    *out = outbuf;\n    return outlen;\nerr:\n    OPENSSL_free(outbuf);\n    return -1;\n}", 'EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, long length)\n{\n    X509_PUBKEY *xpk;\n    EVP_PKEY *pktmp;\n    const unsigned char *q;\n    q = *pp;\n    xpk = d2i_X509_PUBKEY(NULL, &q, length);\n    if (!xpk)\n        return NULL;\n    pktmp = X509_PUBKEY_get(xpk);\n    X509_PUBKEY_free(xpk);\n    if (!pktmp)\n        return NULL;\n    *pp = q;\n    if (a) {\n        EVP_PKEY_free(*a);\n        *a = pktmp;\n    }\n    return pktmp;\n}', 'IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)', 'ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,\n                          const unsigned char **in, long len,\n                          const ASN1_ITEM *it)\n{\n    ASN1_TLC c;\n    ASN1_VALUE *ptmpval = NULL;\n    if (!pval)\n        pval = &ptmpval;\n    asn1_tlc_clear_nc(&c);\n    if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)\n        return *pval;\n    return NULL;\n}', 'int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n                     const ASN1_ITEM *it,\n                     int tag, int aclass, char opt, ASN1_TLC *ctx)\n{\n    int rv;\n    rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx);\n    if (rv <= 0)\n        ASN1_item_ex_free(pval, it);\n    return rv;\n}', 'static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,\n                               long len, const ASN1_ITEM *it,\n                               int tag, int aclass, char opt, ASN1_TLC *ctx)\n{\n    const ASN1_TEMPLATE *tt, *errtt = NULL;\n    const ASN1_EXTERN_FUNCS *ef;\n    const ASN1_AUX *aux = it->funcs;\n    ASN1_aux_cb *asn1_cb;\n    const unsigned char *p = NULL, *q;\n    unsigned char oclass;\n    char seq_eoc, seq_nolen, cst, isopt;\n    long tmplen;\n    int i;\n    int otag;\n    int ret = 0;\n    ASN1_VALUE **pchptr;\n    if (!pval)\n        return 0;\n    if (aux && aux->asn1_cb)\n        asn1_cb = aux->asn1_cb;\n    else\n        asn1_cb = 0;\n    switch (it->itype) {\n    case ASN1_ITYPE_PRIMITIVE:\n        if (it->templates) {\n            if ((tag != -1) || opt) {\n                ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I,\n                        ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);\n                goto err;\n            }\n            return asn1_template_ex_d2i(pval, in, len,\n                                        it->templates, opt, ctx);\n        }\n        return asn1_d2i_ex_primitive(pval, in, len, it,\n                                     tag, aclass, opt, ctx);\n    case ASN1_ITYPE_MSTRING:\n        p = *in;\n        ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,\n                              &p, len, -1, 0, 1, ctx);\n        if (!ret) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n            goto err;\n        }\n        if (oclass != V_ASN1_UNIVERSAL) {\n            if (opt)\n                return -1;\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);\n            goto err;\n        }\n        if (!(ASN1_tag2bit(otag) & it->utype)) {\n            if (opt)\n                return -1;\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MSTRING_WRONG_TAG);\n            goto err;\n        }\n        return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);\n    case ASN1_ITYPE_EXTERN:\n        ef = it->funcs;\n        return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);\n    case ASN1_ITYPE_CHOICE:\n        if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))\n            goto auxerr;\n        if (*pval) {\n            i = asn1_get_choice_selector(pval, it);\n            if ((i >= 0) && (i < it->tcount)) {\n                tt = it->templates + i;\n                pchptr = asn1_get_field_ptr(pval, tt);\n                asn1_template_free(pchptr, tt);\n                asn1_set_choice_selector(pval, -1, it);\n            }\n        } else if (!ASN1_item_ex_new(pval, it)) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n            goto err;\n        }\n        p = *in;\n        for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {\n            pchptr = asn1_get_field_ptr(pval, tt);\n            ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);\n            if (ret == -1)\n                continue;\n            if (ret > 0)\n                break;\n            asn1_template_free(pchptr, tt);\n            errtt = tt;\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n            goto err;\n        }\n        if (i == it->tcount) {\n            if (opt) {\n                ASN1_item_ex_free(pval, it);\n                return -1;\n            }\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);\n            goto err;\n        }\n        asn1_set_choice_selector(pval, i, it);\n        if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))\n            goto auxerr;\n        *in = p;\n        return 1;\n    case ASN1_ITYPE_NDEF_SEQUENCE:\n    case ASN1_ITYPE_SEQUENCE:\n        p = *in;\n        tmplen = len;\n        if (tag == -1) {\n            tag = V_ASN1_SEQUENCE;\n            aclass = V_ASN1_UNIVERSAL;\n        }\n        ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,\n                              &p, len, tag, aclass, opt, ctx);\n        if (!ret) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n            goto err;\n        } else if (ret == -1)\n            return -1;\n        if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {\n            len = tmplen - (p - *in);\n            seq_nolen = 1;\n        }\n        else\n            seq_nolen = seq_eoc;\n        if (!cst) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);\n            goto err;\n        }\n        if (!*pval && !ASN1_item_ex_new(pval, it)) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n            goto err;\n        }\n        if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))\n            goto auxerr;\n        for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {\n            if (tt->flags & ASN1_TFLG_ADB_MASK) {\n                const ASN1_TEMPLATE *seqtt;\n                ASN1_VALUE **pseqval;\n                seqtt = asn1_do_adb(pval, tt, 0);\n                if (seqtt == NULL)\n                    continue;\n                pseqval = asn1_get_field_ptr(pval, seqtt);\n                asn1_template_free(pseqval, seqtt);\n            }\n        }\n        for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {\n            const ASN1_TEMPLATE *seqtt;\n            ASN1_VALUE **pseqval;\n            seqtt = asn1_do_adb(pval, tt, 1);\n            if (seqtt == NULL)\n                goto err;\n            pseqval = asn1_get_field_ptr(pval, seqtt);\n            if (!len)\n                break;\n            q = p;\n            if (asn1_check_eoc(&p, len)) {\n                if (!seq_eoc) {\n                    ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_UNEXPECTED_EOC);\n                    goto err;\n                }\n                len -= p - q;\n                seq_eoc = 0;\n                q = p;\n                break;\n            }\n            if (i == (it->tcount - 1))\n                isopt = 0;\n            else\n                isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);\n            ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);\n            if (!ret) {\n                errtt = seqtt;\n                goto err;\n            } else if (ret == -1) {\n                asn1_template_free(pseqval, seqtt);\n                continue;\n            }\n            len -= p - q;\n        }\n        if (seq_eoc && !asn1_check_eoc(&p, len)) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MISSING_EOC);\n            goto err;\n        }\n        if (!seq_nolen && len) {\n            ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);\n            goto err;\n        }\n        for (; i < it->tcount; tt++, i++) {\n            const ASN1_TEMPLATE *seqtt;\n            seqtt = asn1_do_adb(pval, tt, 1);\n            if (seqtt == NULL)\n                goto err;\n            if (seqtt->flags & ASN1_TFLG_OPTIONAL) {\n                ASN1_VALUE **pseqval;\n                pseqval = asn1_get_field_ptr(pval, seqtt);\n                asn1_template_free(pseqval, seqtt);\n            } else {\n                errtt = seqtt;\n                ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_FIELD_MISSING);\n                goto err;\n            }\n        }\n        if (!asn1_enc_save(pval, *in, p - *in, it))\n            goto auxerr;\n        if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))\n            goto auxerr;\n        *in = p;\n        return 1;\n    default:\n        return 0;\n    }\n auxerr:\n    ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_AUX_ERROR);\n err:\n    if (errtt)\n        ERR_add_error_data(4, "Field=", errtt->field_name,\n                           ", Type=", it->sname);\n    else\n        ERR_add_error_data(2, "Type=", it->sname);\n    return 0;\n}', 'static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,\n                           char *inf, char *cst,\n                           const unsigned char **in, long len,\n                           int exptag, int expclass, char opt, ASN1_TLC *ctx)\n{\n    int i;\n    int ptag, pclass;\n    long plen;\n    const unsigned char *p, *q;\n    p = *in;\n    q = p;\n    if (ctx && ctx->valid) {\n        i = ctx->ret;\n        plen = ctx->plen;\n        pclass = ctx->pclass;\n        ptag = ctx->ptag;\n        p += ctx->hdrlen;\n    } else {\n        i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);\n        if (ctx) {\n            ctx->ret = i;\n            ctx->plen = plen;\n            ctx->pclass = pclass;\n            ctx->ptag = ptag;\n            ctx->hdrlen = p - q;\n            ctx->valid = 1;\n            if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {\n                ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);\n                asn1_tlc_clear(ctx);\n                return 0;\n            }\n        }\n    }\n    if (i & 0x80) {\n        ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);\n        asn1_tlc_clear(ctx);\n        return 0;\n    }\n    if (exptag >= 0) {\n        if ((exptag != ptag) || (expclass != pclass)) {\n            if (opt)\n                return -1;\n            asn1_tlc_clear(ctx);\n            ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);\n            return 0;\n        }\n        asn1_tlc_clear(ctx);\n    }\n    if (i & 1)\n        plen = len - (p - q);\n    if (inf)\n        *inf = i & 1;\n    if (cst)\n        *cst = i & V_ASN1_CONSTRUCTED;\n    if (olen)\n        *olen = plen;\n    if (oclass)\n        *oclass = pclass;\n    if (otag)\n        *otag = ptag;\n    *in = p;\n    return 1;\n}', 'int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\n                    int *pclass, long omax)\n{\n    int i, ret;\n    long l;\n    const unsigned char *p = *pp;\n    int tag, xclass, inf;\n    long max = omax;\n    if (!max)\n        goto err;\n    ret = (*p & V_ASN1_CONSTRUCTED);\n    xclass = (*p & V_ASN1_PRIVATE);\n    i = *p & V_ASN1_PRIMITIVE_TAG;\n    if (i == V_ASN1_PRIMITIVE_TAG) {\n        p++;\n        if (--max == 0)\n            goto err;\n        l = 0;\n        while (*p & 0x80) {\n            l <<= 7L;\n            l |= *(p++) & 0x7f;\n            if (--max == 0)\n                goto err;\n            if (l > (INT_MAX >> 7L))\n                goto err;\n        }\n        l <<= 7L;\n        l |= *(p++) & 0x7f;\n        tag = (int)l;\n        if (--max == 0)\n            goto err;\n    } else {\n        tag = i;\n        p++;\n        if (--max == 0)\n            goto err;\n    }\n    *ptag = tag;\n    *pclass = xclass;\n    if (!asn1_get_length(&p, &inf, plength, max))\n        goto err;\n    if (inf && !(ret & V_ASN1_CONSTRUCTED))\n        goto err;\n    if (*plength > (omax - (p - *pp))) {\n        ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG);\n        ret |= 0x80;\n    }\n    *pp = p;\n    return (ret | inf);\n err:\n    ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_HEADER_TOO_LONG);\n    return (0x80);\n}', 'static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,\n                           long max)\n{\n    const unsigned char *p = *pp;\n    unsigned long ret = 0;\n    unsigned long i;\n    if (max-- < 1)\n        return 0;\n    if (*p == 0x80) {\n        *inf = 1;\n        ret = 0;\n        p++;\n    } else {\n        *inf = 0;\n        i = *p & 0x7f;\n        if (*(p++) & 0x80) {\n            if (max < (long)i + 1)\n                return 0;\n            while (i && *p == 0) {\n                p++;\n                i--;\n            }\n            if (i > sizeof(long))\n                return 0;\n            while (i-- > 0) {\n                ret <<= 8L;\n                ret |= *(p++);\n            }\n        } else\n            ret = i;\n    }\n    if (ret > LONG_MAX)\n        return 0;\n    *pp = p;\n    *rl = (long)ret;\n    return 1;\n}']