ssl/t1_lib.c:2331: error: BUFFER_OVERRUN_L2
  Offset: [0, 6] Size: 6.
Showing all 5 steps of the trace


ssl/t1_lib.c:2297:21: <Offset trace>
2295.                   /* Work out which GOST certificate is avaiable */
2296.                   if (ssl_has_cert(s, SSL_PKEY_GOST12_512)) {
2297.                       idx = SSL_PKEY_GOST12_512;
                            ^
2298.                   } else if (ssl_has_cert(s, SSL_PKEY_GOST12_256)) {
2299.                       idx = SSL_PKEY_GOST12_256;

ssl/t1_lib.c:2297:21: Assignment
2295.                   /* Work out which GOST certificate is avaiable */
2296.                   if (ssl_has_cert(s, SSL_PKEY_GOST12_512)) {
2297.                       idx = SSL_PKEY_GOST12_512;
                            ^
2298.                   } else if (ssl_has_cert(s, SSL_PKEY_GOST12_256)) {
2299.                       idx = SSL_PKEY_GOST12_256;

ssl/t1_lib.c:2234:1: <Length trace>
2232.    * to the server. In this case no error is set.
2233.    */
2234. > int tls_choose_sigalg(SSL *s, int *al)
2235.   {
2236.       int idx = -1;

ssl/t1_lib.c:2234:1: Parameter `s->cert->pkeys[*]`
2232.    * to the server. In this case no error is set.
2233.    */
2234. > int tls_choose_sigalg(SSL *s, int *al)
2235.   {
2236.       int idx = -1;

ssl/t1_lib.c:2331:55: Array access: Offset: [0, 6] Size: 6
2329.                   /* For Suite B need to match signature algorithm to curve */
2330.                   if (tls1_suiteb(s)) {
2331.                       EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[idx].privatekey);
                                                              ^
2332.                       curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
2333.                   } else {

int tls_choose_sigalg(SSL *s, int *al)
{
    int idx = -1;
    const SIGALG_LOOKUP *lu = NULL;
    s->s3->tmp.cert = NULL;
    s->s3->tmp.sigalg = NULL;
    if (SSL_IS_TLS13(s)) {
        size_t i;
#ifndef OPENSSL_NO_EC
        int curve = -1, skip_ec = 0;
#endif
        for (i = 0; i < s->cert->shared_sigalgslen; i++) {
            lu = s->cert->shared_sigalgs[i];
            if (lu->hash == NID_sha1 || lu->sig == EVP_PKEY_DSA
                || lu->sig == EVP_PKEY_RSA)
                continue;
            if (ssl_md(lu->hash_idx) == NULL)
                continue;
            idx = lu->sig_idx;
            if (!ssl_has_cert(s, idx))
                    continue;
            if (lu->sig == EVP_PKEY_EC) {
#ifndef OPENSSL_NO_EC
                if (curve == -1) {
                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[idx].privatekey);
                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
                    if (EC_KEY_get_conv_form(ec)
                        != POINT_CONVERSION_UNCOMPRESSED)
                        skip_ec = 1;
                }
                if (skip_ec || (lu->curve != NID_undef && curve != lu->curve))
                    continue;
#else
                continue;
#endif
            }
            break;
        }
        if (i == s->cert->shared_sigalgslen) {
            if (al == NULL)
                return 1;
            *al = SSL_AD_HANDSHAKE_FAILURE;
            SSLerr(SSL_F_TLS_CHOOSE_SIGALG,
                   SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM);
            return 0;
        }
    } else {
        if (s->server) {
            idx = ssl_cipher_get_cert_index(s->s3->tmp.new_cipher);
            if (idx == -1)
                return 1;
            if (idx == SSL_PKEY_GOST_EC) {
                if (ssl_has_cert(s, SSL_PKEY_GOST12_512)) {
                    idx = SSL_PKEY_GOST12_512;
                } else if (ssl_has_cert(s, SSL_PKEY_GOST12_256)) {
                    idx = SSL_PKEY_GOST12_256;
                } else if (ssl_has_cert(s, SSL_PKEY_GOST01)) {
                    idx = SSL_PKEY_GOST01;
                } else {
                    if (al == NULL)
                        return 1;
                    *al = SSL_AD_INTERNAL_ERROR;
                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);
                    return 0;
                }
            } else if (!ssl_has_cert(s, idx)) {
                if (al == NULL)
                    return 1;
                *al = SSL_AD_INTERNAL_ERROR;
                SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);
                return 0;
            }
        } else {
            idx = s->cert->key - s->cert->pkeys;
            if (!ssl_has_cert(s, idx))
                return 1;
        }
        if (SSL_USE_SIGALGS(s)) {
            if (s->s3->tmp.peer_sigalgs != NULL) {
                size_t i;
#ifndef OPENSSL_NO_EC
                int curve;
                if (tls1_suiteb(s)) {
                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[idx].privatekey);
                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
                } else {
                    curve = -1;
                }
#endif
                for (i = 0; i < s->cert->shared_sigalgslen; i++) {
                    lu = s->cert->shared_sigalgs[i];
#ifdef OPENSSL_NO_EC
                    if (lu->sig_idx == idx)
                        break;
#else
                    if (lu->sig_idx == idx
                        && (curve == -1 || lu->curve == curve))
                        break;
#endif
                    if (idx == SSL_PKEY_RSA && lu->sig == EVP_PKEY_RSA_PSS)
                        break;
                }
                if (i == s->cert->shared_sigalgslen) {
                    if (al == NULL)
                        return 1;
                    *al = SSL_AD_INTERNAL_ERROR;
                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);
                    return 0;
                }
            } else {
                const uint16_t *sent_sigs;
                size_t sent_sigslen, i;
                if ((lu = tls1_get_legacy_sigalg(s, idx)) == NULL) {
                    if (al == NULL)
                        return 1;
                    *al = SSL_AD_INTERNAL_ERROR;
                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);
                    return 0;
                }
                sent_sigslen = tls12_get_psigalgs(s, 1, &sent_sigs);
                for (i = 0; i < sent_sigslen; i++, sent_sigs++) {
                    if (lu->sigalg == *sent_sigs)
                        break;
                }
                if (i == sent_sigslen) {
                    if (al == NULL)
                        return 1;
                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, SSL_R_WRONG_SIGNATURE_TYPE);
                    *al = SSL_AD_HANDSHAKE_FAILURE;
                    return 0;
                }
            }
        } else {
            if ((lu = tls1_get_legacy_sigalg(s, idx)) == NULL) {
                if (al == NULL)
                    return 1;
                *al = SSL_AD_INTERNAL_ERROR;
                SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);
                return 0;
            }
        }
    }
    if (idx == -1) {
        if (al != NULL) {
            *al = SSL_AD_INTERNAL_ERROR;
            SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);
        }
        return 0;
    }
    s->s3->tmp.cert = &s->cert->pkeys[idx];
    s->cert->key = s->s3->tmp.cert;
    s->s3->tmp.sigalg = lu;
    return 1;
}
['int tls_choose_sigalg(SSL *s, int *al)\n{\n    int idx = -1;\n    const SIGALG_LOOKUP *lu = NULL;\n    s->s3->tmp.cert = NULL;\n    s->s3->tmp.sigalg = NULL;\n    if (SSL_IS_TLS13(s)) {\n        size_t i;\n#ifndef OPENSSL_NO_EC\n        int curve = -1, skip_ec = 0;\n#endif\n        for (i = 0; i < s->cert->shared_sigalgslen; i++) {\n            lu = s->cert->shared_sigalgs[i];\n            if (lu->hash == NID_sha1 || lu->sig == EVP_PKEY_DSA\n                || lu->sig == EVP_PKEY_RSA)\n                continue;\n            if (ssl_md(lu->hash_idx) == NULL)\n                continue;\n            idx = lu->sig_idx;\n            if (!ssl_has_cert(s, idx))\n                    continue;\n            if (lu->sig == EVP_PKEY_EC) {\n#ifndef OPENSSL_NO_EC\n                if (curve == -1) {\n                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[idx].privatekey);\n                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n                    if (EC_KEY_get_conv_form(ec)\n                        != POINT_CONVERSION_UNCOMPRESSED)\n                        skip_ec = 1;\n                }\n                if (skip_ec || (lu->curve != NID_undef && curve != lu->curve))\n                    continue;\n#else\n                continue;\n#endif\n            }\n            break;\n        }\n        if (i == s->cert->shared_sigalgslen) {\n            if (al == NULL)\n                return 1;\n            *al = SSL_AD_HANDSHAKE_FAILURE;\n            SSLerr(SSL_F_TLS_CHOOSE_SIGALG,\n                   SSL_R_NO_SUITABLE_SIGNATURE_ALGORITHM);\n            return 0;\n        }\n    } else {\n        if (s->server) {\n            idx = ssl_cipher_get_cert_index(s->s3->tmp.new_cipher);\n            if (idx == -1)\n                return 1;\n            if (idx == SSL_PKEY_GOST_EC) {\n                if (ssl_has_cert(s, SSL_PKEY_GOST12_512)) {\n                    idx = SSL_PKEY_GOST12_512;\n                } else if (ssl_has_cert(s, SSL_PKEY_GOST12_256)) {\n                    idx = SSL_PKEY_GOST12_256;\n                } else if (ssl_has_cert(s, SSL_PKEY_GOST01)) {\n                    idx = SSL_PKEY_GOST01;\n                } else {\n                    if (al == NULL)\n                        return 1;\n                    *al = SSL_AD_INTERNAL_ERROR;\n                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n            } else if (!ssl_has_cert(s, idx)) {\n                if (al == NULL)\n                    return 1;\n                *al = SSL_AD_INTERNAL_ERROR;\n                SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n        } else {\n            idx = s->cert->key - s->cert->pkeys;\n            if (!ssl_has_cert(s, idx))\n                return 1;\n        }\n        if (SSL_USE_SIGALGS(s)) {\n            if (s->s3->tmp.peer_sigalgs != NULL) {\n                size_t i;\n#ifndef OPENSSL_NO_EC\n                int curve;\n                if (tls1_suiteb(s)) {\n                    EC_KEY *ec = EVP_PKEY_get0_EC_KEY(s->cert->pkeys[idx].privatekey);\n                    curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));\n                } else {\n                    curve = -1;\n                }\n#endif\n                for (i = 0; i < s->cert->shared_sigalgslen; i++) {\n                    lu = s->cert->shared_sigalgs[i];\n#ifdef OPENSSL_NO_EC\n                    if (lu->sig_idx == idx)\n                        break;\n#else\n                    if (lu->sig_idx == idx\n                        && (curve == -1 || lu->curve == curve))\n                        break;\n#endif\n                    if (idx == SSL_PKEY_RSA && lu->sig == EVP_PKEY_RSA_PSS)\n                        break;\n                }\n                if (i == s->cert->shared_sigalgslen) {\n                    if (al == NULL)\n                        return 1;\n                    *al = SSL_AD_INTERNAL_ERROR;\n                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n            } else {\n                const uint16_t *sent_sigs;\n                size_t sent_sigslen, i;\n                if ((lu = tls1_get_legacy_sigalg(s, idx)) == NULL) {\n                    if (al == NULL)\n                        return 1;\n                    *al = SSL_AD_INTERNAL_ERROR;\n                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);\n                    return 0;\n                }\n                sent_sigslen = tls12_get_psigalgs(s, 1, &sent_sigs);\n                for (i = 0; i < sent_sigslen; i++, sent_sigs++) {\n                    if (lu->sigalg == *sent_sigs)\n                        break;\n                }\n                if (i == sent_sigslen) {\n                    if (al == NULL)\n                        return 1;\n                    SSLerr(SSL_F_TLS_CHOOSE_SIGALG, SSL_R_WRONG_SIGNATURE_TYPE);\n                    *al = SSL_AD_HANDSHAKE_FAILURE;\n                    return 0;\n                }\n            }\n        } else {\n            if ((lu = tls1_get_legacy_sigalg(s, idx)) == NULL) {\n                if (al == NULL)\n                    return 1;\n                *al = SSL_AD_INTERNAL_ERROR;\n                SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);\n                return 0;\n            }\n        }\n    }\n    if (idx == -1) {\n        if (al != NULL) {\n            *al = SSL_AD_INTERNAL_ERROR;\n            SSLerr(SSL_F_TLS_CHOOSE_SIGALG, ERR_R_INTERNAL_ERROR);\n        }\n        return 0;\n    }\n    s->s3->tmp.cert = &s->cert->pkeys[idx];\n    s->cert->key = s->s3->tmp.cert;\n    s->s3->tmp.sigalg = lu;\n    return 1;\n}']