ssl/s3_srvr.c:541: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - [0, 4+max(0, `s->init_num`)]):unsigned64 by call to `ssl3_send_certificate_request`.
Showing all 9 steps of the trace


ssl/s3_srvr.c:211:1: Parameter `s->init_num`
209.   #endif
210.   
211. > int ssl3_accept(SSL *s)
212.   {
213.       BUF_MEM *buf;

ssl/s3_srvr.c:541:23: Call
539.               } else {
540.                   s->s3->tmp.cert_request = 1;
541.                   ret = ssl3_send_certificate_request(s);
                             ^
542.                   if (ret <= 0)
543.                       goto end;

ssl/s3_srvr.c:1986:1: Parameter `s->init_num`
  1984.   }
  1985.   
  1986. > int ssl3_send_certificate_request(SSL *s)
  1987.   {
  1988.       unsigned char *p, *d;

ssl/s3_srvr.c:2050:18: Call
  2048.   #ifdef NETSCAPE_HANG_BUG
  2049.           if (!SSL_IS_DTLS(s)) {
  2050.               if (!BUF_MEM_grow_clean(buf, s->init_num + 4)) {
                           ^
  2051.                   SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST, ERR_R_BUF_LIB);
  2052.                   goto err;

crypto/buffer/buffer.c:133:1: <LHS trace>
131.   }
132.   
133. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
134.   {
135.       char *ret;

crypto/buffer/buffer.c:133:1: Parameter `len`
    131.   }
    132.   
    133. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
    134.   {
    135.       char *ret;

crypto/buffer/buffer.c:133:1: <RHS trace>
131.   }
132.   
133. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
134.   {
135.       char *ret;

crypto/buffer/buffer.c:133:1: Parameter `len`
    131.   }
    132.   
    133. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
    134.   {
    135.       char *ret;

crypto/buffer/buffer.c:139:9: Binary operation: ([0, +oo] - [0, 4+max(0, s->init_num)]):unsigned64 by call to `ssl3_send_certificate_request` 
    137.   
    138.       if (str->length >= len) {
    139.           memset(&str->data[len], 0, str->length - len);
                   ^
    140.           str->length = len;
    141.           return (len);

size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
{
    char *ret;
    size_t n;
    if (str->length >= len) {
        memset(&str->data[len], 0, str->length - len);
        str->length = len;
        return (len);
    }
    if (str->max >= len) {
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
        return (len);
    }
    if (len > LIMIT_BEFORE_EXPANSION) {
        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
        return 0;
    }
    n = (len + 3) / 3 * 4;
    if (str->data == NULL)
        ret = OPENSSL_malloc(n);
    else
        ret = OPENSSL_realloc_clean(str->data, str->max, n);
    if (ret == NULL) {
        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
        len = 0;
    } else {
        str->data = ret;
        str->max = n;
        memset(&str->data[str->length], 0, len - str->length);
        str->length = len;
    }
    return (len);
}
['int ssl3_accept(SSL *s)\n{\n    BUF_MEM *buf;\n    unsigned long alg_k, Time = (unsigned long)time(NULL);\n    void (*cb) (const SSL *ssl, int type, int val) = NULL;\n    int ret = -1;\n    int new_state, state, skip = 0;\n    RAND_add(&Time, sizeof(Time), 0);\n    ERR_clear_error();\n    clear_sys_error();\n    if (s->info_callback != NULL)\n        cb = s->info_callback;\n    else if (s->ctx->info_callback != NULL)\n        cb = s->ctx->info_callback;\n    s->in_handshake++;\n    if (!SSL_in_init(s) || SSL_in_before(s))\n        SSL_clear(s);\n    if (s->cert == NULL) {\n        SSLerr(SSL_F_SSL3_ACCEPT, SSL_R_NO_CERTIFICATE_SET);\n        return (-1);\n    }\n#ifndef OPENSSL_NO_HEARTBEATS\n    if (s->tlsext_hb_pending) {\n        s->tlsext_hb_pending = 0;\n        s->tlsext_hb_seq++;\n    }\n#endif\n    for (;;) {\n        state = s->state;\n        switch (s->state) {\n        case SSL_ST_RENEGOTIATE:\n            s->renegotiate = 1;\n        case SSL_ST_BEFORE:\n        case SSL_ST_ACCEPT:\n        case SSL_ST_BEFORE | SSL_ST_ACCEPT:\n        case SSL_ST_OK | SSL_ST_ACCEPT:\n            s->server = 1;\n            if (cb != NULL)\n                cb(s, SSL_CB_HANDSHAKE_START, 1);\n            if ((s->version >> 8) != 3) {\n                SSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR);\n                return -1;\n            }\n            if (!ssl_security(s, SSL_SECOP_VERSION, 0, s->version, NULL)) {\n                SSLerr(SSL_F_SSL3_ACCEPT, SSL_R_VERSION_TOO_LOW);\n                return -1;\n            }\n            s->type = SSL_ST_ACCEPT;\n            if (s->init_buf == NULL) {\n                if ((buf = BUF_MEM_new()) == NULL) {\n                    ret = -1;\n                    goto end;\n                }\n                if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {\n                    BUF_MEM_free(buf);\n                    ret = -1;\n                    goto end;\n                }\n                s->init_buf = buf;\n            }\n            if (!ssl3_setup_buffers(s)) {\n                ret = -1;\n                goto end;\n            }\n            s->init_num = 0;\n            s->s3->flags &= ~TLS1_FLAGS_SKIP_CERT_VERIFY;\n            s->s3->flags &= ~SSL3_FLAGS_CCS_OK;\n            s->s3->change_cipher_spec = 0;\n            if (s->state != SSL_ST_RENEGOTIATE) {\n                if (!ssl_init_wbio_buffer(s, 1)) {\n                    ret = -1;\n                    goto end;\n                }\n                ssl3_init_finished_mac(s);\n                s->state = SSL3_ST_SR_CLNT_HELLO_A;\n                s->ctx->stats.sess_accept++;\n            } else if (!s->s3->send_connection_binding &&\n                       !(s->options &\n                         SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)) {\n                SSLerr(SSL_F_SSL3_ACCEPT,\n                       SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);\n                ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n                ret = -1;\n                goto end;\n            } else {\n                s->ctx->stats.sess_accept_renegotiate++;\n                s->state = SSL3_ST_SW_HELLO_REQ_A;\n            }\n            break;\n        case SSL3_ST_SW_HELLO_REQ_A:\n        case SSL3_ST_SW_HELLO_REQ_B:\n            s->shutdown = 0;\n            ret = ssl3_send_hello_request(s);\n            if (ret <= 0)\n                goto end;\n            s->s3->tmp.next_state = SSL3_ST_SW_HELLO_REQ_C;\n            s->state = SSL3_ST_SW_FLUSH;\n            s->init_num = 0;\n            ssl3_init_finished_mac(s);\n            break;\n        case SSL3_ST_SW_HELLO_REQ_C:\n            s->state = SSL_ST_OK;\n            break;\n        case SSL3_ST_SR_CLNT_HELLO_A:\n        case SSL3_ST_SR_CLNT_HELLO_B:\n        case SSL3_ST_SR_CLNT_HELLO_C:\n            ret = ssl3_get_client_hello(s);\n            if (ret <= 0)\n                goto end;\n#ifndef OPENSSL_NO_SRP\n            s->state = SSL3_ST_SR_CLNT_HELLO_D;\n        case SSL3_ST_SR_CLNT_HELLO_D:\n            {\n                int al;\n                if ((ret = ssl_check_srp_ext_ClientHello(s, &al)) < 0) {\n                    s->rwstate = SSL_X509_LOOKUP;\n                    goto end;\n                }\n                if (ret != SSL_ERROR_NONE) {\n                    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n                    if (al != TLS1_AD_UNKNOWN_PSK_IDENTITY)\n                        SSLerr(SSL_F_SSL3_ACCEPT, SSL_R_CLIENTHELLO_TLSEXT);\n                    ret = SSL_TLSEXT_ERR_ALERT_FATAL;\n                    ret = -1;\n                    goto end;\n                }\n            }\n#endif\n            s->renegotiate = 2;\n            s->state = SSL3_ST_SW_SRVR_HELLO_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_SRVR_HELLO_A:\n        case SSL3_ST_SW_SRVR_HELLO_B:\n            ret = ssl3_send_server_hello(s);\n            if (ret <= 0)\n                goto end;\n#ifndef OPENSSL_NO_TLSEXT\n            if (s->hit) {\n                if (s->tlsext_ticket_expected)\n                    s->state = SSL3_ST_SW_SESSION_TICKET_A;\n                else\n                    s->state = SSL3_ST_SW_CHANGE_A;\n            }\n#else\n            if (s->hit)\n                s->state = SSL3_ST_SW_CHANGE_A;\n#endif\n            else\n                s->state = SSL3_ST_SW_CERT_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_CERT_A:\n        case SSL3_ST_SW_CERT_B:\n            if (!\n                (s->s3->tmp.\n                 new_cipher->algorithm_auth & (SSL_aNULL | SSL_aKRB5 |\n                                               SSL_aSRP))\n&& !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {\n                ret = ssl3_send_server_certificate(s);\n                if (ret <= 0)\n                    goto end;\n#ifndef OPENSSL_NO_TLSEXT\n                if (s->tlsext_status_expected)\n                    s->state = SSL3_ST_SW_CERT_STATUS_A;\n                else\n                    s->state = SSL3_ST_SW_KEY_EXCH_A;\n            } else {\n                skip = 1;\n                s->state = SSL3_ST_SW_KEY_EXCH_A;\n            }\n#else\n            } else\n                skip = 1;\n            s->state = SSL3_ST_SW_KEY_EXCH_A;\n#endif\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_KEY_EXCH_A:\n        case SSL3_ST_SW_KEY_EXCH_B:\n            alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n            s->s3->tmp.use_rsa_tmp = 0;\n            if (0\n#ifndef OPENSSL_NO_PSK\n                || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)\n#endif\n#ifndef OPENSSL_NO_SRP\n                || (alg_k & SSL_kSRP)\n#endif\n                || (alg_k & SSL_kDHE)\n                || (alg_k & SSL_kECDHE)\n                || ((alg_k & SSL_kRSA)\n                    && (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL\n                        || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)\n                            && EVP_PKEY_size(s->cert->pkeys\n                                             [SSL_PKEY_RSA_ENC].privatekey) *\n                            8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)\n                        )\n                    )\n                )\n                ) {\n                ret = ssl3_send_server_key_exchange(s);\n                if (ret <= 0)\n                    goto end;\n            } else\n                skip = 1;\n            s->state = SSL3_ST_SW_CERT_REQ_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_CERT_REQ_A:\n        case SSL3_ST_SW_CERT_REQ_B:\n            if (\n                   !(s->verify_mode & SSL_VERIFY_PEER) ||\n                   ((s->session->peer != NULL) &&\n                    (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||\n                   ((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&\n                    !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||\n                   (s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5) ||\n                   (s->s3->tmp.new_cipher->algorithm_auth & SSL_aSRP)\n                   || (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {\n                skip = 1;\n                s->s3->tmp.cert_request = 0;\n                s->state = SSL3_ST_SW_SRVR_DONE_A;\n                if (s->s3->handshake_buffer)\n                    if (!ssl3_digest_cached_records(s))\n                        return -1;\n            } else {\n                s->s3->tmp.cert_request = 1;\n                ret = ssl3_send_certificate_request(s);\n                if (ret <= 0)\n                    goto end;\n#ifndef NETSCAPE_HANG_BUG\n                s->state = SSL3_ST_SW_SRVR_DONE_A;\n#else\n                s->state = SSL3_ST_SW_FLUSH;\n                s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;\n#endif\n                s->init_num = 0;\n            }\n            break;\n        case SSL3_ST_SW_SRVR_DONE_A:\n        case SSL3_ST_SW_SRVR_DONE_B:\n            ret = ssl3_send_server_done(s);\n            if (ret <= 0)\n                goto end;\n            s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;\n            s->state = SSL3_ST_SW_FLUSH;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_FLUSH:\n            s->rwstate = SSL_WRITING;\n            if (BIO_flush(s->wbio) <= 0) {\n                ret = -1;\n                goto end;\n            }\n            s->rwstate = SSL_NOTHING;\n            s->state = s->s3->tmp.next_state;\n            break;\n        case SSL3_ST_SR_CERT_A:\n        case SSL3_ST_SR_CERT_B:\n            if (s->s3->tmp.cert_request) {\n                ret = ssl3_get_client_certificate(s);\n                if (ret <= 0)\n                    goto end;\n            }\n            s->init_num = 0;\n            s->state = SSL3_ST_SR_KEY_EXCH_A;\n            break;\n        case SSL3_ST_SR_KEY_EXCH_A:\n        case SSL3_ST_SR_KEY_EXCH_B:\n            ret = ssl3_get_client_key_exchange(s);\n            if (ret <= 0)\n                goto end;\n            if (ret == 2) {\n#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)\n                s->state = SSL3_ST_SR_FINISHED_A;\n#else\n                if (s->s3->next_proto_neg_seen)\n                    s->state = SSL3_ST_SR_NEXT_PROTO_A;\n                else\n                    s->state = SSL3_ST_SR_FINISHED_A;\n#endif\n                s->init_num = 0;\n            } else if (SSL_USE_SIGALGS(s)) {\n                s->state = SSL3_ST_SR_CERT_VRFY_A;\n                s->init_num = 0;\n                if (!s->session->peer)\n                    break;\n                if (!s->s3->handshake_buffer) {\n                    SSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR);\n                    return -1;\n                }\n                if (!(s->s3->flags & SSL_SESS_FLAG_EXTMS)) {\n                    s->s3->flags |= TLS1_FLAGS_KEEP_HANDSHAKE;\n                    if (!ssl3_digest_cached_records(s))\n                        return -1;\n                }\n            } else {\n                int offset = 0;\n                int dgst_num;\n                s->state = SSL3_ST_SR_CERT_VRFY_A;\n                s->init_num = 0;\n                if (s->s3->handshake_buffer)\n                    if (!ssl3_digest_cached_records(s))\n                        return -1;\n                for (dgst_num = 0; dgst_num < SSL_MAX_DIGEST; dgst_num++)\n                    if (s->s3->handshake_dgst[dgst_num]) {\n                        int dgst_size;\n                        s->method->ssl3_enc->cert_verify_mac(s,\n                                                             EVP_MD_CTX_type\n                                                             (s->\n                                                              s3->handshake_dgst\n                                                              [dgst_num]),\n                                                             &(s->s3->\n                                                               tmp.cert_verify_md\n                                                               [offset]));\n                        dgst_size =\n                            EVP_MD_CTX_size(s->s3->handshake_dgst[dgst_num]);\n                        if (dgst_size < 0) {\n                            ret = -1;\n                            goto end;\n                        }\n                        offset += dgst_size;\n                    }\n            }\n            break;\n        case SSL3_ST_SR_CERT_VRFY_A:\n        case SSL3_ST_SR_CERT_VRFY_B:\n            if (!s->s3->change_cipher_spec)\n                s->s3->flags |= SSL3_FLAGS_CCS_OK;\n            ret = ssl3_get_cert_verify(s);\n            if (ret <= 0)\n                goto end;\n#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)\n            s->state = SSL3_ST_SR_FINISHED_A;\n#else\n            if (s->s3->next_proto_neg_seen)\n                s->state = SSL3_ST_SR_NEXT_PROTO_A;\n            else\n                s->state = SSL3_ST_SR_FINISHED_A;\n#endif\n            s->init_num = 0;\n            break;\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n        case SSL3_ST_SR_NEXT_PROTO_A:\n        case SSL3_ST_SR_NEXT_PROTO_B:\n            if (!s->s3->change_cipher_spec)\n                s->s3->flags |= SSL3_FLAGS_CCS_OK;\n            ret = ssl3_get_next_proto(s);\n            if (ret <= 0)\n                goto end;\n            s->init_num = 0;\n            s->state = SSL3_ST_SR_FINISHED_A;\n            break;\n#endif\n        case SSL3_ST_SR_FINISHED_A:\n        case SSL3_ST_SR_FINISHED_B:\n            if (!s->s3->change_cipher_spec)\n                s->s3->flags |= SSL3_FLAGS_CCS_OK;\n            ret = ssl3_get_finished(s, SSL3_ST_SR_FINISHED_A,\n                                    SSL3_ST_SR_FINISHED_B);\n            if (ret <= 0)\n                goto end;\n            if (s->hit)\n                s->state = SSL_ST_OK;\n#ifndef OPENSSL_NO_TLSEXT\n            else if (s->tlsext_ticket_expected)\n                s->state = SSL3_ST_SW_SESSION_TICKET_A;\n#endif\n            else\n                s->state = SSL3_ST_SW_CHANGE_A;\n            s->init_num = 0;\n            break;\n#ifndef OPENSSL_NO_TLSEXT\n        case SSL3_ST_SW_SESSION_TICKET_A:\n        case SSL3_ST_SW_SESSION_TICKET_B:\n            ret = ssl3_send_newsession_ticket(s);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_CHANGE_A;\n            s->init_num = 0;\n            break;\n        case SSL3_ST_SW_CERT_STATUS_A:\n        case SSL3_ST_SW_CERT_STATUS_B:\n            ret = ssl3_send_cert_status(s);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_KEY_EXCH_A;\n            s->init_num = 0;\n            break;\n#endif\n        case SSL3_ST_SW_CHANGE_A:\n        case SSL3_ST_SW_CHANGE_B:\n            s->session->cipher = s->s3->tmp.new_cipher;\n            if (!s->method->ssl3_enc->setup_key_block(s)) {\n                ret = -1;\n                goto end;\n            }\n            ret = ssl3_send_change_cipher_spec(s,\n                                               SSL3_ST_SW_CHANGE_A,\n                                               SSL3_ST_SW_CHANGE_B);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_FINISHED_A;\n            s->init_num = 0;\n            if (!s->method->ssl3_enc->change_cipher_state(s,\n                                                          SSL3_CHANGE_CIPHER_SERVER_WRITE))\n            {\n                ret = -1;\n                goto end;\n            }\n            break;\n        case SSL3_ST_SW_FINISHED_A:\n        case SSL3_ST_SW_FINISHED_B:\n            ret = ssl3_send_finished(s,\n                                     SSL3_ST_SW_FINISHED_A,\n                                     SSL3_ST_SW_FINISHED_B,\n                                     s->method->\n                                     ssl3_enc->server_finished_label,\n                                     s->method->\n                                     ssl3_enc->server_finished_label_len);\n            if (ret <= 0)\n                goto end;\n            s->state = SSL3_ST_SW_FLUSH;\n            if (s->hit) {\n#if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)\n                s->s3->tmp.next_state = SSL3_ST_SR_FINISHED_A;\n#else\n                if (s->s3->next_proto_neg_seen) {\n                    s->s3->tmp.next_state = SSL3_ST_SR_NEXT_PROTO_A;\n                } else\n                    s->s3->tmp.next_state = SSL3_ST_SR_FINISHED_A;\n#endif\n            } else\n                s->s3->tmp.next_state = SSL_ST_OK;\n            s->init_num = 0;\n            break;\n        case SSL_ST_OK:\n            ssl3_cleanup_key_block(s);\n            BUF_MEM_free(s->init_buf);\n            s->init_buf = NULL;\n            ssl_free_wbio_buffer(s);\n            s->init_num = 0;\n            if (s->renegotiate == 2) {\n                s->renegotiate = 0;\n                s->new_session = 0;\n                ssl_update_cache(s, SSL_SESS_CACHE_SERVER);\n                s->ctx->stats.sess_accept_good++;\n                s->handshake_func = ssl3_accept;\n                if (cb != NULL)\n                    cb(s, SSL_CB_HANDSHAKE_DONE, 1);\n            }\n            ret = 1;\n            goto end;\n        default:\n            SSLerr(SSL_F_SSL3_ACCEPT, SSL_R_UNKNOWN_STATE);\n            ret = -1;\n            goto end;\n        }\n        if (!s->s3->tmp.reuse_message && !skip) {\n            if (s->debug) {\n                if ((ret = BIO_flush(s->wbio)) <= 0)\n                    goto end;\n            }\n            if ((cb != NULL) && (s->state != state)) {\n                new_state = s->state;\n                s->state = state;\n                cb(s, SSL_CB_ACCEPT_LOOP, 1);\n                s->state = new_state;\n            }\n        }\n        skip = 0;\n    }\n end:\n    s->in_handshake--;\n    if (cb != NULL)\n        cb(s, SSL_CB_ACCEPT_EXIT, ret);\n    return (ret);\n}', 'int ssl3_send_certificate_request(SSL *s)\n{\n    unsigned char *p, *d;\n    int i, j, nl, off, n;\n    STACK_OF(X509_NAME) *sk = NULL;\n    X509_NAME *name;\n    BUF_MEM *buf;\n    if (s->state == SSL3_ST_SW_CERT_REQ_A) {\n        buf = s->init_buf;\n        d = p = ssl_handshake_start(s);\n        p++;\n        n = ssl3_get_req_cert_type(s, p);\n        d[0] = n;\n        p += n;\n        n++;\n        if (SSL_USE_SIGALGS(s)) {\n            const unsigned char *psigs;\n            unsigned char *etmp = p;\n            nl = tls12_get_psigalgs(s, &psigs);\n            p += 2;\n            nl = tls12_copy_sigalgs(s, p, psigs, nl);\n            s2n(nl, etmp);\n            p += nl;\n            n += nl + 2;\n        }\n        off = n;\n        p += 2;\n        n += 2;\n        sk = SSL_get_client_CA_list(s);\n        nl = 0;\n        if (sk != NULL) {\n            for (i = 0; i < sk_X509_NAME_num(sk); i++) {\n                name = sk_X509_NAME_value(sk, i);\n                j = i2d_X509_NAME(name, NULL);\n                if (!BUF_MEM_grow_clean\n                    (buf, SSL_HM_HEADER_LENGTH(s) + n + j + 2)) {\n                    SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,\n                           ERR_R_BUF_LIB);\n                    goto err;\n                }\n                p = ssl_handshake_start(s) + n;\n                s2n(j, p);\n                i2d_X509_NAME(name, &p);\n                n += 2 + j;\n                nl += 2 + j;\n            }\n        }\n        p = ssl_handshake_start(s) + off;\n        s2n(nl, p);\n        ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE_REQUEST, n);\n#ifdef NETSCAPE_HANG_BUG\n        if (!SSL_IS_DTLS(s)) {\n            if (!BUF_MEM_grow_clean(buf, s->init_num + 4)) {\n                SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST, ERR_R_BUF_LIB);\n                goto err;\n            }\n            p = (unsigned char *)s->init_buf->data + s->init_num;\n            *(p++) = SSL3_MT_SERVER_DONE;\n            *(p++) = 0;\n            *(p++) = 0;\n            *(p++) = 0;\n            s->init_num += 4;\n        }\n#endif\n        s->state = SSL3_ST_SW_CERT_REQ_B;\n    }\n    return ssl_do_write(s);\n err:\n    return (-1);\n}', 'size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n{\n    char *ret;\n    size_t n;\n    if (str->length >= len) {\n        memset(&str->data[len], 0, str->length - len);\n        str->length = len;\n        return (len);\n    }\n    if (str->max >= len) {\n        memset(&str->data[str->length], 0, len - str->length);\n        str->length = len;\n        return (len);\n    }\n    if (len > LIMIT_BEFORE_EXPANSION) {\n        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    n = (len + 3) / 3 * 4;\n    if (str->data == NULL)\n        ret = OPENSSL_malloc(n);\n    else\n        ret = OPENSSL_realloc_clean(str->data, str->max, n);\n    if (ret == NULL) {\n        BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n        len = 0;\n    } else {\n        str->data = ret;\n        str->max = n;\n        memset(&str->data[str->length], 0, len - str->length);\n        str->length = len;\n    }\n    return (len);\n}']