ssl/t1_lib.c:1284: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: 28 by call to `tls_curve_allowed`.
Showing all 7 steps of the trace


ssl/t1_lib.c:1116:1: Parameter `*s->session->tlsext_ellipticcurvelist`
1114.   	}
1115.   
1116. > unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, int *al)
1117.   	{
1118.   	int extdatalen=0;

ssl/t1_lib.c:1284:8: Call
1282.   		for (i = 0; i < plistlen; i += 2, plist += 2)
1283.   			{
1284.   			if (tls_curve_allowed(s, plist, SSL_SECOP_CURVE_SUPPORTED))
               ^
1285.   				{
1286.   				*etmp++ = plist[0];

ssl/t1_lib.c:429:1: <Offset trace>
427.   
428.   /* See if curve is allowed by security callback */
429. > static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
430.   	{
431.   	const tls_curve_info *cinfo;

ssl/t1_lib.c:429:1: Parameter `*curve`
  427.   
  428.   /* See if curve is allowed by security callback */
  429. > static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
  430.   	{
  431.   	const tls_curve_info *cinfo;

ssl/t1_lib.c:235:1: <Length trace>
233.   #define TLS_CURVE_PRIME		0x0
234.   
235. > static const tls_curve_info nid_list[] =
236.   	{
237.   		{NID_sect163k1, 80, TLS_CURVE_CHAR2},/* sect163k1 (1) */

ssl/t1_lib.c:235:1: Array declaration
  233.   #define TLS_CURVE_PRIME		0x0
  234.   
  235. > static const tls_curve_info nid_list[] =
  236.   	{
  237.   		{NID_sect163k1, 80, TLS_CURVE_CHAR2},/* sect163k1 (1) */

ssl/t1_lib.c:437:2: Array access: Offset: [-1, +oo] Size: 28 by call to `tls_curve_allowed` 
  435.   				sizeof(nid_list)/sizeof(nid_list[0])))
  436.   		return 0;
  437.   	cinfo = &nid_list[curve[1]-1];
          ^
  438.   	return ssl_security(s, op, cinfo->secbits, cinfo->nid, (void *)curve);
  439.   	}

static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
	{
	const tls_curve_info *cinfo;
	if (curve[0])
		return 1;
	if ((curve[1] < 1) || ((size_t)curve[1] >
				sizeof(nid_list)/sizeof(nid_list[0])))
		return 0;
	cinfo = &nid_list[curve[1]-1];
	return ssl_security(s, op, cinfo->secbits, cinfo->nid, (void *)curve);
	}
['unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, int *al)\n\t{\n\tint extdatalen=0;\n\tunsigned char *orig = buf;\n\tunsigned char *ret = buf;\n#ifndef OPENSSL_NO_EC\n\tint using_ecc = 0;\n\tif (s->version >= TLS1_VERSION || SSL_IS_DTLS(s))\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_kECDHE|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 orig;\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 - ret - 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\tsize_t i;\n\t\tunsigned char *etmp;\n\t\ttls1_get_formatlist(s, &plist, &plistlen);\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\tetmp = ret + 4;\n\t\tfor (i = 0; i < plistlen; i += 2, plist += 2)\n\t\t\t{\n\t\t\tif (tls_curve_allowed(s, plist, SSL_SECOP_CURVE_SUPPORTED))\n\t\t\t\t{\n\t\t\t\t*etmp++ = plist[0];\n\t\t\t\t*etmp++ = plist[1];\n\t\t\t\t}\n\t\t\t}\n\t\tplistlen = etmp - ret - 4;\n\t\ts2n(plistlen + 2, ret);\n\t\ts2n(plistlen, ret);\n\t\tret+=plistlen;\n\t\t}\n#endif\n\tif (tls_use_ticket(s))\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 (SSL_USE_SIGALGS(s))\n\t\t{\n\t\tsize_t salglen;\n\t\tconst unsigned char *salg;\n\t\tunsigned char *etmp;\n\t\tsalglen = tls12_get_psigalgs(s, &salg);\n\t\tif ((size_t)(limit - ret) < salglen + 6)\n\t\t\treturn NULL;\n\t\ts2n(TLSEXT_TYPE_signature_algorithms,ret);\n\t\tetmp = ret;\n\t\tret += 4;\n\t\tsalglen = tls12_copy_sigalgs(s, ret, salg, salglen);\n\t\ts2n(salglen + 2, etmp);\n\t\ts2n(salglen, etmp);\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\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\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\tif ((limit - ret - 4 - 1) < 0)\n\t\treturn NULL;\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\tif (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len)\n\t\t{\n\t\tif ((size_t)(limit - ret) < 6 + s->alpn_client_proto_list_len)\n\t\t\treturn NULL;\n\t\ts2n(TLSEXT_TYPE_application_layer_protocol_negotiation,ret);\n\t\ts2n(2 + s->alpn_client_proto_list_len,ret);\n\t\ts2n(s->alpn_client_proto_list_len,ret);\n\t\tmemcpy(ret, s->alpn_client_proto_list,\n\t\t       s->alpn_client_proto_list_len);\n\t\tret += s->alpn_client_proto_list_len;\n\t\t}\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 - ret - 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->cert->custom_cli_ext_records_count)\n\t\t{\n\t\tsize_t i;\n\t\tcustom_cli_ext_record* record;\n\t\tfor (i = 0; i < s->cert->custom_cli_ext_records_count; i++)\n\t\t\t{\n\t\t\tconst unsigned char* out = NULL;\n\t\t\tunsigned short outlen = 0;\n\t\t\trecord = &s->cert->custom_cli_ext_records[i];\n\t\t\tif (record->fn1)\n\t\t\t\t{\n\t\t\t\tint cb_retval = 0;\n\t\t\t\tcb_retval = record->fn1(s, record->ext_type,\n\t\t\t\t\t\t\t&out, &outlen, al,\n\t\t\t\t\t\t\trecord->arg);\n\t\t\t\tif (cb_retval == 0)\n\t\t\t\t\treturn NULL;\n\t\t\t\tif (cb_retval == -1)\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tif (limit < ret + 4 + outlen)\n\t\t\t\treturn NULL;\n\t\t\ts2n(record->ext_type, ret);\n\t\t\ts2n(outlen, ret);\n\t\t\tmemcpy(ret, out, outlen);\n\t\t\tret += outlen;\n\t\t\t}\n\t\t}\n#ifdef TLSEXT_TYPE_encrypt_then_mac\n\ts2n(TLSEXT_TYPE_encrypt_then_mac,ret);\n\ts2n(0,ret);\n#endif\n\tif (s->options & SSL_OP_TLSEXT_PADDING)\n\t\t{\n\t\tint hlen = ret - (unsigned char *)s->init_buf->data;\n\t\tif (s->state == SSL23_ST_CW_CLNT_HELLO_A)\n\t\t\thlen -= 5;\n\t\tif (hlen > 0xff && hlen < 0x200)\n\t\t\t{\n\t\t\thlen = 0x200 - hlen;\n\t\t\tif (hlen >= 4)\n\t\t\t\thlen -= 4;\n\t\t\telse\n\t\t\t\thlen = 0;\n\t\t\ts2n(TLSEXT_TYPE_padding, ret);\n\t\t\ts2n(hlen, ret);\n\t\t\tmemset(ret, 0, hlen);\n\t\t\tret += hlen;\n\t\t\t}\n\t\t}\n\tif ((extdatalen = ret-orig-2)== 0)\n\t\treturn orig;\n\ts2n(extdatalen, orig);\n\treturn ret;\n\t}', 'static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)\n\t{\n\tconst tls_curve_info *cinfo;\n\tif (curve[0])\n\t\treturn 1;\n\tif ((curve[1] < 1) || ((size_t)curve[1] >\n\t\t\t\tsizeof(nid_list)/sizeof(nid_list[0])))\n\t\treturn 0;\n\tcinfo = &nid_list[curve[1]-1];\n\treturn ssl_security(s, op, cinfo->secbits, cinfo->nid, (void *)curve);\n\t}']