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


ssl/t1_lib.c:1026:1: Parameter `*s->session->tlsext_supportedgroupslist`
1024.   }
1025.   
1026. > int ssl_add_clienthello_tlsext(SSL *s, WPACKET *pkt, int *al)
1027.   {
1028.   #ifndef OPENSSL_NO_EC

ssl/t1_lib.c:1156:17: Call
1154.           /* Copy curve ID if supported */
1155.           for (i = 0; i < num_curves; i++, pcurvestmp += 2) {
1156.               if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {
                        ^
1157.                   if (!WPACKET_put_bytes_u8(pkt, pcurvestmp[0])
1158.                       || !WPACKET_put_bytes_u8(pkt, pcurvestmp[1])) {

ssl/t1_lib.c:312:1: <Offset trace>
310.   
311.   /* See if curve is allowed by security callback */
312. > static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
313.   {
314.       const tls_curve_info *cinfo;

ssl/t1_lib.c:312:1: Parameter `*curve`
  310.   
  311.   /* See if curve is allowed by security callback */
  312. > static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
  313.   {
  314.       const tls_curve_info *cinfo;

ssl/t1_lib.c:144:1: <Length trace>
142.    * table: the index of each entry is one less than the TLS curve id.
143.    */
144. > static const tls_curve_info nid_list[] = {
145.       {NID_sect163k1, 80, TLS_CURVE_CHAR2}, /* sect163k1 (1) */
146.       {NID_sect163r1, 80, TLS_CURVE_CHAR2}, /* sect163r1 (2) */

ssl/t1_lib.c:144:1: Array declaration
  142.    * table: the index of each entry is one less than the TLS curve id.
  143.    */
  144. > static const tls_curve_info nid_list[] = {
  145.       {NID_sect163k1, 80, TLS_CURVE_CHAR2}, /* sect163k1 (1) */
  146.       {NID_sect163r1, 80, TLS_CURVE_CHAR2}, /* sect163r1 (2) */

ssl/t1_lib.c:319:5: Array access: Offset: [-1, +oo] Size: 29 by call to `tls_curve_allowed` 
  317.       if ((curve[1] < 1) || ((size_t)curve[1] > OSSL_NELEM(nid_list)))
  318.           return 0;
  319.       cinfo = &nid_list[curve[1] - 1];
             ^
  320.   # ifdef OPENSSL_NO_EC2M
  321.       if (cinfo->flags & TLS_CURVE_CHAR2)

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] > OSSL_NELEM(nid_list)))
        return 0;
    cinfo = &nid_list[curve[1] - 1];
# ifdef OPENSSL_NO_EC2M
    if (cinfo->flags & TLS_CURVE_CHAR2)
        return 0;
# endif
    return ssl_security(s, op, cinfo->secbits, cinfo->nid, (void *)curve);
}
['int ssl_add_clienthello_tlsext(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_EC\n    const unsigned char *pcurves = NULL;\n    size_t num_curves = 0;\n    int using_ecc = 0;\n    if ((s->version >= TLS1_VERSION && s->version <= TLS1_2_VERSION)\n            || SSL_IS_DTLS(s)) {\n        int i;\n        unsigned long alg_k, alg_a;\n        STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n        for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {\n            const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n            alg_k = c->algorithm_mkey;\n            alg_a = c->algorithm_auth;\n            if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK))\n                || (alg_a & SSL_aECDSA)) {\n                using_ecc = 1;\n                break;\n            }\n        }\n    } else if (s->version >= TLS1_3_VERSION) {\n        using_ecc = 1;\n    }\n#else\n    if (s->version >= TLS1_3_VERSION) {\n        SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n#endif\n    if (s->renegotiate) {\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_sub_memcpy_u8(pkt, s->s3->previous_client_finished,\n                                   s->s3->previous_client_finished_len)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n    if (s->client_version == SSL3_VERSION)\n        goto done;\n    if (s->tlsext_hostname != NULL) {\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_put_bytes_u8(pkt, TLSEXT_NAMETYPE_host_name)\n                || !WPACKET_sub_memcpy_u16(pkt, s->tlsext_hostname,\n                                           strlen(s->tlsext_hostname))\n                || !WPACKET_close(pkt)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#ifndef OPENSSL_NO_SRP\n    if (s->srp_ctx.login != NULL) {\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u8(pkt)\n                || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)\n                || !WPACKET_memcpy(pkt, s->srp_ctx.login,\n                                   strlen(s->srp_ctx.login))\n                || !WPACKET_close(pkt)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#endif\n#ifndef OPENSSL_NO_EC\n    if (using_ecc) {\n        const unsigned char *pformats, *pcurvestmp;\n        size_t num_formats;\n        size_t i;\n        tls1_get_formatlist(s, &pformats, &num_formats);\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_sub_memcpy_u8(pkt, pformats, num_formats)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        pcurves = s->tlsext_supportedgroupslist;\n        if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        pcurvestmp = pcurves;\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_groups)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u16(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        for (i = 0; i < num_curves; i++, pcurvestmp += 2) {\n            if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n                if (!WPACKET_put_bytes_u8(pkt, pcurvestmp[0])\n                    || !WPACKET_put_bytes_u8(pkt, pcurvestmp[1])) {\n                        SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n                               ERR_R_INTERNAL_ERROR);\n                        return 0;\n                    }\n            }\n        }\n        if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#endif\n    if (tls_use_ticket(s)) {\n        size_t ticklen;\n        if (!s->new_session && s->session && s->session->tlsext_tick)\n            ticklen = s->session->tlsext_ticklen;\n        else if (s->session && s->tlsext_session_ticket &&\n                 s->tlsext_session_ticket->data) {\n            ticklen = s->tlsext_session_ticket->length;\n            s->session->tlsext_tick = OPENSSL_malloc(ticklen);\n            if (s->session->tlsext_tick == NULL) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n            memcpy(s->session->tlsext_tick,\n                   s->tlsext_session_ticket->data, ticklen);\n            s->session->tlsext_ticklen = ticklen;\n        } else\n            ticklen = 0;\n        if (ticklen == 0 && s->tlsext_session_ticket &&\n            s->tlsext_session_ticket->data == NULL)\n            goto skip_ext;\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)\n                || !WPACKET_sub_memcpy_u16(pkt, s->session->tlsext_tick,\n                                           ticklen)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n skip_ext:\n    if (SSL_CLIENT_USE_SIGALGS(s)) {\n        size_t salglen;\n        const unsigned char *salg;\n        salglen = tls12_get_psigalgs(s, &salg);\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !tls12_copy_sigalgs(s, pkt, salg, salglen)\n                || !WPACKET_close(pkt)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#ifndef OPENSSL_NO_OCSP\n    if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) {\n        int i;\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_put_bytes_u8(pkt, TLSEXT_STATUSTYPE_ocsp)\n                || !WPACKET_start_sub_packet_u16(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n            unsigned char *idbytes;\n            int idlen;\n            OCSP_RESPID *id;\n            id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n            idlen = i2d_OCSP_RESPID(id, NULL);\n            if (idlen <= 0\n                    || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)\n                    || i2d_OCSP_RESPID(id, &idbytes) != idlen) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n        }\n        if (!WPACKET_close(pkt)\n                || !WPACKET_start_sub_packet_u16(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        if (s->tlsext_ocsp_exts) {\n            unsigned char *extbytes;\n            int extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n            if (extlen < 0) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n            if (!WPACKET_allocate_bytes(pkt, extlen, &extbytes)\n                    || i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &extbytes)\n                       != extlen) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n           }\n        }\n        if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) {\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)\n                || !WPACKET_put_bytes_u16(pkt, 0)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#endif\n    if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) {\n        if (!WPACKET_put_bytes_u16(pkt,\n                    TLSEXT_TYPE_application_layer_protocol_negotiation)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_sub_memcpy_u16(pkt, s->alpn_client_proto_list,\n                                           s->alpn_client_proto_list_len)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        s->s3->alpn_sent = 1;\n    }\n#ifndef OPENSSL_NO_SRTP\n    if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) {\n        STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = SSL_get_srtp_profiles(s);\n        SRTP_PROTECTION_PROFILE *prof;\n        int i, ct;\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u16(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        ct = sk_SRTP_PROTECTION_PROFILE_num(clnt);\n        for (i = 0; i < ct; i++) {\n            prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);\n            if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n        }\n        if (!WPACKET_close(pkt)\n                || !WPACKET_put_bytes_u8(pkt, 0)\n                || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#endif\n    custom_ext_init(&s->cert->cli_ext);\n    if (!custom_ext_add(s, 0, pkt, al)) {\n        SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    if (!(s->options & SSL_OP_NO_ENCRYPT_THEN_MAC)) {\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)\n            || !WPACKET_put_bytes_u16(pkt, 0)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#ifndef OPENSSL_NO_CT\n    if (s->ct_validation_callback != NULL) {\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signed_certificate_timestamp)\n                || !WPACKET_put_bytes_u16(pkt, 0)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n#endif\n    if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)\n            || !WPACKET_put_bytes_u16(pkt, 0)) {\n        SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    if (SSL_IS_TLS13(s)) {\n        int min_version, max_version, reason, currv;\n        size_t i, sharessent = 0;\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_supported_versions)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u8(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        reason = ssl_get_client_min_max_version(s, &min_version, &max_version);\n        if (reason != 0) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, reason);\n            return 0;\n        }\n        for (currv = max_version; currv >= min_version; currv--) {\n            if (currv == TLS1_3_VERSION) {\n                if (!WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION_DRAFT)) {\n                    SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n                           ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n            } else if (!WPACKET_put_bytes_u16(pkt, currv)) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n        }\n        if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_key_share)\n                || !WPACKET_start_sub_packet_u16(pkt)\n                || !WPACKET_start_sub_packet_u16(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        for (i = 0; i < num_curves && sharessent < 1; i++, pcurves += 2) {\n            if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n                unsigned char *encodedPoint = NULL;\n                unsigned int curve_id = 0;\n                EVP_PKEY *key_share_key = NULL;\n                size_t encodedlen;\n                if (s->s3->tmp.pkey != NULL) {\n                    SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n                           ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n                curve_id = (pcurves[0] << 8) | pcurves[1];\n                key_share_key = ssl_generate_pkey_curve(curve_id);\n                if (key_share_key == NULL) {\n                    SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_EVP_LIB);\n                    return 0;\n                }\n                encodedlen = EVP_PKEY_get1_tls_encodedpoint(key_share_key,\n                                                            &encodedPoint);\n                if (encodedlen == 0) {\n                    SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_EC_LIB);\n                    EVP_PKEY_free(key_share_key);\n                    return 0;\n                }\n                if (!WPACKET_put_bytes_u16(pkt, curve_id)\n                        || !WPACKET_sub_memcpy_u16(pkt, encodedPoint,\n                                                   encodedlen)) {\n                    SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n                           ERR_R_INTERNAL_ERROR);\n                    EVP_PKEY_free(key_share_key);\n                    OPENSSL_free(encodedPoint);\n                    return 0;\n                }\n                s->s3->group_id = curve_id;\n                s->s3->tmp.pkey = key_share_key;\n                sharessent++;\n                OPENSSL_free(encodedPoint);\n            }\n        }\n        if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n    }\n    if (s->options & SSL_OP_TLSEXT_PADDING) {\n        unsigned char *padbytes;\n        size_t hlen;\n        if (!WPACKET_get_total_written(pkt, &hlen)) {\n            SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        if (hlen > 0xff && hlen < 0x200) {\n            hlen = 0x200 - hlen;\n            if (hlen >= 4)\n                hlen -= 4;\n            else\n                hlen = 0;\n            if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_padding)\n                    || !WPACKET_sub_allocate_bytes_u16(pkt, hlen, &padbytes)) {\n                SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n            memset(padbytes, 0, hlen);\n        }\n    }\n done:\n    return 1;\n}', 'static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)\n{\n    const tls_curve_info *cinfo;\n    if (curve[0])\n        return 1;\n    if ((curve[1] < 1) || ((size_t)curve[1] > OSSL_NELEM(nid_list)))\n        return 0;\n    cinfo = &nid_list[curve[1] - 1];\n# ifdef OPENSSL_NO_EC2M\n    if (cinfo->flags & TLS_CURVE_CHAR2)\n        return 0;\n# endif\n    return ssl_security(s, op, cinfo->secbits, cinfo->nid, (void *)curve);\n}']