ssl/d1_lib.c:726: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] (⇐ [0, +oo] + 8) Size: [1, 2147483644] by call to `WPACKET_memcpy`.
Showing all 17 steps of the trace


ssl/d1_lib.c:719:18: Call
717.   
718.               /* Construct the record and message headers */
719.               if (!WPACKET_init(&wpkt, s->init_buf)
                        ^
720.                       || !WPACKET_put_bytes_u8(&wpkt, SSL3_RT_HANDSHAKE)
721.                       || !WPACKET_put_bytes_u16(&wpkt, version)

ssl/packet.c:122:12: Call
  120.   int WPACKET_init(WPACKET *pkt, BUF_MEM *buf)
  121.   {
  122.       return WPACKET_init_len(pkt, buf, 0);
                    ^
  123.   }
  124.   

ssl/packet.c:86:1: Parameter `pkt->curr`
    84.   }
    85.   
    86. > int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)
    87.   {
    88.       unsigned char *lenchars;

ssl/d1_lib.c:720:25: Call
718.               /* Construct the record and message headers */
719.               if (!WPACKET_init(&wpkt, s->init_buf)
720.                       || !WPACKET_put_bytes_u8(&wpkt, SSL3_RT_HANDSHAKE)
                               ^
721.                       || !WPACKET_put_bytes_u16(&wpkt, version)
722.                          /*

ssl/packet.c:261:1: Parameter `pkt->curr`
  259.   }
  260.   
  261. > int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)
  262.   {
  263.       unsigned char *data;

ssl/d1_lib.c:721:25: Call
719.               if (!WPACKET_init(&wpkt, s->init_buf)
720.                       || !WPACKET_put_bytes_u8(&wpkt, SSL3_RT_HANDSHAKE)
721.                       || !WPACKET_put_bytes_u16(&wpkt, version)
                               ^
722.                          /*
723.                           * Record sequence number is always the same as in the

ssl/packet.c:261:1: Parameter `pkt->curr`
  259.   }
  260.   
  261. > int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)
  262.   {
  263.       unsigned char *data;

ssl/d1_lib.c:726:25: Call
724.                           * received ClientHello
725.                           */
726.                       || !WPACKET_memcpy(&wpkt, seq, SEQ_NUM_SIZE)
                               ^
727.                          /* End of record, start sub packet for message */
728.                       || !WPACKET_start_sub_packet_u16(&wpkt)

ssl/packet.c:302:1: <Offset trace>
300.   }
301.   
302. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
303.   {
304.       unsigned char *dest;

ssl/packet.c:302:1: Parameter `len`
  300.   }
  301.   
  302. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
  303.   {
  304.       unsigned char *dest;

ssl/packet.c:302:1: <Length trace>
300.   }
301.   
302. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
303.   {
304.       unsigned char *dest;

ssl/packet.c:302:1: Parameter `*pkt->buf->data`
  300.   }
  301.   
  302. > int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)
  303.   {
  304.       unsigned char *dest;

ssl/packet.c:309:10: Call
  307.           return 1;
  308.   
  309.       if (!WPACKET_allocate_bytes(pkt, len, &dest))
                  ^
  310.           return 0;
  311.   

ssl/packet.c:15:1: Parameter `**allocbytes`
    13.   #define DEFAULT_BUF_SIZE    256
    14.   
    15. > int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
    16.   {
    17.       if (!WPACKET_reserve_bytes(pkt, len, allocbytes))

ssl/packet.c:17:10: Call
    15.   int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
    16.   {
    17.       if (!WPACKET_reserve_bytes(pkt, len, allocbytes))
                   ^
    18.           return 0;
    19.   

ssl/packet.c:36:1: Parameter `**allocbytes`
      34.   }
      35.   
      36. > int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
      37.   {
      38.       /* Internal API, so should not fail */

ssl/packet.c:312:5: Array access: Offset added: [8, +oo] (⇐ [0, +oo] + 8) Size: [1, 2147483644] by call to `WPACKET_memcpy` 
  310.           return 0;
  311.   
  312.       memcpy(dest, src, len);
             ^
  313.   
  314.       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 DTLSv1_listen(SSL *s, BIO_ADDR *client)\n{\n    int next, n, ret = 0, clearpkt = 0;\n    unsigned char cookie[DTLS1_COOKIE_LENGTH];\n    unsigned char seq[SEQ_NUM_SIZE];\n    const unsigned char *data;\n    unsigned char *buf;\n    unsigned long fragoff, fraglen, msglen;\n    unsigned int rectype, versmajor, msgseq, msgtype, clientvers, cookielen;\n    BIO *rbio, *wbio;\n    BUF_MEM *bufm;\n    BIO_ADDR *tmpclient = NULL;\n    PACKET pkt, msgpkt, msgpayload, session, cookiepkt;\n    if (!SSL_clear(s))\n        return -1;\n    ERR_clear_error();\n    rbio = SSL_get_rbio(s);\n    wbio = SSL_get_wbio(s);\n    if (!rbio || !wbio) {\n        SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_BIO_NOT_SET);\n        return -1;\n    }\n    BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n    if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) {\n        SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNSUPPORTED_SSL_VERSION);\n        return -1;\n    }\n    if (s->init_buf == NULL) {\n        if ((bufm = BUF_MEM_new()) == NULL) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n            return -1;\n        }\n        if (!BUF_MEM_grow(bufm, SSL3_RT_MAX_PLAIN_LENGTH)) {\n            BUF_MEM_free(bufm);\n            SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n            return -1;\n        }\n        s->init_buf = bufm;\n    }\n    buf = (unsigned char *)s->init_buf->data;\n    do {\n        clear_sys_error();\n        n = BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n        if (n <= 0) {\n            if (BIO_should_retry(rbio)) {\n                goto end;\n            }\n            return -1;\n        }\n        clearpkt = 1;\n        if (!PACKET_buf_init(&pkt, buf, n)) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_INTERNAL_ERROR);\n            return -1;\n        }\n        if (n < DTLS1_RT_HEADER_LENGTH) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_RECORD_TOO_SMALL);\n            goto end;\n        }\n        if (s->msg_callback)\n            s->msg_callback(0, 0, SSL3_RT_HEADER, buf,\n                            DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n        if (!PACKET_get_1(&pkt, &rectype)\n            || !PACKET_get_1(&pkt, &versmajor)) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (rectype != SSL3_RT_HANDSHAKE) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n            goto end;\n        }\n        if (versmajor != DTLS1_VERSION_MAJOR) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_BAD_PROTOCOL_VERSION_NUMBER);\n            goto end;\n        }\n        if (!PACKET_forward(&pkt, 1)\n            || !PACKET_copy_bytes(&pkt, seq, SEQ_NUM_SIZE)\n            || !PACKET_get_length_prefixed_2(&pkt, &msgpkt)) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (seq[0] != 0 || seq[1] != 0) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n            goto end;\n        }\n        data = PACKET_data(&msgpkt);\n        if (!PACKET_get_1(&msgpkt, &msgtype)\n            || !PACKET_get_net_3(&msgpkt, &msglen)\n            || !PACKET_get_net_2(&msgpkt, &msgseq)\n            || !PACKET_get_net_3(&msgpkt, &fragoff)\n            || !PACKET_get_net_3(&msgpkt, &fraglen)\n            || !PACKET_get_sub_packet(&msgpkt, &msgpayload, fraglen)\n            || PACKET_remaining(&msgpkt) != 0) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (msgtype != SSL3_MT_CLIENT_HELLO) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n            goto end;\n        }\n        if (msgseq > 2) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_INVALID_SEQUENCE_NUMBER);\n            goto end;\n        }\n        if (fragoff != 0 || fraglen > msglen) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_FRAGMENTED_CLIENT_HELLO);\n            goto end;\n        }\n        if (s->msg_callback)\n            s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, data,\n                            fraglen + DTLS1_HM_HEADER_LENGTH, s,\n                            s->msg_callback_arg);\n        if (!PACKET_get_net_2(&msgpayload, &clientvers)) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (DTLS_VERSION_LT(clientvers, (unsigned int)s->method->version) &&\n            s->method->version != DTLS_ANY_VERSION) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_WRONG_VERSION_NUMBER);\n            goto end;\n        }\n        if (!PACKET_forward(&msgpayload, SSL3_RANDOM_SIZE)\n            || !PACKET_get_length_prefixed_1(&msgpayload, &session)\n            || !PACKET_get_length_prefixed_1(&msgpayload, &cookiepkt)) {\n            SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (PACKET_remaining(&cookiepkt) == 0) {\n            next = LISTEN_SEND_VERIFY_REQUEST;\n        } else {\n            if (s->ctx->app_verify_cookie_cb == NULL) {\n                SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_NO_VERIFY_COOKIE_CALLBACK);\n                return -1;\n            }\n            if (s->ctx->app_verify_cookie_cb(s, PACKET_data(&cookiepkt),\n                                             PACKET_remaining(&cookiepkt)) ==\n                0) {\n                next = LISTEN_SEND_VERIFY_REQUEST;\n            } else {\n                next = LISTEN_SUCCESS;\n            }\n        }\n        if (next == LISTEN_SEND_VERIFY_REQUEST) {\n            WPACKET wpkt;\n            unsigned int version;\n            size_t wreclen;\n            BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n            BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n            BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n            if (s->ctx->app_gen_cookie_cb == NULL ||\n                s->ctx->app_gen_cookie_cb(s, cookie, &cookielen) == 0 ||\n                cookielen > 255) {\n                SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_COOKIE_GEN_CALLBACK_FAILURE);\n                return -1;\n            }\n            version = (s->method->version == DTLS_ANY_VERSION) ? DTLS1_VERSION\n                                                               : s->version;\n            if (!WPACKET_init(&wpkt, s->init_buf)\n                    || !WPACKET_put_bytes_u8(&wpkt, SSL3_RT_HANDSHAKE)\n                    || !WPACKET_put_bytes_u16(&wpkt, version)\n                    || !WPACKET_memcpy(&wpkt, seq, SEQ_NUM_SIZE)\n                    || !WPACKET_start_sub_packet_u16(&wpkt)\n                    || !WPACKET_put_bytes_u8(&wpkt,\n                                             DTLS1_MT_HELLO_VERIFY_REQUEST)\n                    || !WPACKET_put_bytes_u24(&wpkt, 0)\n                    || !WPACKET_put_bytes_u16(&wpkt, 0)\n                    || !WPACKET_put_bytes_u24(&wpkt, 0)\n                    || !WPACKET_start_sub_packet_u24(&wpkt)\n                    || !dtls_raw_hello_verify_request(&wpkt, cookie, cookielen)\n                    || !WPACKET_close(&wpkt)\n                    || !WPACKET_close(&wpkt)\n                    || !WPACKET_get_total_written(&wpkt, &wreclen)\n                    || !WPACKET_finish(&wpkt)) {\n                SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_INTERNAL_ERROR);\n                WPACKET_cleanup(&wpkt);\n                return -1;\n            }\n            memcpy(&buf[DTLS1_RT_HEADER_LENGTH + 1],\n                   &buf[DTLS1_RT_HEADER_LENGTH + DTLS1_HM_HEADER_LENGTH - 3],\n                   3);\n            if (s->msg_callback)\n                s->msg_callback(1, 0, SSL3_RT_HEADER, buf,\n                                DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n            if ((tmpclient = BIO_ADDR_new()) == NULL) {\n                SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n                goto end;\n            }\n            if (BIO_dgram_get_peer(rbio, tmpclient) > 0) {\n                (void)BIO_dgram_set_peer(wbio, tmpclient);\n            }\n            BIO_ADDR_free(tmpclient);\n            tmpclient = NULL;\n            if (BIO_write(wbio, buf, wreclen) < (int)wreclen) {\n                if (BIO_should_retry(wbio)) {\n                    goto end;\n                }\n                return -1;\n            }\n            if (BIO_flush(wbio) <= 0) {\n                if (BIO_should_retry(wbio)) {\n                    goto end;\n                }\n                return -1;\n            }\n        }\n    } while (next != LISTEN_SUCCESS);\n    s->d1->handshake_read_seq = 1;\n    s->d1->handshake_write_seq = 1;\n    s->d1->next_handshake_write_seq = 1;\n    DTLS_RECORD_LAYER_set_write_sequence(&s->rlayer, seq);\n    SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);\n    ossl_statem_set_hello_verify_done(s);\n    if (BIO_dgram_get_peer(rbio, client) <= 0)\n        BIO_ADDR_clear(client);\n    ret = 1;\n    clearpkt = 0;\n end:\n    BIO_ADDR_free(tmpclient);\n    BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n    if (clearpkt) {\n        BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n    }\n    return ret;\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    assert(buf != NULL);\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    assert(size <= sizeof(unsigned int));\n    if (size > sizeof(unsigned int)\n            || !WPACKET_allocate_bytes(pkt, size, &data)\n            || !put_value(data, val, size))\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 (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n        return 0;\n    pkt->written += len;\n    pkt->curr += len;\n    return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n    assert(pkt->subs != NULL && len != 0);\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        size_t reflen;\n        reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n        if (reflen > SIZE_MAX / 2) {\n            newlen = SIZE_MAX;\n        } else {\n            newlen = reflen * 2;\n            if (newlen < DEFAULT_BUF_SIZE)\n                newlen = DEFAULT_BUF_SIZE;\n        }\n        if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n            return 0;\n    }\n    *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n    return 1;\n}']