ssl/statem/statem_clnt.c:1815: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: 28 by call to `tls1_check_curve`.
Showing all 9 steps of the trace


ssl/statem/statem_clnt.c:1585:1: Parameter `*pkt->curr`
1583.   }
1584.   
1585. > MSG_PROCESS_RETURN tls_process_key_exchange(SSL *s, PACKET *pkt)
1586.   {
1587.       EVP_MD_CTX md_ctx;

ssl/statem/statem_clnt.c:1815:14: Call
1813.            * invalid curve. ECParameters is 3 bytes.
1814.            */
1815.           if (!tls1_check_curve(s, ecparams, 3)) {
                     ^
1816.               SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_WRONG_CURVE);
1817.               goto f_err;

ssl/t1_lib.c:266:1: Array declaration
  264.   
  265.   /* The client's default curves / the server's 'auto' curves. */
  266. > static const unsigned char eccurves_auto[] = {
  267.       /* Prefer P-256 which has the fastest and most secure implementations. */
  268.       0, 23,                      /* secp256r1 (23) */

ssl/t1_lib.c:507:20: Call
  505.       for (i = 0; i < num_curves; i++, curves += 2) {
  506.           if (p[1] == curves[0] && p[2] == curves[1])
  507.               return tls_curve_allowed(s, p + 1, SSL_SECOP_CURVE_CHECK);
                            ^
  508.       }
  509.       return 0;

ssl/t1_lib.c:466:1: <Offset trace>
464.   
465.   /* See if curve is allowed by security callback */
466. > static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
467.   {
468.       const tls_curve_info *cinfo;

ssl/t1_lib.c:466:1: Parameter `*curve`
    464.   
    465.   /* See if curve is allowed by security callback */
    466. > static int tls_curve_allowed(SSL *s, const unsigned char *curve, int op)
    467.   {
    468.       const tls_curve_info *cinfo;

ssl/t1_lib.c:228:1: <Length trace>
226.   # define TLS_CURVE_PRIME         0x0
227.   
228. > static const tls_curve_info nid_list[] = {
229.       {NID_sect163k1, 80, TLS_CURVE_CHAR2}, /* sect163k1 (1) */
230.       {NID_sect163r1, 80, TLS_CURVE_CHAR2}, /* sect163r1 (2) */

ssl/t1_lib.c:228:1: Array declaration
    226.   # define TLS_CURVE_PRIME         0x0
    227.   
    228. > static const tls_curve_info nid_list[] = {
    229.       {NID_sect163k1, 80, TLS_CURVE_CHAR2}, /* sect163k1 (1) */
    230.       {NID_sect163r1, 80, TLS_CURVE_CHAR2}, /* sect163r1 (2) */

ssl/t1_lib.c:473:5: Array access: Offset: [-1, +oo] Size: 28 by call to `tls1_check_curve` 
    471.       if ((curve[1] < 1) || ((size_t)curve[1] > OSSL_NELEM(nid_list)))
    472.           return 0;
    473.       cinfo = &nid_list[curve[1] - 1];
               ^
    474.   # ifdef OPENSSL_NO_EC2M
    475.       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);
}
['MSG_PROCESS_RETURN tls_process_key_exchange(SSL *s, PACKET *pkt)\n{\n    EVP_MD_CTX md_ctx;\n    int al, j;\n    long alg_k, alg_a;\n    EVP_PKEY *pkey = NULL;\n    const EVP_MD *md = NULL;\n#ifndef OPENSSL_NO_RSA\n    RSA *rsa = NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n    DH *dh = NULL;\n#endif\n#ifndef OPENSSL_NO_EC\n    EC_KEY *ecdh = NULL;\n    BN_CTX *bn_ctx = NULL;\n    EC_POINT *srvr_ecpoint = NULL;\n    int curve_nid = 0;\n#endif\n    PACKET save_param_start, signature;\n    EVP_MD_CTX_init(&md_ctx);\n    alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n    save_param_start = *pkt;\n#ifndef OPENSSL_NO_RSA\n    RSA_free(s->s3->peer_rsa_tmp);\n    s->s3->peer_rsa_tmp = NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n    DH_free(s->s3->peer_dh_tmp);\n    s->s3->peer_dh_tmp = NULL;\n#endif\n#ifndef OPENSSL_NO_EC\n    EC_KEY_free(s->s3->peer_ecdh_tmp);\n    s->s3->peer_ecdh_tmp = NULL;\n#endif\n    alg_a = s->s3->tmp.new_cipher->algorithm_auth;\n    al = SSL_AD_DECODE_ERROR;\n#ifndef OPENSSL_NO_PSK\n    if (alg_k & SSL_PSK) {\n        PACKET psk_identity_hint;\n        if (!PACKET_get_length_prefixed_2(pkt, &psk_identity_hint)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n            goto f_err;\n        }\n        if (PACKET_remaining(&psk_identity_hint) > PSK_MAX_IDENTITY_LEN) {\n            al = SSL_AD_HANDSHAKE_FAILURE;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_DATA_LENGTH_TOO_LONG);\n            goto f_err;\n        }\n        if (PACKET_remaining(&psk_identity_hint) == 0) {\n            OPENSSL_free(s->session->psk_identity_hint);\n            s->session->psk_identity_hint = NULL;\n        } else if (!PACKET_strndup(&psk_identity_hint,\n                            &s->session->psk_identity_hint)) {\n            al = SSL_AD_INTERNAL_ERROR;\n            goto f_err;\n        }\n    }\n    if (alg_k & (SSL_kPSK | SSL_kRSAPSK)) {\n    } else\n#endif\n#ifndef OPENSSL_NO_SRP\n    if (alg_k & SSL_kSRP) {\n        PACKET prime, generator, salt, server_pub;\n        if (!PACKET_get_length_prefixed_2(pkt, &prime)\n            || !PACKET_get_length_prefixed_2(pkt, &generator)\n            || !PACKET_get_length_prefixed_1(pkt, &salt)\n            || !PACKET_get_length_prefixed_2(pkt, &server_pub)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n            goto f_err;\n        }\n        if ((s->srp_ctx.N =\n             BN_bin2bn(PACKET_data(&prime),\n                       PACKET_remaining(&prime), NULL)) == NULL\n            || (s->srp_ctx.g =\n                BN_bin2bn(PACKET_data(&generator),\n                          PACKET_remaining(&generator), NULL)) == NULL\n            || (s->srp_ctx.s =\n                BN_bin2bn(PACKET_data(&salt),\n                          PACKET_remaining(&salt), NULL)) == NULL\n            || (s->srp_ctx.B =\n                BN_bin2bn(PACKET_data(&server_pub),\n                          PACKET_remaining(&server_pub), NULL)) == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_BN_LIB);\n            goto err;\n        }\n        if (!srp_verify_server_param(s, &al)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_BAD_SRP_PARAMETERS);\n            goto f_err;\n        }\n        if (alg_a & (SSL_aRSA|SSL_aDSS))\n            pkey = X509_get_pubkey(s->session->peer);\n    } else\n#endif\n#ifndef OPENSSL_NO_RSA\n    if (alg_k & SSL_kRSA) {\n        PACKET mod, exp;\n        if (!SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)) {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_UNEXPECTED_MESSAGE);\n            goto f_err;\n        }\n        if (!PACKET_get_length_prefixed_2(pkt, &mod)\n            || !PACKET_get_length_prefixed_2(pkt, &exp)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n            goto f_err;\n        }\n        if ((rsa = RSA_new()) == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if ((rsa->n = BN_bin2bn(PACKET_data(&mod), PACKET_remaining(&mod),\n                                rsa->n)) == NULL\n            || (rsa->e = BN_bin2bn(PACKET_data(&exp), PACKET_remaining(&exp),\n                                   rsa->e)) == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_BN_LIB);\n            goto err;\n        }\n        if (alg_a & SSL_aRSA)\n            pkey = X509_get_pubkey(s->session->peer);\n        else {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n            goto err;\n        }\n        s->s3->peer_rsa_tmp = rsa;\n        rsa = NULL;\n    }\n#else\n    if (0) ;\n#endif\n#ifndef OPENSSL_NO_DH\n    else if (alg_k & (SSL_kDHE | SSL_kDHEPSK)) {\n        PACKET prime, generator, pub_key;\n        if (!PACKET_get_length_prefixed_2(pkt, &prime)\n            || !PACKET_get_length_prefixed_2(pkt, &generator)\n            || !PACKET_get_length_prefixed_2(pkt, &pub_key)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n            goto f_err;\n        }\n        if ((dh = DH_new()) == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_DH_LIB);\n            goto err;\n        }\n        if ((dh->p = BN_bin2bn(PACKET_data(&prime),\n                               PACKET_remaining(&prime), NULL)) == NULL\n            || (dh->g = BN_bin2bn(PACKET_data(&generator),\n                                  PACKET_remaining(&generator), NULL)) == NULL\n            || (dh->pub_key =\n                BN_bin2bn(PACKET_data(&pub_key),\n                          PACKET_remaining(&pub_key), NULL)) == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_BN_LIB);\n            goto err;\n        }\n        if (BN_is_zero(dh->p) || BN_is_zero(dh->g) || BN_is_zero(dh->pub_key)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_BAD_DH_VALUE);\n            goto f_err;\n        }\n        if (!ssl_security(s, SSL_SECOP_TMP_DH, DH_security_bits(dh), 0, dh)) {\n            al = SSL_AD_HANDSHAKE_FAILURE;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_DH_KEY_TOO_SMALL);\n            goto f_err;\n        }\n        if (alg_a & (SSL_aRSA|SSL_aDSS))\n            pkey = X509_get_pubkey(s->session->peer);\n        s->s3->peer_dh_tmp = dh;\n        dh = NULL;\n    }\n#endif\n#ifndef OPENSSL_NO_EC\n    else if (alg_k & (SSL_kECDHE | SSL_kECDHEPSK)) {\n        EC_GROUP *ngroup;\n        const EC_GROUP *group;\n        PACKET encoded_pt;\n        unsigned char *ecparams;\n        if ((ecdh = EC_KEY_new()) == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if (!PACKET_get_bytes(pkt, &ecparams, 3)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_TOO_SHORT);\n            goto f_err;\n        }\n        if (!tls1_check_curve(s, ecparams, 3)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_WRONG_CURVE);\n            goto f_err;\n        }\n        if ((curve_nid = tls1_ec_curve_id2nid(*(ecparams + 2))) == 0) {\n            al = SSL_AD_INTERNAL_ERROR;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE,\n                   SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);\n            goto f_err;\n        }\n        ngroup = EC_GROUP_new_by_curve_name(curve_nid);\n        if (ngroup == NULL) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_EC_LIB);\n            goto err;\n        }\n        if (EC_KEY_set_group(ecdh, ngroup) == 0) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_EC_LIB);\n            goto err;\n        }\n        EC_GROUP_free(ngroup);\n        group = EC_KEY_get0_group(ecdh);\n        if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&\n            (EC_GROUP_get_degree(group) > 163)) {\n            al = SSL_AD_EXPORT_RESTRICTION;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE,\n                   SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER);\n            goto f_err;\n        }\n        if (((srvr_ecpoint = EC_POINT_new(group)) == NULL) ||\n            ((bn_ctx = BN_CTX_new()) == NULL)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if (!PACKET_get_length_prefixed_1(pkt, &encoded_pt)) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n            goto f_err;\n        }\n        if (EC_POINT_oct2point(group, srvr_ecpoint, PACKET_data(&encoded_pt),\n                               PACKET_remaining(&encoded_pt), bn_ctx) == 0) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_BAD_ECPOINT);\n            goto f_err;\n        }\n        if (0) ;\n# ifndef OPENSSL_NO_RSA\n        else if (alg_a & SSL_aRSA)\n            pkey = X509_get_pubkey(s->session->peer);\n# endif\n# ifndef OPENSSL_NO_EC\n        else if (alg_a & SSL_aECDSA)\n            pkey = X509_get_pubkey(s->session->peer);\n# endif\n        EC_KEY_set_public_key(ecdh, srvr_ecpoint);\n        s->s3->peer_ecdh_tmp = ecdh;\n        ecdh = NULL;\n        BN_CTX_free(bn_ctx);\n        bn_ctx = NULL;\n        EC_POINT_free(srvr_ecpoint);\n        srvr_ecpoint = NULL;\n    } else if (alg_k) {\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_UNEXPECTED_MESSAGE);\n        goto f_err;\n    }\n#endif\n    if (pkey != NULL) {\n        PACKET params;\n        if (!PACKET_get_sub_packet(&save_param_start, &params,\n                                   PACKET_remaining(&save_param_start) -\n                                   PACKET_remaining(pkt))) {\n            al = SSL_AD_INTERNAL_ERROR;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n            goto f_err;\n        }\n        if (SSL_USE_SIGALGS(s)) {\n            unsigned char *sigalgs;\n            int rv;\n            if (!PACKET_get_bytes(pkt, &sigalgs, 2)) {\n                SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_TOO_SHORT);\n                goto f_err;\n            }\n            rv = tls12_check_peer_sigalg(&md, s, sigalgs, pkey);\n            if (rv == -1)\n                goto err;\n            else if (rv == 0) {\n                goto f_err;\n            }\n#ifdef SSL_DEBUG\n            fprintf(stderr, "USING TLSv1.2 HASH %s\\n", EVP_MD_name(md));\n#endif\n        } else if (pkey->type == EVP_PKEY_RSA) {\n            md = EVP_md5_sha1();\n        } else {\n            md = EVP_sha1();\n        }\n        if (!PACKET_get_length_prefixed_2(pkt, &signature)\n            || PACKET_remaining(pkt) != 0) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_LENGTH_MISMATCH);\n            goto f_err;\n        }\n        j = EVP_PKEY_size(pkey);\n        if (j < 0) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n            goto f_err;\n        }\n        if (PACKET_remaining(&signature) > (size_t)j) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_WRONG_SIGNATURE_LENGTH);\n            goto f_err;\n        }\n        if (EVP_VerifyInit_ex(&md_ctx, md, NULL) <= 0\n                || EVP_VerifyUpdate(&md_ctx, &(s->s3->client_random[0]),\n                                    SSL3_RANDOM_SIZE) <= 0\n                || EVP_VerifyUpdate(&md_ctx, &(s->s3->server_random[0]),\n                                    SSL3_RANDOM_SIZE) <= 0\n                || EVP_VerifyUpdate(&md_ctx, PACKET_data(&params),\n                                    PACKET_remaining(&params)) <= 0) {\n            al = SSL_AD_INTERNAL_ERROR;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_EVP_LIB);\n            goto f_err;\n        }\n        if (EVP_VerifyFinal(&md_ctx, PACKET_data(&signature),\n                            PACKET_remaining(&signature), pkey) <= 0) {\n            al = SSL_AD_DECRYPT_ERROR;\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_BAD_SIGNATURE);\n            goto f_err;\n        }\n    } else {\n        if (!(alg_a & (SSL_aNULL | SSL_aSRP)) && !(alg_k & SSL_PSK)) {\n            if (ssl3_check_cert_and_algorithm(s))\n                SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n            goto err;\n        }\n        if (PACKET_remaining(pkt) != 0) {\n            SSLerr(SSL_F_TLS_PROCESS_KEY_EXCHANGE, SSL_R_EXTRA_DATA_IN_MESSAGE);\n            goto f_err;\n        }\n    }\n    EVP_PKEY_free(pkey);\n    EVP_MD_CTX_cleanup(&md_ctx);\n    return MSG_PROCESS_CONTINUE_READING;\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n    EVP_PKEY_free(pkey);\n#ifndef OPENSSL_NO_RSA\n    RSA_free(rsa);\n#endif\n#ifndef OPENSSL_NO_DH\n    DH_free(dh);\n#endif\n#ifndef OPENSSL_NO_EC\n    BN_CTX_free(bn_ctx);\n    EC_POINT_free(srvr_ecpoint);\n    EC_KEY_free(ecdh);\n#endif\n    EVP_MD_CTX_cleanup(&md_ctx);\n    ossl_statem_set_error(s);\n    return MSG_PROCESS_ERROR;\n}', 'int tls1_check_curve(SSL *s, const unsigned char *p, size_t len)\n{\n    const unsigned char *curves;\n    size_t num_curves, i;\n    unsigned int suiteb_flags = tls1_suiteb(s);\n    if (len != 3 || p[0] != NAMED_CURVE_TYPE)\n        return 0;\n    if (suiteb_flags) {\n        unsigned long cid = s->s3->tmp.new_cipher->id;\n        if (p[1])\n            return 0;\n        if (cid == TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256) {\n            if (p[2] != TLSEXT_curve_P_256)\n                return 0;\n        } else if (cid == TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384) {\n            if (p[2] != TLSEXT_curve_P_384)\n                return 0;\n        } else\n            return 0;\n    }\n    if (!tls1_get_curvelist(s, 0, &curves, &num_curves))\n        return 0;\n    for (i = 0; i < num_curves; i++, curves += 2) {\n        if (p[1] == curves[0] && p[2] == curves[1])\n            return tls_curve_allowed(s, p + 1, SSL_SECOP_CURVE_CHECK);\n    }\n    return 0;\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}']