ssl/t1_lib.c:937: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] (⇐ [1, +oo] + [0, +oo]) Size: [0, +oo] by call to `i2d_X509_EXTENSIONS`.
Showing all 20 steps of the trace


ssl/t1_lib.c:669:1: Parameter `*s->tlsext_session_ticket->data`
667.   }
668.   
669. > unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
670.   	{
671.   	int extdatalen=0;

ssl/t1_lib.c:937:13: Call
935.   		if (s->tlsext_ocsp_exts)
936.   			{
937.   			extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);
                   ^
938.   			if (extlen < 0)
939.   				return NULL;

crypto/asn1/x_exten.c:75:1: Parameter `**out`
  73.   
  74.   IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
  75. > IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
  76.   IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)

crypto/asn1/x_exten.c:75:1: Call
  73.   
  74.   IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
  75. > IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
  76.   IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)

crypto/asn1/tasn_enc.c:89:1: Parameter `**out`
    87.   	}
    88.   
    89. > int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
    90.   	{
    91.   	return asn1_item_flags_i2d(val, out, it, 0);

crypto/asn1/tasn_enc.c:91:9: Call
    89.   int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
    90.   	{
    91.   	return asn1_item_flags_i2d(val, out, it, 0);
                  ^
    92.   	}
    93.   

crypto/asn1/tasn_enc.c:103:1: Parameter `**out`
      101.    */
      102.   
      103. > static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
      104.   					const ASN1_ITEM *it, int flags)
      105.   	{

crypto/asn1/tasn_enc.c:122:9: Call
      120.   		}
      121.   
      122.   	return ASN1_item_ex_i2d(&val, out, it, -1, flags);
                     ^
      123.   	}
      124.   

crypto/asn1/tasn_enc.c:130:1: Parameter `**out`
        128.    */
        129.   
        130. > int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
        131.   			const ASN1_ITEM *it, int tag, int aclass)
        132.   	{

crypto/asn1/tasn_enc.c:170:11: Call
        168.   			chtt = it->templates + i;
        169.   			pchval = asn1_get_field_ptr(pval, chtt);
        170.   			return asn1_template_ex_i2d(pchval, out, chtt,
                         ^
        171.   								-1, aclass);
        172.   			}

crypto/asn1/tasn_enc.c:270:1: Parameter `**out`
          268.   	}
          269.   
          270. > static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
          271.   				const ASN1_TEMPLATE *tt, int tag, int iclass)
          272.   	{

crypto/asn1/tasn_enc.c:376:3: Call
          374.   			ASN1_put_object(out, ndef, sklen, ttag, tclass);
          375.   		/* SET or SEQUENCE and IMPLICIT tag */
          376.   		ASN1_put_object(out, ndef, skcontlen, sktag, skaclass);
                   ^
          377.   		/* And the stuff itself */
          378.   		asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),

crypto/asn1/asn1_lib.c:208:7: <Offset trace>
206.   		{
207.   		*(p++)=i|V_ASN1_PRIMITIVE_TAG;
208.   		for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
             ^
209.   		ttag = i;
210.   		while(i-- > 0)

crypto/asn1/asn1_lib.c:208:7: Assignment
            206.   		{
            207.   		*(p++)=i|V_ASN1_PRIMITIVE_TAG;
            208.   		for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
                         ^
            209.   		ttag = i;
            210.   		while(i-- > 0)

crypto/asn1/asn1_lib.c:210:9: Assignment
            208.   		for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
            209.   		ttag = i;
            210.   		while(i-- > 0)
                           ^
            211.   			{
            212.   			p[i] = tag & 0x7f;

crypto/asn1/asn1_lib.c:195:1: <Length trace>
193.   /* class 0 is constructed
194.    * constructed == 2 for indefinite length constructed */
195. > void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
196.   	     int xclass)
197.   	{

crypto/asn1/asn1_lib.c:195:1: Parameter `**pp`
            193.   /* class 0 is constructed
            194.    * constructed == 2 for indefinite length constructed */
            195. > void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
            196.   	     int xclass)
            197.   	{

crypto/asn1/asn1_lib.c:198:2: Assignment
            196.   	     int xclass)
            197.   	{
            198.   	unsigned char *p= *pp;
                    ^
            199.   	int i, ttag;
            200.   

crypto/asn1/asn1_lib.c:207:5: Assignment
            205.   	else
            206.   		{
            207.   		*(p++)=i|V_ASN1_PRIMITIVE_TAG;
                       ^
            208.   		for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
            209.   		ttag = i;

crypto/asn1/asn1_lib.c:212:4: Array access: Offset: [1, +oo] (⇐ [1, +oo] + [0, +oo]) Size: [0, +oo] by call to `i2d_X509_EXTENSIONS` 
            210.   		while(i-- > 0)
            211.   			{
            212.   			p[i] = tag & 0x7f;
                      ^
            213.   			if(i != (ttag - 1)) p[i] |= 0x80;
            214.   			tag >>= 7;

void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
	     int xclass)
	{
	unsigned char *p= *pp;
	int i, ttag;
	i=(constructed)?V_ASN1_CONSTRUCTED:0;
	i|=(xclass&V_ASN1_PRIVATE);
	if (tag < 31)
		*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
	else
		{
		*(p++)=i|V_ASN1_PRIMITIVE_TAG;
		for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;
		ttag = i;
		while(i-- > 0)
			{
			p[i] = tag & 0x7f;
			if(i != (ttag - 1)) p[i] |= 0x80;
			tag >>= 7;
			}
		p += ttag;
		}
	if (constructed == 2)
		*(p++)=0x80;
	else
		asn1_put_length(&p,length);
	*pp=p;
	}
['unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)\n\t{\n\tint extdatalen=0;\n\tunsigned char *ret = p;\n#ifndef OPENSSL_NO_EC\n\tint using_ecc = 0;\n\tif (s->version != DTLS1_VERSION && s->version >= TLS1_VERSION)\n\t\t{\n\t\tint i;\n\t\tunsigned long alg_k, alg_a;\n\t\tSTACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n\t\tfor (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++)\n\t\t\t{\n\t\t\tSSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n\t\t\talg_k = c->algorithm_mkey;\n\t\t\talg_a = c->algorithm_auth;\n\t\t\tif ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)\n\t\t\t\t|| (alg_a & SSL_aECDSA)))\n\t\t\t\t{\n\t\t\t\tusing_ecc = 1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n\tif (s->client_version == SSL3_VERSION\n\t\t\t\t\t&& !s->s3->send_connection_binding)\n\t\treturn p;\n\tret+=2;\n\tif (ret>=limit) return NULL;\n \tif (s->tlsext_hostname != NULL)\n\t\t{\n\t\tunsigned long size_str;\n\t\tlong lenmax;\n\t\tif ((lenmax = limit - ret - 9) < 0\n\t\t    || (size_str = strlen(s->tlsext_hostname)) > (unsigned long)lenmax)\n\t\t\treturn NULL;\n\t\ts2n(TLSEXT_TYPE_server_name,ret);\n\t\ts2n(size_str+5,ret);\n\t\ts2n(size_str+3,ret);\n\t\t*(ret++) = (unsigned char) TLSEXT_NAMETYPE_host_name;\n\t\ts2n(size_str,ret);\n\t\tmemcpy(ret, s->tlsext_hostname, size_str);\n\t\tret+=size_str;\n\t\t}\n        if (s->renegotiate)\n          {\n          int el;\n          if(!ssl_add_clienthello_renegotiate_ext(s, 0, &el, 0))\n              {\n              SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n              return NULL;\n              }\n          if((limit - p - 4 - el) < 0) return NULL;\n          s2n(TLSEXT_TYPE_renegotiate,ret);\n          s2n(el,ret);\n          if(!ssl_add_clienthello_renegotiate_ext(s, ret, &el, el))\n              {\n              SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n              return NULL;\n              }\n          ret += el;\n        }\n#ifndef OPENSSL_NO_SRP\n\tif (s->srp_ctx.login != NULL)\n\t\t{\n\t\tint login_len = strlen(s->srp_ctx.login);\n\t\tif (login_len > 255 || login_len == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tif ((limit - ret - 5 - login_len) < 0) return NULL;\n\t\ts2n(TLSEXT_TYPE_srp,ret);\n\t\ts2n(login_len+1,ret);\n\t\t(*ret++) = (unsigned char) login_len;\n\t\tmemcpy(ret, s->srp_ctx.login, login_len);\n\t\tret+=login_len;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_EC\n\tif (using_ecc)\n\t\t{\n\t\tlong lenmax;\n\t\tconst unsigned char *plist;\n\t\tsize_t plistlen;\n\t\tplist = s->tlsext_ecpointformatlist;\n\t\tif (plist)\n\t\t\tplistlen = s->tlsext_ecpointformatlist_length;\n\t\telse\n\t\t\t{\n\t\t\tplist = ecformats_default;\n\t\t\tplistlen = sizeof(ecformats_default);\n\t\t\t}\n\t\tif ((lenmax = limit - ret - 5) < 0) return NULL;\n\t\tif (plistlen > (size_t)lenmax) return NULL;\n\t\tif (plistlen > 255)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n\t\t\treturn NULL;\n\t\t\t}\n\t\ts2n(TLSEXT_TYPE_ec_point_formats,ret);\n\t\ts2n(plistlen + 1,ret);\n\t\t*(ret++) = (unsigned char)plistlen ;\n\t\tmemcpy(ret, plist, plistlen);\n\t\tret+=plistlen;\n\t\tplist = s->tlsext_ellipticcurvelist;\n\t\ttls1_get_curvelist(s, 0, &plist, &plistlen);\n\t\tif ((lenmax = limit - ret - 6) < 0) return NULL;\n\t\tif (plistlen > (size_t)lenmax) return NULL;\n\t\tif (plistlen > 65532)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n\t\t\treturn NULL;\n\t\t\t}\n\t\ts2n(TLSEXT_TYPE_elliptic_curves,ret);\n\t\ts2n(plistlen + 2, ret);\n\t\ts2n(plistlen, ret);\n\t\tmemcpy(ret, plist, plistlen);\n\t\tret+=plistlen;\n\t\t}\n#endif\n\tif (!(SSL_get_options(s) & SSL_OP_NO_TICKET))\n\t\t{\n\t\tint ticklen;\n\t\tif (!s->new_session && s->session && s->session->tlsext_tick)\n\t\t\tticklen = s->session->tlsext_ticklen;\n\t\telse if (s->session && s->tlsext_session_ticket &&\n\t\t\t s->tlsext_session_ticket->data)\n\t\t\t{\n\t\t\tticklen = s->tlsext_session_ticket->length;\n\t\t\ts->session->tlsext_tick = OPENSSL_malloc(ticklen);\n\t\t\tif (!s->session->tlsext_tick)\n\t\t\t\treturn NULL;\n\t\t\tmemcpy(s->session->tlsext_tick,\n\t\t\t       s->tlsext_session_ticket->data,\n\t\t\t       ticklen);\n\t\t\ts->session->tlsext_ticklen = ticklen;\n\t\t\t}\n\t\telse\n\t\t\tticklen = 0;\n\t\tif (ticklen == 0 && s->tlsext_session_ticket &&\n\t\t    s->tlsext_session_ticket->data == NULL)\n\t\t\tgoto skip_ext;\n\t\tif ((long)(limit - ret - 4 - ticklen) < 0) return NULL;\n\t\ts2n(TLSEXT_TYPE_session_ticket,ret);\n\t\ts2n(ticklen,ret);\n\t\tif (ticklen)\n\t\t\t{\n\t\t\tmemcpy(ret, s->session->tlsext_tick, ticklen);\n\t\t\tret += ticklen;\n\t\t\t}\n\t\t}\n\t\tskip_ext:\n\tif (TLS1_get_client_version(s) >= TLS1_2_VERSION)\n\t\t{\n\t\tsize_t salglen;\n\t\tsalglen = tls12_get_sig_algs(s, NULL);\n\t\tif ((size_t)(limit - ret) < salglen + 6)\n\t\t\treturn NULL;\n\t\ts2n(TLSEXT_TYPE_signature_algorithms,ret);\n\t\ts2n(salglen + 2, ret);\n\t\ts2n(salglen, ret);\n\t\ttls12_get_sig_algs(s, ret);\n\t\tret += salglen;\n\t\t}\n#ifdef TLSEXT_TYPE_opaque_prf_input\n\tif (s->s3->client_opaque_prf_input != NULL &&\n\t    s->version != DTLS1_VERSION)\n\t\t{\n\t\tsize_t col = s->s3->client_opaque_prf_input_len;\n\t\tif ((long)(limit - ret - 6 - col < 0))\n\t\t\treturn NULL;\n\t\tif (col > 0xFFFD)\n\t\t\treturn NULL;\n\t\ts2n(TLSEXT_TYPE_opaque_prf_input, ret);\n\t\ts2n(col + 2, ret);\n\t\ts2n(col, ret);\n\t\tmemcpy(ret, s->s3->client_opaque_prf_input, col);\n\t\tret += col;\n\t\t}\n#endif\n\tif (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp &&\n\t    s->version != DTLS1_VERSION)\n\t\t{\n\t\tint i;\n\t\tlong extlen, idlen, itmp;\n\t\tOCSP_RESPID *id;\n\t\tidlen = 0;\n\t\tfor (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++)\n\t\t\t{\n\t\t\tid = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n\t\t\titmp = i2d_OCSP_RESPID(id, NULL);\n\t\t\tif (itmp <= 0)\n\t\t\t\treturn NULL;\n\t\t\tidlen += itmp + 2;\n\t\t\t}\n\t\tif (s->tlsext_ocsp_exts)\n\t\t\t{\n\t\t\textlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n\t\t\tif (extlen < 0)\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\telse\n\t\t\textlen = 0;\n\t\tif ((long)(limit - ret - 7 - extlen - idlen) < 0) return NULL;\n\t\ts2n(TLSEXT_TYPE_status_request, ret);\n\t\tif (extlen + idlen > 0xFFF0)\n\t\t\treturn NULL;\n\t\ts2n(extlen + idlen + 5, ret);\n\t\t*(ret++) = TLSEXT_STATUSTYPE_ocsp;\n\t\ts2n(idlen, ret);\n\t\tfor (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++)\n\t\t\t{\n\t\t\tunsigned char *q = ret;\n\t\t\tid = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n\t\t\tret += 2;\n\t\t\titmp = i2d_OCSP_RESPID(id, &ret);\n\t\t\ts2n(itmp, q);\n\t\t\t}\n\t\ts2n(extlen, ret);\n\t\tif (extlen > 0)\n\t\t\ti2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ret);\n\t\t}\n#ifndef OPENSSL_NO_HEARTBEATS\n\ts2n(TLSEXT_TYPE_heartbeat,ret);\n\ts2n(1,ret);\n\tif (s->tlsext_heartbeat & SSL_TLSEXT_HB_DONT_RECV_REQUESTS)\n\t\t*(ret++) = SSL_TLSEXT_HB_DONT_SEND_REQUESTS;\n\telse\n\t\t*(ret++) = SSL_TLSEXT_HB_ENABLED;\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n\tif (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len)\n\t\t{\n\t\tif (limit - ret - 4 < 0)\n\t\t\treturn NULL;\n\t\ts2n(TLSEXT_TYPE_next_proto_neg,ret);\n\t\ts2n(0,ret);\n\t\t}\n#endif\n        if(SSL_get_srtp_profiles(s))\n                {\n                int el;\n                ssl_add_clienthello_use_srtp_ext(s, 0, &el, 0);\n                if((limit - p - 4 - el) < 0) return NULL;\n                s2n(TLSEXT_TYPE_use_srtp,ret);\n                s2n(el,ret);\n                if(ssl_add_clienthello_use_srtp_ext(s, ret, &el, el))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n\t\t\treturn NULL;\n\t\t\t}\n                ret += el;\n                }\n\tif (s->ctx->tlsext_authz_server_audit_proof_cb != NULL)\n\t\t{\n\t\tsize_t lenmax;\n                const unsigned short ext_len = 2;\n                const unsigned char list_len = 1;\n\t\tif ((lenmax = limit - ret - 6) < 0) return NULL;\n\t\ts2n(TLSEXT_TYPE_server_authz, ret);\n\t\ts2n(ext_len, ret);\n\t\t*(ret++) = list_len;\n\t\t*(ret++) = TLSEXT_AUTHZDATAFORMAT_audit_proof;\n\t\t}\n\tif ((extdatalen = ret-p-2) == 0)\n\t\treturn p;\n\ts2n(extdatalen,p);\n\treturn ret;\n\t}', 'IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)', 'int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)\n\t{\n\treturn asn1_item_flags_i2d(val, out, it, 0);\n\t}', 'static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,\n\t\t\t\t\tconst ASN1_ITEM *it, int flags)\n\t{\n\tif (out && !*out)\n\t\t{\n\t\tunsigned char *p, *buf;\n\t\tint len;\n\t\tlen = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);\n\t\tif (len <= 0)\n\t\t\treturn len;\n\t\tbuf = OPENSSL_malloc(len);\n\t\tif (!buf)\n\t\t\treturn -1;\n\t\tp = buf;\n\t\tASN1_item_ex_i2d(&val, &p, it, -1, flags);\n\t\t*out = buf;\n\t\treturn len;\n\t\t}\n\treturn ASN1_item_ex_i2d(&val, out, it, -1, flags);\n\t}', 'int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,\n\t\t\tconst ASN1_ITEM *it, int tag, int aclass)\n\t{\n\tconst ASN1_TEMPLATE *tt = NULL;\n\tunsigned char *p = NULL;\n\tint i, seqcontlen, seqlen, ndef = 1;\n\tconst ASN1_COMPAT_FUNCS *cf;\n\tconst ASN1_EXTERN_FUNCS *ef;\n\tconst ASN1_AUX *aux = it->funcs;\n\tASN1_aux_cb *asn1_cb = 0;\n\tif ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)\n\t\treturn 0;\n\tif (aux && aux->asn1_cb)\n\t\t asn1_cb = aux->asn1_cb;\n\tswitch(it->itype)\n\t\t{\n\t\tcase ASN1_ITYPE_PRIMITIVE:\n\t\tif (it->templates)\n\t\t\treturn asn1_template_ex_i2d(pval, out, it->templates,\n\t\t\t\t\t\t\t\ttag, aclass);\n\t\treturn asn1_i2d_ex_primitive(pval, out, it, tag, aclass);\n\t\tbreak;\n\t\tcase ASN1_ITYPE_MSTRING:\n\t\treturn asn1_i2d_ex_primitive(pval, out, it, -1, aclass);\n\t\tcase ASN1_ITYPE_CHOICE:\n\t\tif (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))\n\t\t\t\treturn 0;\n\t\ti = asn1_get_choice_selector(pval, it);\n\t\tif ((i >= 0) && (i < it->tcount))\n\t\t\t{\n\t\t\tASN1_VALUE **pchval;\n\t\t\tconst ASN1_TEMPLATE *chtt;\n\t\t\tchtt = it->templates + i;\n\t\t\tpchval = asn1_get_field_ptr(pval, chtt);\n\t\t\treturn asn1_template_ex_i2d(pchval, out, chtt,\n\t\t\t\t\t\t\t\t-1, aclass);\n\t\t\t}\n\t\tif (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))\n\t\t\t\treturn 0;\n\t\tbreak;\n\t\tcase ASN1_ITYPE_EXTERN:\n\t\tef = it->funcs;\n\t\treturn ef->asn1_ex_i2d(pval, out, it, tag, aclass);\n\t\tcase ASN1_ITYPE_COMPAT:\n\t\tcf = it->funcs;\n\t\tif (out)\n\t\t\tp = *out;\n\t\ti = cf->asn1_i2d(*pval, out);\n\t\tif (out && (tag != -1))\n\t\t\t*p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);\n\t\treturn i;\n\t\tcase ASN1_ITYPE_NDEF_SEQUENCE:\n\t\tif (aclass & ASN1_TFLG_NDEF) ndef = 2;\n\t\tcase ASN1_ITYPE_SEQUENCE:\n\t\ti = asn1_enc_restore(&seqcontlen, out, pval, it);\n\t\tif (i < 0)\n\t\t\treturn 0;\n\t\tif (i > 0)\n\t\t\treturn seqcontlen;\n\t\tseqcontlen = 0;\n\t\tif (tag == -1)\n\t\t\t{\n\t\t\ttag = V_ASN1_SEQUENCE;\n\t\t\taclass = (aclass & ~ASN1_TFLG_TAG_CLASS)\n\t\t\t\t\t| V_ASN1_UNIVERSAL;\n\t\t\t}\n\t\tif (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))\n\t\t\t\treturn 0;\n\t\tfor (i = 0, tt = it->templates; i < it->tcount; tt++, i++)\n\t\t\t{\n\t\t\tconst ASN1_TEMPLATE *seqtt;\n\t\t\tASN1_VALUE **pseqval;\n\t\t\tseqtt = asn1_do_adb(pval, tt, 1);\n\t\t\tif (!seqtt)\n\t\t\t\treturn 0;\n\t\t\tpseqval = asn1_get_field_ptr(pval, seqtt);\n\t\t\tseqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,\n\t\t\t\t\t\t\t\t-1, aclass);\n\t\t\t}\n\t\tseqlen = ASN1_object_size(ndef, seqcontlen, tag);\n\t\tif (!out)\n\t\t\treturn seqlen;\n\t\tASN1_put_object(out, ndef, seqcontlen, tag, aclass);\n\t\tfor (i = 0, tt = it->templates; i < it->tcount; tt++, i++)\n\t\t\t{\n\t\t\tconst ASN1_TEMPLATE *seqtt;\n\t\t\tASN1_VALUE **pseqval;\n\t\t\tseqtt = asn1_do_adb(pval, tt, 1);\n\t\t\tif (!seqtt)\n\t\t\t\treturn 0;\n\t\t\tpseqval = asn1_get_field_ptr(pval, seqtt);\n\t\t\tasn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);\n\t\t\t}\n\t\tif (ndef == 2)\n\t\t\tASN1_put_eoc(out);\n\t\tif (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))\n\t\t\t\treturn 0;\n\t\treturn seqlen;\n\t\tdefault:\n\t\treturn 0;\n\t\t}\n\treturn 0;\n\t}', 'static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,\n\t\t\t\tconst ASN1_TEMPLATE *tt, int tag, int iclass)\n\t{\n\tint i, ret, flags, ttag, tclass, ndef;\n\tflags = tt->flags;\n\tif (flags & ASN1_TFLG_TAG_MASK)\n\t\t{\n\t\tif (tag != -1)\n\t\t\treturn -1;\n\t\tttag = tt->tag;\n\t\ttclass = flags & ASN1_TFLG_TAG_CLASS;\n\t\t}\n\telse if (tag != -1)\n\t\t{\n\t\tttag = tag;\n\t\ttclass = iclass & ASN1_TFLG_TAG_CLASS;\n\t\t}\n\telse\n\t\t{\n\t\tttag = -1;\n\t\ttclass = 0;\n\t\t}\n\ticlass &= ~ASN1_TFLG_TAG_CLASS;\n\tif ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))\n\t\tndef = 2;\n\telse ndef = 1;\n\tif (flags & ASN1_TFLG_SK_MASK)\n\t\t{\n\t\tSTACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;\n\t\tint isset, sktag, skaclass;\n\t\tint skcontlen, sklen;\n\t\tASN1_VALUE *skitem;\n\t\tif (!*pval)\n\t\t\treturn 0;\n\t\tif (flags & ASN1_TFLG_SET_OF)\n\t\t\t{\n\t\t\tisset = 1;\n\t\t\tif (flags & ASN1_TFLG_SEQUENCE_OF)\n\t\t\t\tisset = 2;\n\t\t\t}\n\t\telse isset = 0;\n\t\tif ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG))\n\t\t\t{\n\t\t\tsktag = ttag;\n\t\t\tskaclass = tclass;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tskaclass = V_ASN1_UNIVERSAL;\n\t\t\tif (isset)\n\t\t\t\tsktag = V_ASN1_SET;\n\t\t\telse sktag = V_ASN1_SEQUENCE;\n\t\t\t}\n\t\tskcontlen = 0;\n\t\tfor (i = 0; i < sk_ASN1_VALUE_num(sk); i++)\n\t\t\t{\n\t\t\tskitem = sk_ASN1_VALUE_value(sk, i);\n\t\t\tskcontlen += ASN1_item_ex_i2d(&skitem, NULL,\n\t\t\t\t\t\tASN1_ITEM_ptr(tt->item),\n\t\t\t\t\t\t\t-1, iclass);\n\t\t\t}\n\t\tsklen = ASN1_object_size(ndef, skcontlen, sktag);\n\t\tif (flags & ASN1_TFLG_EXPTAG)\n\t\t\tret = ASN1_object_size(ndef, sklen, ttag);\n\t\telse ret = sklen;\n\t\tif (!out)\n\t\t\treturn ret;\n\t\tif (flags & ASN1_TFLG_EXPTAG)\n\t\t\tASN1_put_object(out, ndef, sklen, ttag, tclass);\n\t\tASN1_put_object(out, ndef, skcontlen, sktag, skaclass);\n\t\tasn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item),\n\t\t\t\t\t\t\t\tisset, iclass);\n\t\tif (ndef == 2)\n\t\t\t{\n\t\t\tASN1_put_eoc(out);\n\t\t\tif (flags & ASN1_TFLG_EXPTAG)\n\t\t\t\tASN1_put_eoc(out);\n\t\t\t}\n\t\treturn ret;\n\t\t}\n\tif (flags & ASN1_TFLG_EXPTAG)\n\t\t{\n\t\ti = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item),\n\t\t\t\t\t\t\t\t-1, iclass);\n\t\tif (!i)\n\t\t\treturn 0;\n\t\tret = ASN1_object_size(ndef, i, ttag);\n\t\tif (out)\n\t\t\t{\n\t\t\tASN1_put_object(out, ndef, i, ttag, tclass);\n\t\t\tASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),\n\t\t\t\t\t\t\t\t-1, iclass);\n\t\t\tif (ndef == 2)\n\t\t\t\tASN1_put_eoc(out);\n\t\t\t}\n\t\treturn ret;\n\t\t}\n\treturn ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),\n\t\t\t\t\t\tttag, tclass | iclass);\n}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t     int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i, ttag;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMITIVE_TAG;\n\t\tfor(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7;\n\t\tttag = i;\n\t\twhile(i-- > 0)\n\t\t\t{\n\t\t\tp[i] = tag & 0x7f;\n\t\t\tif(i != (ttag - 1)) p[i] |= 0x80;\n\t\t\ttag >>= 7;\n\t\t\t}\n\t\tp += ttag;\n\t\t}\n\tif (constructed == 2)\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}']