ssl/statem/statem_clnt.c:786: error: BUFFER_OVERRUN_L3
  Offset added: [32, +oo] (⇐ [0, +oo] + 32) Size: [1, 2147483644] by call to `WPACKET_memcpy`.
Showing all 13 steps of the trace


ssl/statem/statem_clnt.c:702:10: Call
700.       WPACKET pkt;
701.   
702.       if (!WPACKET_init(&pkt, s->init_buf)
                ^
703.               || !WPACKET_set_max_size(&pkt, SSL3_RT_MAX_PLAIN_LENGTH)) {
704.           /* Should not happen */

ssl/packet.c:84:12: Call
  82.   int WPACKET_init(WPACKET *pkt, BUF_MEM *buf)
  83.   {
  84.       return WPACKET_init_len(pkt, buf, 0);
                   ^
  85.   }
  86.   

ssl/packet.c:49:1: Parameter `pkt->curr`
    47.   }
    48.   
    49. > int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)
    50.   {
    51.       unsigned char *lenchars;

ssl/statem/statem_clnt.c:785:10: Call
783.        * the negotiated version.
784.        */
785.       if (!WPACKET_put_bytes(&pkt, s->client_version, 2)
                ^
786.               || !WPACKET_memcpy(&pkt, s->s3->client_random, SSL3_RANDOM_SIZE)) {
787.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);

ssl/packet.c:205:1: Parameter `pkt->curr`
  203.   }
  204.   
  205. > int WPACKET_put_bytes(WPACKET *pkt, unsigned int val, size_t size)
  206.   {
  207.       unsigned char *data;

ssl/statem/statem_clnt.c:786:17: Call
784.        */
785.       if (!WPACKET_put_bytes(&pkt, s->client_version, 2)
786.               || !WPACKET_memcpy(&pkt, s->s3->client_random, SSL3_RANDOM_SIZE)) {
                       ^
787.           SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
788.           goto err;

ssl/packet.c:250:1: <Offset trace>
248.   }
249.   
250. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
251.   {
252.       unsigned char *dest;

ssl/packet.c:250:1: Parameter `len`
  248.   }
  249.   
  250. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
  251.   {
  252.       unsigned char *dest;

ssl/packet.c:250:1: <Length trace>
248.   }
249.   
250. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
251.   {
252.       unsigned char *dest;

ssl/packet.c:250:1: Parameter `*pkt->buf->data`
  248.   }
  249.   
  250. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
  251.   {
  252.       unsigned char *dest;

ssl/packet.c:257:10: Call
  255.           return 1;
  256.   
  257.       if (!WPACKET_allocate_bytes(pkt, len, &dest))
                  ^
  258.           return 0;
  259.   

ssl/packet.c:14:1: Parameter `**allocbytes`
    12.   #define DEFAULT_BUF_SIZE    256
    13.   
    14. > int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
    15.   {
    16.       if (pkt->subs == NULL || len == 0)

ssl/packet.c:260:5: Array access: Offset added: [32, +oo] (⇐ [0, +oo] + 32) Size: [1, 2147483644] by call to `WPACKET_memcpy` 
  258.           return 0;
  259.   
  260.       memcpy(dest, src, len);
             ^
  261.   
  262.       return 1;

int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
{
    unsigned char *dest;
    if (len == 0)
        return 1;
    if (!WPACKET_allocate_bytes(pkt, len, &dest))
        return 0;
    memcpy(dest, src, len);
    return 1;
}
['int tls_construct_client_hello(SSL *s)\n{\n    unsigned char *p;\n    int i;\n    int protverr;\n    int al = SSL_AD_HANDSHAKE_FAILURE;\n#ifndef OPENSSL_NO_COMP\n    SSL_COMP *comp;\n#endif\n    SSL_SESSION *sess = s->session;\n    WPACKET pkt;\n    if (!WPACKET_init(&pkt, s->init_buf)\n            || !WPACKET_set_max_size(&pkt, SSL3_RT_MAX_PLAIN_LENGTH)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    protverr = ssl_set_client_hello_version(s);\n    if (protverr != 0) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, protverr);\n        goto err;\n    }\n    if ((sess == NULL) || !ssl_version_supported(s, sess->ssl_version) ||\n        (!sess->session_id_length && !sess->tlsext_tick) ||\n        (sess->not_resumable)) {\n        if (!ssl_get_new_session(s, 0))\n            goto err;\n    }\n    p = s->s3->client_random;\n    if (SSL_IS_DTLS(s)) {\n        size_t idx;\n        i = 1;\n        for (idx = 0; idx < sizeof(s->s3->client_random); idx++) {\n            if (p[idx]) {\n                i = 0;\n                break;\n            }\n        }\n    } else\n        i = 1;\n    if (i && ssl_fill_hello_random(s, 0, p, sizeof(s->s3->client_random)) <= 0)\n        goto err;\n    if (!ssl_set_handshake_header2(s, &pkt, SSL3_MT_CLIENT_HELLO)) {\n        ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!WPACKET_put_bytes(&pkt, s->client_version, 2)\n            || !WPACKET_memcpy(&pkt, s->s3->client_random, SSL3_RANDOM_SIZE)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (s->new_session)\n        i = 0;\n    else\n        i = s->session->session_id_length;\n    if (i > (int)sizeof(s->session->session_id)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || (i != 0 && !WPACKET_memcpy(&pkt, s->session->session_id, i))\n            || !WPACKET_close(&pkt)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (SSL_IS_DTLS(s)) {\n        if (s->d1->cookie_len > sizeof(s->d1->cookie)\n                || !WPACKET_sub_memcpy(&pkt, s->d1->cookie, s->d1->cookie_len,\n                                       1)) {\n            SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n            goto err;\n        }\n    }\n    if (!WPACKET_start_sub_packet_u16(&pkt)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), &pkt))\n        goto err;\n    if (!WPACKET_close(&pkt)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!WPACKET_start_sub_packet_u8(&pkt)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n#ifndef OPENSSL_NO_COMP\n    if (ssl_allow_compression(s) && s->ctx->comp_methods) {\n        int compnum = sk_SSL_COMP_num(s->ctx->comp_methods);\n        for (i = 0; i < compnum; i++) {\n            comp = sk_SSL_COMP_value(s->ctx->comp_methods, i);\n            if (!WPACKET_put_bytes(&pkt, comp->id, 1)) {\n                SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n        }\n    }\n#endif\n    if (!WPACKET_put_bytes(&pkt, 0, 1) || !WPACKET_close(&pkt)) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (ssl_prepare_clienthello_tlsext(s) <= 0) {\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, SSL_R_CLIENTHELLO_TLSEXT);\n        goto err;\n    }\n    if (!WPACKET_start_sub_packet_u16(&pkt)\n            || !WPACKET_set_flags(&pkt, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH)\n            || !ssl_add_clienthello_tlsext(s, &pkt, &al)\n            || !WPACKET_close(&pkt)) {\n        ssl3_send_alert(s, SSL3_AL_FATAL, al);\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!WPACKET_close(&pkt) || !ssl_close_construct_packet(s, &pkt)) {\n        ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n        SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    return 1;\n err:\n    ossl_statem_set_error(s);\n    WPACKET_cleanup(&pkt);\n    return 0;\n}', 'int WPACKET_init(WPACKET *pkt, BUF_MEM *buf)\n{\n    return WPACKET_init_len(pkt, buf, 0);\n}', 'int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)\n{\n    unsigned char *lenchars;\n    if (buf == NULL)\n        return 0;\n    pkt->buf = buf;\n    pkt->curr = 0;\n    pkt->written = 0;\n    pkt->maxsize = maxmaxsize(lenbytes);\n    pkt->subs = OPENSSL_zalloc(sizeof(*pkt->subs));\n    if (pkt->subs == NULL)\n        return 0;\n    if (lenbytes == 0)\n        return 1;\n    pkt->subs->pwritten = lenbytes;\n    pkt->subs->lenbytes = lenbytes;\n    if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars)) {\n        OPENSSL_free(pkt->subs);\n        pkt->subs = NULL;\n        return 0;\n    }\n    pkt->subs->packet_len = lenchars - (unsigned char *)pkt->buf->data;\n    return 1;\n}', 'int WPACKET_put_bytes(WPACKET *pkt, unsigned int val, size_t size)\n{\n    unsigned char *data;\n    if (size > sizeof(unsigned int)\n            || !WPACKET_allocate_bytes(pkt, size, &data))\n        return 0;\n    for (data += size - 1; size > 0; size--) {\n        *data = (unsigned char)(val & 0xff);\n        data--;\n        val >>= 8;\n    }\n    if (val > 0)\n        return 0;\n    return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n    unsigned char *dest;\n    if (len == 0)\n        return 1;\n    if (!WPACKET_allocate_bytes(pkt, len, &dest))\n        return 0;\n    memcpy(dest, src, len);\n    return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n    if (pkt->subs == NULL || len == 0)\n        return 0;\n    if (pkt->maxsize - pkt->written < len)\n        return 0;\n    if (pkt->buf->length - pkt->written < len) {\n        size_t newlen;\n        if (pkt->buf->length > SIZE_MAX / 2) {\n            newlen = SIZE_MAX;\n        } else {\n            newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE\n                                             : pkt->buf->length * 2;\n        }\n        if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n            return 0;\n    }\n    pkt->written += len;\n    *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n    pkt->curr += len;\n    return 1;\n}']