ssl/statem/statem_clnt.c:3026: error: BUFFER_OVERRUN_L3
  Offset: [-2, 5] Size: 6 by call to `tls1_check_chain`.
Showing all 6 steps of the trace


ssl/statem/statem_clnt.c:3026:10: Call
3024.        */
3025.       if (s->cert->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT &&
3026.           !tls1_check_chain(s, NULL, NULL, NULL, -2))
                 ^
3027.           return 0;
3028.       return 1;

ssl/t1_lib.c:1878:1: <Offset trace>
1876.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
1877.   
1878. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
1879.                        int idx)
1880.   {

ssl/t1_lib.c:1878:1: Parameter `idx`
  1876.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
  1877.   
  1878. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
  1879.                        int idx)
  1880.   {

ssl/t1_lib.c:1878:1: <Length trace>
1876.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
1877.   
1878. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
1879.                        int idx)
1880.   {

ssl/t1_lib.c:1878:1: Parameter `s->s3->tmp.md[*]`
  1876.            | CERT_PKEY_ISSUER_NAME|CERT_PKEY_CERT_TYPE)
  1877.   
  1878. > int tls1_check_chain(SSL *s, X509 *x, EVP_PKEY *pk, STACK_OF(X509) *chain,
  1879.                        int idx)
  1880.   {

ssl/t1_lib.c:2105:18: Array access: Offset: [-2, 5] Size: 6 by call to `tls1_check_chain` 
  2103.           if (*pvalid & CERT_PKEY_EXPLICIT_SIGN)
  2104.               rv |= CERT_PKEY_EXPLICIT_SIGN | CERT_PKEY_SIGN;
  2105.           else if (s->s3->tmp.md[idx] != NULL)
                           ^
  2106.               rv |= CERT_PKEY_SIGN;
  2107.       } 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 = (int)(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;
    } else {
        if (!x || !pk)
            return 0;
        idx = ssl_cert_type(x, pk);
        if (idx == -1)
            return 0;
        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;
        int rsign = 0;
        if (s->s3->tmp.peer_sigalgs)
            default_nid = 0;
        else {
            switch (idx) {
            case SSL_PKEY_RSA:
                rsign = EVP_PKEY_RSA;
                default_nid = NID_sha1WithRSAEncryption;
                break;
            case SSL_PKEY_DSA_SIGN:
                rsign = EVP_PKEY_DSA;
                default_nid = NID_dsaWithSHA1;
                break;
            case SSL_PKEY_ECC:
                rsign = EVP_PKEY_EC;
                default_nid = NID_ecdsa_with_SHA1;
                break;
            case SSL_PKEY_GOST01:
                rsign = NID_id_GostR3410_2001;
                default_nid = NID_id_GostR3411_94_with_GostR3410_2001;
                break;
            case SSL_PKEY_GOST12_256:
                rsign = NID_id_GostR3410_2012_256;
                default_nid = NID_id_tc26_signwithdigest_gost3410_2012_256;
                break;
            case SSL_PKEY_GOST12_512:
                rsign = NID_id_GostR3410_2012_512;
                default_nid = NID_id_tc26_signwithdigest_gost3410_2012_512;
                break;
            default:
                default_nid = -1;
                break;
            }
        }
        if (default_nid > 0 && c->conf_sigalgs) {
            size_t j;
            const uint16_t *p = c->conf_sigalgs;
            for (j = 0; j < c->conf_sigalgslen; j++, p++) {
                const SIGALG_LOOKUP *lu = tls1_lookup_sigalg(*p);
                if (lu != NULL && lu->hash == NID_sha1 && lu->sig == 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 (EVP_PKEY_id(pk)) {
        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;
        }
        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    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    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 = (int)(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    } else {\n        if (!x || !pk)\n            return 0;\n        idx = ssl_cert_type(x, pk);\n        if (idx == -1)\n            return 0;\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        int rsign = 0;\n        if (s->s3->tmp.peer_sigalgs)\n            default_nid = 0;\n        else {\n            switch (idx) {\n            case SSL_PKEY_RSA:\n                rsign = EVP_PKEY_RSA;\n                default_nid = NID_sha1WithRSAEncryption;\n                break;\n            case SSL_PKEY_DSA_SIGN:\n                rsign = EVP_PKEY_DSA;\n                default_nid = NID_dsaWithSHA1;\n                break;\n            case SSL_PKEY_ECC:\n                rsign = EVP_PKEY_EC;\n                default_nid = NID_ecdsa_with_SHA1;\n                break;\n            case SSL_PKEY_GOST01:\n                rsign = NID_id_GostR3410_2001;\n                default_nid = NID_id_GostR3411_94_with_GostR3410_2001;\n                break;\n            case SSL_PKEY_GOST12_256:\n                rsign = NID_id_GostR3410_2012_256;\n                default_nid = NID_id_tc26_signwithdigest_gost3410_2012_256;\n                break;\n            case SSL_PKEY_GOST12_512:\n                rsign = NID_id_GostR3410_2012_512;\n                default_nid = NID_id_tc26_signwithdigest_gost3410_2012_512;\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 uint16_t *p = c->conf_sigalgs;\n            for (j = 0; j < c->conf_sigalgslen; j++, p++) {\n                const SIGALG_LOOKUP *lu = tls1_lookup_sigalg(*p);\n                if (lu != NULL && lu->hash == NID_sha1 && lu->sig == 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 (EVP_PKEY_id(pk)) {\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        }\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}']