crypto/pem/pem_pkey.c:42: error: BUFFER_OVERRUN_L3
  Offset: [2, +oo] Size: [1, +oo] by call to `d2i_PKCS8_PRIV_KEY_INFO`.
Showing all 27 steps of the trace


crypto/pem/pem_pkey.c:35:10: Call
33.       EVP_PKEY *ret = NULL;
34.   
35.       if (!PEM_bytes_read_bio_secmem(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp,
               ^
36.   				   cb, u))
37.           return NULL;

crypto/pem/pem_lib.c:287:1: Parameter `**pdata`
  285.   }
  286.   
  287. > int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,
  288.                                 const char *name, BIO *bp, pem_password_cb *cb,
  289.                                 void *u) {

crypto/pem/pem_lib.c:290:12: Call
  288.                                 const char *name, BIO *bp, pem_password_cb *cb,
  289.                                 void *u) {
  290.       return pem_bytes_read_bio_flags(pdata, plen, pnm, name, bp, cb, u,
                    ^
  291.                                       PEM_FLAG_SECURE | PEM_FLAG_EAY_COMPATIBLE);
  292.   }

crypto/pem/pem_lib.c:237:1: Parameter `**pdata`
    235.   }
    236.   
    237. > static int pem_bytes_read_bio_flags(unsigned char **pdata, long *plen,
    238.                                       char **pnm, const char *name, BIO *bp,
    239.                                       pem_password_cb *cb, void *u,

crypto/pem/pem_pkey.c:38:5: Assignment
36.   				   cb, u))
37.           return NULL;
38.       p = data;
          ^
39.   
40.       if (strcmp(nm, PEM_STRING_PKCS8INF) == 0) {

crypto/pem/pem_pkey.c:42:17: Call
40.       if (strcmp(nm, PEM_STRING_PKCS8INF) == 0) {
41.           PKCS8_PRIV_KEY_INFO *p8inf;
42.           p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
                      ^
43.           if (!p8inf)
44.               goto p8err;

crypto/asn1/p8_pkey.c:36:1: Parameter `**in`
  34.   } ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  35.   
  36. > IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
  37.   
  38.   int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,

crypto/asn1/p8_pkey.c:36:1: Call
  34.   } ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
  35.   
  36. > IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)
  37.   
  38.   int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj,

crypto/asn1/tasn_dec.c:105:1: Parameter `**in`
    103.    */
    104.   
    105. > ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
    106.                             const unsigned char **in, long len,
    107.                             const ASN1_ITEM *it)

crypto/asn1/tasn_dec.c:114:9: Call
    112.           pval = &ptmpval;
    113.       asn1_tlc_clear_nc(&c);
    114.       if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
                   ^
    115.           return *pval;
    116.       return NULL;

crypto/asn1/tasn_dec.c:119:1: Parameter `**in`
      117.   }
      118.   
      119. > int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
      120.                        const ASN1_ITEM *it,
      121.                        int tag, int aclass, char opt, ASN1_TLC *ctx)

crypto/asn1/tasn_dec.c:124:10: Call
      122.   {
      123.       int rv;
      124.       rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx, 0);
                      ^
      125.       if (rv <= 0)
      126.           ASN1_item_ex_free(pval, it);

crypto/asn1/tasn_dec.c:135:1: Parameter `**in`
        133.    */
        134.   
        135. > static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,
        136.                                  long len, const ASN1_ITEM *it,
        137.                                  int tag, int aclass, char opt, ASN1_TLC *ctx,

crypto/asn1/tasn_dec.c:185:9: Assignment
        183.   
        184.       case ASN1_ITYPE_MSTRING:
        185.           p = *in;
                       ^
        186.           /* Just read in tag and class */
        187.           ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,

crypto/asn1/tasn_dec.c:187:15: Call
        185.           p = *in;
        186.           /* Just read in tag and class */
        187.           ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
                             ^
        188.                                 &p, len, -1, 0, 1, ctx);
        189.           if (!ret) {

crypto/asn1/tasn_dec.c:1078:1: Parameter `**in`
          1076.    */
          1077.   
          1078. > static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
          1079.                              char *inf, char *cst,
          1080.                              const unsigned char **in, long len,

crypto/asn1/tasn_dec.c:1087:5: Assignment
          1085.       long plen;
          1086.       const unsigned char *p, *q;
          1087.       p = *in;
                      ^
          1088.       q = p;
          1089.   

crypto/asn1/tasn_dec.c:1097:13: Call
          1095.           p += ctx->hdrlen;
          1096.       } else {
          1097.           i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
                              ^
          1098.           if (ctx) {
          1099.               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:112:1: <Length trace>
110.    * are stored most significant digit first.
111.    */
112. > static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
113.                              long max)
114.   {

crypto/asn1/asn1_lib.c:112:1: Parameter `**pp`
              110.    * are stored most significant digit first.
              111.    */
              112. > static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
              113.                              long max)
              114.   {

crypto/asn1/asn1_lib.c:115:5: Assignment
              113.                              long max)
              114.   {
              115.       const unsigned char *p = *pp;
                         ^
              116.       unsigned long ret = 0;
              117.       int i;

crypto/asn1/asn1_lib.c:127:14: Assignment
              125.           *inf = 0;
              126.           i = *p & 0x7f;
              127.           if (*p++ & 0x80) {
                                  ^
              128.               if (max < i + 1)
              129.                   return 0;

crypto/asn1/asn1_lib.c:131:29: Array access: Offset: [2, +oo] Size: [1, +oo] by call to `d2i_PKCS8_PRIV_KEY_INFO` 
              129.                   return 0;
              130.               /* Skip leading zeroes */
              131.               while (i > 0 && *p == 0) {
                                                 ^
              132.                   p++;
              133.                   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;
    int i;
    if (max-- < 1)
        return 0;
    if (*p == 0x80) {
        *inf = 1;
        p++;
    } else {
        *inf = 0;
        i = *p & 0x7f;
        if (*p++ & 0x80) {
            if (max < i + 1)
                return 0;
            while (i > 0 && *p == 0) {
                p++;
                i--;
            }
            if (i > (int)sizeof(long))
                return 0;
            while (i > 0) {
                ret <<= 8;
                ret |= *p++;
                i--;
            }
            if (ret > LONG_MAX)
                return 0;
        } else
            ret = i;
    }
    *pp = p;
    *rl = (long)ret;
    return 1;
}
['EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,\n                                  void *u)\n{\n    char *nm = NULL;\n    const unsigned char *p = NULL;\n    unsigned char *data = NULL;\n    long len;\n    int slen;\n    EVP_PKEY *ret = NULL;\n    if (!PEM_bytes_read_bio_secmem(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp,\n\t\t\t\t   cb, u))\n        return NULL;\n    p = data;\n    if (strcmp(nm, PEM_STRING_PKCS8INF) == 0) {\n        PKCS8_PRIV_KEY_INFO *p8inf;\n        p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);\n        if (!p8inf)\n            goto p8err;\n        ret = EVP_PKCS82PKEY(p8inf);\n        if (x) {\n            EVP_PKEY_free((EVP_PKEY *)*x);\n            *x = ret;\n        }\n        PKCS8_PRIV_KEY_INFO_free(p8inf);\n    } else if (strcmp(nm, PEM_STRING_PKCS8) == 0) {\n        PKCS8_PRIV_KEY_INFO *p8inf;\n        X509_SIG *p8;\n        int klen;\n        char psbuf[PEM_BUFSIZE];\n        p8 = d2i_X509_SIG(NULL, &p, len);\n        if (!p8)\n            goto p8err;\n        if (cb)\n            klen = cb(psbuf, PEM_BUFSIZE, 0, u);\n        else\n            klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);\n        if (klen <= 0) {\n            PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, PEM_R_BAD_PASSWORD_READ);\n            X509_SIG_free(p8);\n            goto err;\n        }\n        p8inf = PKCS8_decrypt(p8, psbuf, klen);\n        X509_SIG_free(p8);\n        OPENSSL_cleanse(psbuf, klen);\n        if (!p8inf)\n            goto p8err;\n        ret = EVP_PKCS82PKEY(p8inf);\n        if (x) {\n            EVP_PKEY_free((EVP_PKEY *)*x);\n            *x = ret;\n        }\n        PKCS8_PRIV_KEY_INFO_free(p8inf);\n    } else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0) {\n        const EVP_PKEY_ASN1_METHOD *ameth;\n        ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);\n        if (!ameth || !ameth->old_priv_decode)\n            goto p8err;\n        ret = d2i_PrivateKey(ameth->pkey_id, x, &p, len);\n    }\n p8err:\n    if (ret == NULL)\n        PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB);\n err:\n    OPENSSL_secure_free(nm);\n    OPENSSL_secure_clear_free(data, len);\n    return ret;\n}', 'int PEM_bytes_read_bio_secmem(unsigned char **pdata, long *plen, char **pnm,\n                              const char *name, BIO *bp, pem_password_cb *cb,\n                              void *u) {\n    return pem_bytes_read_bio_flags(pdata, plen, pnm, name, bp, cb, u,\n                                    PEM_FLAG_SECURE | PEM_FLAG_EAY_COMPATIBLE);\n}', 'static int pem_bytes_read_bio_flags(unsigned char **pdata, long *plen,\n                                    char **pnm, const char *name, BIO *bp,\n                                    pem_password_cb *cb, void *u,\n                                    unsigned int flags)\n{\n    EVP_CIPHER_INFO cipher;\n    char *nm = NULL, *header = NULL;\n    unsigned char *data = NULL;\n    long len = 0;\n    int ret = 0;\n    do {\n        pem_free(nm, flags, 0);\n        pem_free(header, flags, 0);\n        pem_free(data, flags, len);\n        if (!PEM_read_bio_ex(bp, &nm, &header, &data, &len, flags)) {\n            if (ERR_GET_REASON(ERR_peek_error()) == PEM_R_NO_START_LINE)\n                ERR_add_error_data(2, "Expecting: ", name);\n            return 0;\n        }\n    } while (!check_pem(nm, name));\n    if (!PEM_get_EVP_CIPHER_INFO(header, &cipher))\n        goto err;\n    if (!PEM_do_header(&cipher, data, &len, cb, u))\n        goto err;\n    *pdata = data;\n    *plen = len;\n    if (pnm != NULL)\n        *pnm = nm;\n    ret = 1;\n err:\n    if (!ret || pnm == NULL)\n        pem_free(nm, flags, 0);\n    pem_free(header, flags, 0);\n    if (!ret)\n        pem_free(data, flags, len);\n    return ret;\n}', 'IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO)', '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, 0);\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                               int depth)\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    if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {\n        ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_NESTED_TOO_DEEP);\n        goto err;\n    }\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, depth);\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, depth);\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                                       depth);\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    int i;\n    if (max-- < 1)\n        return 0;\n    if (*p == 0x80) {\n        *inf = 1;\n        p++;\n    } else {\n        *inf = 0;\n        i = *p & 0x7f;\n        if (*p++ & 0x80) {\n            if (max < i + 1)\n                return 0;\n            while (i > 0 && *p == 0) {\n                p++;\n                i--;\n            }\n            if (i > (int)sizeof(long))\n                return 0;\n            while (i > 0) {\n                ret <<= 8;\n                ret |= *p++;\n                i--;\n            }\n            if (ret > LONG_MAX)\n                return 0;\n        } else\n            ret = i;\n    }\n    *pp = p;\n    *rl = (long)ret;\n    return 1;\n}']