ssl/d1_lib.c:640: error: INTEGER_OVERFLOW_L2
  ([1, +oo] - 8):unsigned64 by call to `PACKET_copy_bytes`.
Showing all 20 steps of the trace


ssl/d1_lib.c:593:14: Call
591.           clearpkt = 1;
592.   
593.           if (!PACKET_buf_init(&pkt, buf, n)) {
                    ^
594.               SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);
595.               return -1;

ssl/packet_locl.h:109:1: Parameter `pkt->remaining`
  107.    * is being used.
  108.    */
  109. > static inline int PACKET_buf_init(PACKET *pkt, unsigned char *buf, size_t len)
  110.   {
  111.       /* Sanity check for negative values. */

ssl/d1_lib.c:618:14: Call
616.   
617.           /* Get the record header */
618.           if (!PACKET_get_1(&pkt, &rectype)
                    ^
619.               || !PACKET_get_1(&pkt, &versmajor)) {
620.               SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);

ssl/packet_locl.h:248:8: Parameter `pkt->remaining`
  246.   
  247.   /* Get 1 byte from |pkt| and store the value in |*data| */
  248.   __owur static inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
                ^
  249.   {
  250.       if (!PACKET_peek_1(pkt, data))

ssl/packet_locl.h:250:10: Call
  248.   __owur static inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
  249.   {
  250.       if (!PACKET_peek_1(pkt, data))
                  ^
  251.           return 0;
  252.   

ssl/packet_locl.h:237:8: Parameter `pkt->remaining`
    235.   
    236.   /* Peek ahead at 1 byte from |pkt| and store the value in |*data| */
    237.   __owur static inline int PACKET_peek_1(const PACKET *pkt, unsigned int *data)
                  ^
    238.   {
    239.       if (!PACKET_remaining(pkt))

ssl/d1_lib.c:619:17: Call
617.           /* Get the record header */
618.           if (!PACKET_get_1(&pkt, &rectype)
619.               || !PACKET_get_1(&pkt, &versmajor)) {
                       ^
620.               SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);
621.               goto end;

ssl/packet_locl.h:248:8: Parameter `pkt->remaining`
  246.   
  247.   /* Get 1 byte from |pkt| and store the value in |*data| */
  248.   __owur static inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
                ^
  249.   {
  250.       if (!PACKET_peek_1(pkt, data))

ssl/packet_locl.h:250:10: Call
  248.   __owur static inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
  249.   {
  250.       if (!PACKET_peek_1(pkt, data))
                  ^
  251.           return 0;
  252.   

ssl/packet_locl.h:237:8: Parameter `pkt->remaining`
    235.   
    236.   /* Peek ahead at 1 byte from |pkt| and store the value in |*data| */
    237.   __owur static inline int PACKET_peek_1(const PACKET *pkt, unsigned int *data)
                  ^
    238.   {
    239.       if (!PACKET_remaining(pkt))

ssl/d1_lib.c:638:14: Call
636.           }
637.   
638.           if (!PACKET_forward(&pkt, 1)
                    ^
639.               /* Save the sequence number: 64 bits, with top 2 bytes = epoch */
640.               || !PACKET_copy_bytes(&pkt, seq, SEQ_NUM_SIZE)

ssl/packet_locl.h:401:8: Parameter `len`
  399.   
  400.   /* Move the current reading position forward |len| bytes */
  401.   __owur static inline int PACKET_forward(PACKET *pkt, size_t len)
                ^
  402.   {
  403.       if (PACKET_remaining(pkt) < len)

ssl/d1_lib.c:640:17: Call
638.           if (!PACKET_forward(&pkt, 1)
639.               /* Save the sequence number: 64 bits, with top 2 bytes = epoch */
640.               || !PACKET_copy_bytes(&pkt, seq, SEQ_NUM_SIZE)
                       ^
641.               || !PACKET_get_length_prefixed_2(&pkt, &msgpkt)
642.               || PACKET_remaining(&pkt) != 0) {

ssl/packet_locl.h:340:8: Parameter `len`
  338.    * The caller is responsible for ensuring that |data| can hold |len| bytes.
  339.    */
  340.   __owur static inline int PACKET_copy_bytes(PACKET *pkt, unsigned char *data,
                ^
  341.                                              size_t len)
  342.   {

ssl/packet_locl.h:346:5: Call
  344.           return 0;
  345.   
  346.       packet_forward(pkt, len);
             ^
  347.   
  348.       return 1;

ssl/packet_locl.h:79:1: <LHS trace>
77.   
78.   /* Internal unchecked shorthand; don't use outside this file. */
79. > static inline void packet_forward(PACKET *pkt, size_t len)
80.   {
81.       pkt->curr += len;

ssl/packet_locl.h:79:1: Parameter `pkt->remaining`
    77.   
    78.   /* Internal unchecked shorthand; don't use outside this file. */
    79. > static inline void packet_forward(PACKET *pkt, size_t len)
    80.   {
    81.       pkt->curr += len;

ssl/packet_locl.h:79:1: <RHS trace>
77.   
78.   /* Internal unchecked shorthand; don't use outside this file. */
79. > static inline void packet_forward(PACKET *pkt, size_t len)
80.   {
81.       pkt->curr += len;

ssl/packet_locl.h:79:1: Parameter `len`
    77.   
    78.   /* Internal unchecked shorthand; don't use outside this file. */
    79. > static inline void packet_forward(PACKET *pkt, size_t len)
    80.   {
    81.       pkt->curr += len;

ssl/packet_locl.h:82:5: Binary operation: ([1, +oo] - 8):unsigned64 by call to `PACKET_copy_bytes` 
    80.   {
    81.       pkt->curr += len;
    82.       pkt->remaining -= len;
              ^
    83.   }
    84.   

static inline void packet_forward(PACKET *pkt, size_t len)
{
    pkt->curr += len;
    pkt->remaining -= len;
}
['int dtls1_listen(SSL *s, struct sockaddr *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    unsigned char *data, *p, *buf;\n    unsigned long reclen, fragoff, fraglen, msglen;\n    unsigned int rectype, versmajor, msgseq, msgtype, clientvers, cookielen;\n    BIO *rbio, *wbio;\n    BUF_MEM *bufm;\n    struct sockaddr_storage tmpclient;\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_DTLS1_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_DTLS1_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_DTLS1_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_DTLS1_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_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);\n            return -1;\n        }\n        if (n < DTLS1_RT_HEADER_LENGTH) {\n            SSLerr(SSL_F_DTLS1_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_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (rectype != SSL3_RT_HANDSHAKE)  {\n            SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n            goto end;\n        }\n        if (versmajor != DTLS1_VERSION_MAJOR) {\n            SSLerr(SSL_F_DTLS1_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            || PACKET_remaining(&pkt) != 0) {\n            SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (seq[0] != 0 || seq[1] != 0) {\n            SSLerr(SSL_F_DTLS1_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, msglen)\n            || PACKET_remaining(&msgpkt) != 0) {\n            SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if (msgtype != SSL3_MT_CLIENT_HELLO) {\n            SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n            goto end;\n        }\n        if(msgseq > 2) {\n            SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_INVALID_SEQUENCE_NUMBER);\n            goto end;\n        }\n        if (fragoff != 0 || fraglen != msglen) {\n            SSLerr(SSL_F_DTLS1_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                            msglen + DTLS1_HM_HEADER_LENGTH, s,\n                            s->msg_callback_arg);\n        if (!PACKET_get_net_2(&msgpayload, &clientvers)) {\n            SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n            goto end;\n        }\n        if ((clientvers > (unsigned int)s->method->version &&\n                              s->method->version != DTLS_ANY_VERSION)) {\n            SSLerr(SSL_F_DTLS1_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_DTLS1_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_DTLS1_LISTEN, SSL_R_NO_VERIFY_COOKIE_CALLBACK);\n                return -1;\n            }\n            if (PACKET_remaining(&cookiepkt) > sizeof(s->d1->rcvd_cookie)\n                || s->ctx->app_verify_cookie_cb(s, PACKET_data(&cookiepkt),\n                    PACKET_remaining(&cookiepkt)) == 0) {\n                next = LISTEN_SEND_VERIFY_REQUEST;\n            } else {\n                next = LISTEN_SUCCESS;\n            }\n        }\n        if (next == LISTEN_SEND_VERIFY_REQUEST) {\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                SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_COOKIE_GEN_CALLBACK_FAILURE);\n                return -1;\n            }\n            p = &buf[DTLS1_RT_HEADER_LENGTH];\n            msglen = dtls1_raw_hello_verify_request(p + DTLS1_HM_HEADER_LENGTH,\n                                                    cookie, cookielen);\n            *p++ = DTLS1_MT_HELLO_VERIFY_REQUEST;\n            l2n3(msglen, p);\n            s2n(0, p);\n            l2n3(0, p);\n            l2n3(msglen, p);\n            reclen = msglen + DTLS1_HM_HEADER_LENGTH;\n            p = buf;\n            *(p++) = SSL3_RT_HANDSHAKE;\n            if (s->method->version == DTLS_ANY_VERSION) {\n                *(p++) = DTLS1_VERSION >> 8;\n                *(p++) = DTLS1_VERSION & 0xff;\n            } else {\n                *(p++) = s->version >> 8;\n                *(p++) = s->version & 0xff;\n            }\n            memcpy(p, seq, SEQ_NUM_SIZE);\n            p += SEQ_NUM_SIZE;\n            s2n(reclen, p);\n            reclen += DTLS1_RT_HEADER_LENGTH;\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(BIO_dgram_get_peer(rbio, &tmpclient) <= 0\n               || BIO_dgram_set_peer(wbio, &tmpclient) <= 0) {\n                SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);\n                goto end;\n            }\n            if (BIO_write(wbio, buf, reclen) < (int)reclen) {\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    s->state = SSL_ST_ACCEPT;\n    if(BIO_dgram_get_peer(rbio, client) <= 0) {\n        SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);\n        return -1;\n    }\n    ret = 1;\n    clearpkt = 0;\nend:\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}', 'static inline void packet_forward(PACKET *pkt, size_t len)\n{\n    pkt->curr += len;\n    pkt->remaining -= len;\n}']