ssl/s3_clnt.c:3116: error: BUFFER_OVERRUN_L3
  Offset: [-2, 7] Size: 8 by call to `tls1_check_chain`.
Showing all 6 steps of the trace


ssl/s3_clnt.c:3116:10: Call
3114.        */
3115.       if (s->cert->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT &&
3116.           !tls1_check_chain(s, NULL, NULL, NULL, -2))
                 ^
3117.           return 0;
3118.       alg_k = s->s3->tmp.new_cipher->algorithm_mkey;

ssl/t1_lib.c:3924:1: <Offset trace>
3922.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
3923.   
3924. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
3925.                        int idx)
3926.   {

ssl/t1_lib.c:3924:1: Parameter `idx`
  3922.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
  3923.   
  3924. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
  3925.                        int idx)
  3926.   {

ssl/t1_lib.c:3924:1: <Length trace>
3922.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
3923.   
3924. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
3925.                        int idx)
3926.   {

ssl/t1_lib.c:3924:1: Parameter `s->s3->tmp.md[*]`
  3922.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
  3923.   
  3924. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
  3925.                        int idx)
  3926.   {

ssl/t1_lib.c:4156:18: Array access: Offset: [-2, 7] Size: 8 by call to `tls1_check_chain` 
  4154.           if (*pvalid & CERT_PKEY_EXPLICIT_SIGN)
  4155.               rv |= CERT_PKEY_EXPLICIT_SIGN | CERT_PKEY_SIGN;
  4156.           else if (s->s3->tmp.md[idx] != NULL)
                           ^
  4157.               rv |= CERT_PKEY_SIGN;
  4158.       } else

int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
                     int idx)
{
    int i;
    int rv = 0;
    int check_flags = 0, strict_mode;
    CERT_PKEY *cpk = NULL;
    CERT *c = s->cert;
    uint32_t *pvalid;
    unsigned int suiteb_flags = tls1_suiteb(s);
    if (idx != -1) {
        if (idx == -2) {
            cpk = c->key;
            idx = cpk - c->pkeys;
        } else
            cpk = c->pkeys + idx;
        pvalid = s->s3->tmp.valid_flags + idx;
        x = cpk->x509;
        pk = cpk->privatekey;
        chain = cpk->chain;
        strict_mode = c->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT;
        if (!x || !pk)
            goto end;
#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL
        if (s->cert->cert_flags & SSL_CERT_FLAG_BROKEN_PROTOCOL) {
            rv = CERT_PKEY_STRICT_FLAGS | CERT_PKEY_EXPLICIT_SIGN |
                CERT_PKEY_VALID | CERT_PKEY_SIGN;
            *pvalid = rv;
            return rv;
        }
#endif
    } else {
        if (!x || !pk)
            return 0;
        idx = ssl_cert_type(x, pk);
        if (idx == -1)
            return 0;
        cpk = c->pkeys + idx;
        pvalid = s->s3->tmp.valid_flags + idx;
        if (c->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT)
            check_flags = CERT_PKEY_STRICT_FLAGS;
        else
            check_flags = CERT_PKEY_VALID_FLAGS;
        strict_mode = 1;
    }
    if (suiteb_flags) {
        int ok;
        if (check_flags)
            check_flags |= CERT_PKEY_SUITEB;
        ok = X509_chain_check_suiteb(NULL, x, chain, suiteb_flags);
        if (ok == X509_V_OK)
            rv |= CERT_PKEY_SUITEB;
        else if (!check_flags)
            goto end;
    }
    if (TLS1_get_version(s) >= TLS1_2_VERSION && strict_mode) {
        int default_nid;
        unsigned char rsign = 0;
        if (s->s3->tmp.peer_sigalgs)
            default_nid = 0;
        else {
            switch (idx) {
            case SSL_PKEY_RSA_ENC:
            case SSL_PKEY_RSA_SIGN:
            case SSL_PKEY_DH_RSA:
                rsign = TLSEXT_signature_rsa;
                default_nid = NID_sha1WithRSAEncryption;
                break;
            case SSL_PKEY_DSA_SIGN:
            case SSL_PKEY_DH_DSA:
                rsign = TLSEXT_signature_dsa;
                default_nid = NID_dsaWithSHA1;
                break;
            case SSL_PKEY_ECC:
                rsign = TLSEXT_signature_ecdsa;
                default_nid = NID_ecdsa_with_SHA1;
                break;
            default:
                default_nid = -1;
                break;
            }
        }
        if (default_nid > 0 && c->conf_sigalgs) {
            size_t j;
            const unsigned char *p = c->conf_sigalgs;
            for (j = 0; j < c->conf_sigalgslen; j += 2, p += 2) {
                if (p[0] == TLSEXT_hash_sha1 && p[1] == rsign)
                    break;
            }
            if (j == c->conf_sigalgslen) {
                if (check_flags)
                    goto skip_sigs;
                else
                    goto end;
            }
        }
        if (!tls1_check_sig_alg(c, x, default_nid)) {
            if (!check_flags)
                goto end;
        } else
            rv |= CERT_PKEY_EE_SIGNATURE;
        rv |= CERT_PKEY_CA_SIGNATURE;
        for (i = 0; i < sk_X509_num(chain); i++) {
            if (!tls1_check_sig_alg(c, sk_X509_value(chain, i), default_nid)) {
                if (check_flags) {
                    rv &= ~CERT_PKEY_CA_SIGNATURE;
                    break;
                } else
                    goto end;
            }
        }
    }
    else if (check_flags)
        rv |= CERT_PKEY_EE_SIGNATURE | CERT_PKEY_CA_SIGNATURE;
 skip_sigs:
    if (tls1_check_cert_param(s, x, check_flags ? 1 : 2))
        rv |= CERT_PKEY_EE_PARAM;
    else if (!check_flags)
        goto end;
    if (!s->server)
        rv |= CERT_PKEY_CA_PARAM;
    else if (strict_mode) {
        rv |= CERT_PKEY_CA_PARAM;
        for (i = 0; i < sk_X509_num(chain); i++) {
            X509 *ca = sk_X509_value(chain, i);
            if (!tls1_check_cert_param(s, ca, 0)) {
                if (check_flags) {
                    rv &= ~CERT_PKEY_CA_PARAM;
                    break;
                } else
                    goto end;
            }
        }
    }
    if (!s->server && strict_mode) {
        STACK_OF(X509_NAME) *ca_dn;
        int check_type = 0;
        switch (pk->type) {
        case EVP_PKEY_RSA:
            check_type = TLS_CT_RSA_SIGN;
            break;
        case EVP_PKEY_DSA:
            check_type = TLS_CT_DSS_SIGN;
            break;
        case EVP_PKEY_EC:
            check_type = TLS_CT_ECDSA_SIGN;
            break;
        case EVP_PKEY_DH:
        case EVP_PKEY_DHX:
            {
                int cert_type = X509_certificate_type(x, pk);
                if (cert_type & EVP_PKS_RSA)
                    check_type = TLS_CT_RSA_FIXED_DH;
                if (cert_type & EVP_PKS_DSA)
                    check_type = TLS_CT_DSS_FIXED_DH;
            }
        }
        if (check_type) {
            const unsigned char *ctypes;
            int ctypelen;
            if (c->ctypes) {
                ctypes = c->ctypes;
                ctypelen = (int)c->ctype_num;
            } else {
                ctypes = (unsigned char *)s->s3->tmp.ctype;
                ctypelen = s->s3->tmp.ctype_num;
            }
            for (i = 0; i < ctypelen; i++) {
                if (ctypes[i] == check_type) {
                    rv |= CERT_PKEY_CERT_TYPE;
                    break;
                }
            }
            if (!(rv & CERT_PKEY_CERT_TYPE) && !check_flags)
                goto end;
        } else
            rv |= CERT_PKEY_CERT_TYPE;
        ca_dn = s->s3->tmp.ca_names;
        if (!sk_X509_NAME_num(ca_dn))
            rv |= CERT_PKEY_ISSUER_NAME;
        if (!(rv & CERT_PKEY_ISSUER_NAME)) {
            if (ssl_check_ca_name(ca_dn, x))
                rv |= CERT_PKEY_ISSUER_NAME;
        }
        if (!(rv & CERT_PKEY_ISSUER_NAME)) {
            for (i = 0; i < sk_X509_num(chain); i++) {
                X509 *xtmp = sk_X509_value(chain, i);
                if (ssl_check_ca_name(ca_dn, xtmp)) {
                    rv |= CERT_PKEY_ISSUER_NAME;
                    break;
                }
            }
        }
        if (!check_flags && !(rv & CERT_PKEY_ISSUER_NAME))
            goto end;
    } else
        rv |= CERT_PKEY_ISSUER_NAME | CERT_PKEY_CERT_TYPE;
    if (!check_flags || (rv & check_flags) == check_flags)
        rv |= CERT_PKEY_VALID;
 end:
    if (TLS1_get_version(s) >= TLS1_2_VERSION) {
        if (*pvalid & CERT_PKEY_EXPLICIT_SIGN)
            rv |= CERT_PKEY_EXPLICIT_SIGN | CERT_PKEY_SIGN;
        else if (s->s3->tmp.md[idx] != NULL)
            rv |= CERT_PKEY_SIGN;
    } else
        rv |= CERT_PKEY_SIGN | CERT_PKEY_EXPLICIT_SIGN;
    if (!check_flags) {
        if (rv & CERT_PKEY_VALID)
            *pvalid = rv;
        else {
            *pvalid &= CERT_PKEY_EXPLICIT_SIGN;
            return 0;
        }
    }
    return rv;
}
['static int ssl3_check_client_certificate(SSL *s)\n{\n    unsigned long alg_k;\n    if (!s->cert || !s->cert->key->x509 || !s->cert->key->privatekey)\n        return 0;\n    if (SSL_USE_SIGALGS(s) && !s->s3->tmp.md[s->cert->key - s->cert->pkeys])\n        return 0;\n    if (s->cert->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT &&\n        !tls1_check_chain(s, NULL, NULL, NULL, -2))\n        return 0;\n    alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n    if (alg_k & (SSL_kDHr | SSL_kDHd)) {\n        int i = s->session->peer_type;\n        EVP_PKEY *clkey = NULL, *spkey = NULL;\n        clkey = s->cert->key->privatekey;\n        if (EVP_PKEY_id(clkey) != EVP_PKEY_DH)\n            return 1;\n        if (i >= 0)\n            spkey = X509_get_pubkey(s->session->peer);\n        if (spkey) {\n            i = EVP_PKEY_cmp_parameters(clkey, spkey);\n            EVP_PKEY_free(spkey);\n            if (i != 1)\n                return 0;\n        }\n        s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY;\n    }\n    return 1;\n}', 'int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,\n                     int idx)\n{\n    int i;\n    int rv = 0;\n    int check_flags = 0, strict_mode;\n    CERT_PKEY *cpk = NULL;\n    CERT *c = s->cert;\n    uint32_t *pvalid;\n    unsigned int suiteb_flags = tls1_suiteb(s);\n    if (idx != -1) {\n        if (idx == -2) {\n            cpk = c->key;\n            idx = cpk - c->pkeys;\n        } else\n            cpk = c->pkeys + idx;\n        pvalid = s->s3->tmp.valid_flags + idx;\n        x = cpk->x509;\n        pk = cpk->privatekey;\n        chain = cpk->chain;\n        strict_mode = c->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT;\n        if (!x || !pk)\n            goto end;\n#ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL\n        if (s->cert->cert_flags & SSL_CERT_FLAG_BROKEN_PROTOCOL) {\n            rv = CERT_PKEY_STRICT_FLAGS | CERT_PKEY_EXPLICIT_SIGN |\n                CERT_PKEY_VALID | CERT_PKEY_SIGN;\n            *pvalid = rv;\n            return rv;\n        }\n#endif\n    } else {\n        if (!x || !pk)\n            return 0;\n        idx = ssl_cert_type(x, pk);\n        if (idx == -1)\n            return 0;\n        cpk = c->pkeys + idx;\n        pvalid = s->s3->tmp.valid_flags + idx;\n        if (c->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT)\n            check_flags = CERT_PKEY_STRICT_FLAGS;\n        else\n            check_flags = CERT_PKEY_VALID_FLAGS;\n        strict_mode = 1;\n    }\n    if (suiteb_flags) {\n        int ok;\n        if (check_flags)\n            check_flags |= CERT_PKEY_SUITEB;\n        ok = X509_chain_check_suiteb(NULL, x, chain, suiteb_flags);\n        if (ok == X509_V_OK)\n            rv |= CERT_PKEY_SUITEB;\n        else if (!check_flags)\n            goto end;\n    }\n    if (TLS1_get_version(s) >= TLS1_2_VERSION && strict_mode) {\n        int default_nid;\n        unsigned char rsign = 0;\n        if (s->s3->tmp.peer_sigalgs)\n            default_nid = 0;\n        else {\n            switch (idx) {\n            case SSL_PKEY_RSA_ENC:\n            case SSL_PKEY_RSA_SIGN:\n            case SSL_PKEY_DH_RSA:\n                rsign = TLSEXT_signature_rsa;\n                default_nid = NID_sha1WithRSAEncryption;\n                break;\n            case SSL_PKEY_DSA_SIGN:\n            case SSL_PKEY_DH_DSA:\n                rsign = TLSEXT_signature_dsa;\n                default_nid = NID_dsaWithSHA1;\n                break;\n            case SSL_PKEY_ECC:\n                rsign = TLSEXT_signature_ecdsa;\n                default_nid = NID_ecdsa_with_SHA1;\n                break;\n            default:\n                default_nid = -1;\n                break;\n            }\n        }\n        if (default_nid > 0 && c->conf_sigalgs) {\n            size_t j;\n            const unsigned char *p = c->conf_sigalgs;\n            for (j = 0; j < c->conf_sigalgslen; j += 2, p += 2) {\n                if (p[0] == TLSEXT_hash_sha1 && p[1] == rsign)\n                    break;\n            }\n            if (j == c->conf_sigalgslen) {\n                if (check_flags)\n                    goto skip_sigs;\n                else\n                    goto end;\n            }\n        }\n        if (!tls1_check_sig_alg(c, x, default_nid)) {\n            if (!check_flags)\n                goto end;\n        } else\n            rv |= CERT_PKEY_EE_SIGNATURE;\n        rv |= CERT_PKEY_CA_SIGNATURE;\n        for (i = 0; i < sk_X509_num(chain); i++) {\n            if (!tls1_check_sig_alg(c, sk_X509_value(chain, i), default_nid)) {\n                if (check_flags) {\n                    rv &= ~CERT_PKEY_CA_SIGNATURE;\n                    break;\n                } else\n                    goto end;\n            }\n        }\n    }\n    else if (check_flags)\n        rv |= CERT_PKEY_EE_SIGNATURE | CERT_PKEY_CA_SIGNATURE;\n skip_sigs:\n    if (tls1_check_cert_param(s, x, check_flags ? 1 : 2))\n        rv |= CERT_PKEY_EE_PARAM;\n    else if (!check_flags)\n        goto end;\n    if (!s->server)\n        rv |= CERT_PKEY_CA_PARAM;\n    else if (strict_mode) {\n        rv |= CERT_PKEY_CA_PARAM;\n        for (i = 0; i < sk_X509_num(chain); i++) {\n            X509 *ca = sk_X509_value(chain, i);\n            if (!tls1_check_cert_param(s, ca, 0)) {\n                if (check_flags) {\n                    rv &= ~CERT_PKEY_CA_PARAM;\n                    break;\n                } else\n                    goto end;\n            }\n        }\n    }\n    if (!s->server && strict_mode) {\n        STACK_OF(X509_NAME) *ca_dn;\n        int check_type = 0;\n        switch (pk->type) {\n        case EVP_PKEY_RSA:\n            check_type = TLS_CT_RSA_SIGN;\n            break;\n        case EVP_PKEY_DSA:\n            check_type = TLS_CT_DSS_SIGN;\n            break;\n        case EVP_PKEY_EC:\n            check_type = TLS_CT_ECDSA_SIGN;\n            break;\n        case EVP_PKEY_DH:\n        case EVP_PKEY_DHX:\n            {\n                int cert_type = X509_certificate_type(x, pk);\n                if (cert_type & EVP_PKS_RSA)\n                    check_type = TLS_CT_RSA_FIXED_DH;\n                if (cert_type & EVP_PKS_DSA)\n                    check_type = TLS_CT_DSS_FIXED_DH;\n            }\n        }\n        if (check_type) {\n            const unsigned char *ctypes;\n            int ctypelen;\n            if (c->ctypes) {\n                ctypes = c->ctypes;\n                ctypelen = (int)c->ctype_num;\n            } else {\n                ctypes = (unsigned char *)s->s3->tmp.ctype;\n                ctypelen = s->s3->tmp.ctype_num;\n            }\n            for (i = 0; i < ctypelen; i++) {\n                if (ctypes[i] == check_type) {\n                    rv |= CERT_PKEY_CERT_TYPE;\n                    break;\n                }\n            }\n            if (!(rv & CERT_PKEY_CERT_TYPE) && !check_flags)\n                goto end;\n        } else\n            rv |= CERT_PKEY_CERT_TYPE;\n        ca_dn = s->s3->tmp.ca_names;\n        if (!sk_X509_NAME_num(ca_dn))\n            rv |= CERT_PKEY_ISSUER_NAME;\n        if (!(rv & CERT_PKEY_ISSUER_NAME)) {\n            if (ssl_check_ca_name(ca_dn, x))\n                rv |= CERT_PKEY_ISSUER_NAME;\n        }\n        if (!(rv & CERT_PKEY_ISSUER_NAME)) {\n            for (i = 0; i < sk_X509_num(chain); i++) {\n                X509 *xtmp = sk_X509_value(chain, i);\n                if (ssl_check_ca_name(ca_dn, xtmp)) {\n                    rv |= CERT_PKEY_ISSUER_NAME;\n                    break;\n                }\n            }\n        }\n        if (!check_flags && !(rv & CERT_PKEY_ISSUER_NAME))\n            goto end;\n    } else\n        rv |= CERT_PKEY_ISSUER_NAME | CERT_PKEY_CERT_TYPE;\n    if (!check_flags || (rv & check_flags) == check_flags)\n        rv |= CERT_PKEY_VALID;\n end:\n    if (TLS1_get_version(s) >= TLS1_2_VERSION) {\n        if (*pvalid & CERT_PKEY_EXPLICIT_SIGN)\n            rv |= CERT_PKEY_EXPLICIT_SIGN | CERT_PKEY_SIGN;\n        else if (s->s3->tmp.md[idx] != NULL)\n            rv |= CERT_PKEY_SIGN;\n    } else\n        rv |= CERT_PKEY_SIGN | CERT_PKEY_EXPLICIT_SIGN;\n    if (!check_flags) {\n        if (rv & CERT_PKEY_VALID)\n            *pvalid = rv;\n        else {\n            *pvalid &= CERT_PKEY_EXPLICIT_SIGN;\n            return 0;\n        }\n    }\n    return rv;\n}']