ssl/statem/statem_dtls.c:722: error: INTEGER_OVERFLOW_L2
  ([2, max(2147483644, `s->init_buf->max`)] - [1, 2147483644]):unsigned64 by call to `dtls1_retrieve_buffered_fragment`.
Showing all 13 steps of the trace


ssl/statem/statem_dtls.c:712:1: Parameter `s->init_buf->max`
710.   }
711.   
712. > static int dtls_get_reassembled_message(SSL *s, long *len)
713.   {
714.       unsigned char wire[DTLS1_HM_HEADER_LENGTH];

ssl/statem/statem_dtls.c:722:21: Call
720.    redo:
721.       /* see if we have the required fragment already */
722.       if ((frag_len = dtls1_retrieve_buffered_fragment(s, &ok)) || ok) {
                           ^
723.           if (ok)
724.               s->init_num = frag_len;

ssl/statem/statem_dtls.c:447:1: Parameter `s->init_buf->max`
  445.   }
  446.   
  447. > static int dtls1_retrieve_buffered_fragment(SSL *s, int *ok)
  448.   {
  449.       /*-

ssl/statem/statem_dtls.c:486:14: Call
  484.           pqueue_pop(s->d1->buffered_messages);
  485.   
  486.           al = dtls1_preprocess_fragment(s, &frag->msg_header);
                      ^
  487.   
  488.           if (al == 0) {          /* no alert */

ssl/statem/statem_dtls.c:405:1: Parameter `s->init_buf->max`
    403.   }
    404.   
    405. > static int dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr)
    406.   {
    407.       size_t frag_off, frag_len, msg_len;

ssl/statem/statem_dtls.c:425:14: Call
    423.            * dtls_max_handshake_message_len(s) above
    424.            */
    425.           if (!BUF_MEM_grow_clean(s->init_buf, msg_len + DTLS1_HM_HEADER_LENGTH)) {
                        ^
    426.               SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, ERR_R_BUF_LIB);
    427.               return SSL_AD_INTERNAL_ERROR;

crypto/buffer/buffer.c:109:1: Parameter `len`
      107.   }
      108.   
      109. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
      110.   {
      111.       char *ret;

crypto/buffer/buffer.c:134:15: Call
      132.           ret = sec_alloc_realloc(str, n);
      133.       else
      134.           ret = OPENSSL_clear_realloc(str->data, str->max, n);
                           ^
      135.       if (ret == NULL) {
      136.           BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);

crypto/mem.c:136:1: <LHS trace>
134.   }
135.   
136. > void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
137.                              const char *file, int line)
138.   {

crypto/mem.c:136:1: Parameter `num`
        134.   }
        135.   
        136. > void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
        137.                              const char *file, int line)
        138.   {

crypto/mem.c:136:1: <RHS trace>
134.   }
135.   
136. > void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
137.                              const char *file, int line)
138.   {

crypto/mem.c:136:1: Parameter `num`
        134.   }
        135.   
        136. > void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
        137.                              const char *file, int line)
        138.   {

crypto/mem.c:151:9: Binary operation: ([2, max(2147483644, s->init_buf->max)] - [1, 2147483644]):unsigned64 by call to `dtls1_retrieve_buffered_fragment` 
        149.       /* Can't shrink the buffer since memcpy below copies |old_len| bytes. */
        150.       if (num < old_len) {
        151.           OPENSSL_cleanse((char*)str + num, old_len - num);
                       ^
        152.           return str;
        153.       }

void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
                           const char *file, int line)
{
    void *ret = NULL;
    if (str == NULL)
        return CRYPTO_malloc(num, file, line);
    if (num == 0) {
        CRYPTO_clear_free(str, old_len, file, line);
        return NULL;
    }
    if (num < old_len) {
        OPENSSL_cleanse((char*)str + num, old_len - num);
        return str;
    }
    ret = CRYPTO_malloc(num, file, line);
    if (ret != NULL) {
        memcpy(ret, str, old_len);
        CRYPTO_clear_free(str, old_len, file, line);
    }
    return ret;
}
['static int dtls_get_reassembled_message(SSL *s, long *len)\n{\n    unsigned char wire[DTLS1_HM_HEADER_LENGTH];\n    unsigned long mlen, frag_off, frag_len;\n    int i, al, recvd_type;\n    struct hm_header_st msg_hdr;\n    int ok;\n redo:\n    if ((frag_len = dtls1_retrieve_buffered_fragment(s, &ok)) || ok) {\n        if (ok)\n            s->init_num = frag_len;\n        *len = frag_len;\n        return ok;\n    }\n    i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, &recvd_type, wire,\n                                  DTLS1_HM_HEADER_LENGTH, 0);\n    if (i <= 0) {\n        s->rwstate = SSL_READING;\n        *len = i;\n        return 0;\n    }\n    if (recvd_type == SSL3_RT_CHANGE_CIPHER_SPEC) {\n        if (wire[0] != SSL3_MT_CCS) {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE,\n                   SSL_R_BAD_CHANGE_CIPHER_SPEC);\n            goto f_err;\n        }\n        memcpy(s->init_buf->data, wire, i);\n        s->init_num = i - 1;\n        s->init_msg = s->init_buf->data + 1;\n        s->s3->tmp.message_type = SSL3_MT_CHANGE_CIPHER_SPEC;\n        s->s3->tmp.message_size = i - 1;\n        *len = i - 1;\n        return 1;\n    }\n    if (i != DTLS1_HM_HEADER_LENGTH) {\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL_R_UNEXPECTED_MESSAGE);\n        goto f_err;\n    }\n    dtls1_get_message_header(wire, &msg_hdr);\n    mlen = msg_hdr.msg_len;\n    frag_off = msg_hdr.frag_off;\n    frag_len = msg_hdr.frag_len;\n    if (frag_len > RECORD_LAYER_get_rrec_length(&s->rlayer)) {\n        al = SSL3_AD_ILLEGAL_PARAMETER;\n        SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL_R_BAD_LENGTH);\n        goto f_err;\n    }\n    if (msg_hdr.seq != s->d1->handshake_read_seq) {\n        *len = dtls1_process_out_of_seq_message(s, &msg_hdr, &ok);\n        return ok;\n    }\n    if (frag_len && frag_len < mlen) {\n        *len = dtls1_reassemble_fragment(s, &msg_hdr, &ok);\n        return ok;\n    }\n    if (!s->server && s->d1->r_msg_hdr.frag_off == 0 &&\n        wire[0] == SSL3_MT_HELLO_REQUEST) {\n        if (wire[1] == 0 && wire[2] == 0 && wire[3] == 0) {\n            if (s->msg_callback)\n                s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n                                wire, DTLS1_HM_HEADER_LENGTH, s,\n                                s->msg_callback_arg);\n            s->init_num = 0;\n            goto redo;\n        } else {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE,\n                   SSL_R_UNEXPECTED_MESSAGE);\n            goto f_err;\n        }\n    }\n    if ((al = dtls1_preprocess_fragment(s, &msg_hdr)))\n        goto f_err;\n    if (frag_len > 0) {\n        unsigned char *p =\n            (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n        i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,\n                                      &p[frag_off], frag_len, 0);\n        if (i <= 0) {\n            s->rwstate = SSL_READING;\n            *len = i;\n            return 0;\n        }\n    } else\n        i = 0;\n    if (i != (int)frag_len) {\n        al = SSL3_AD_ILLEGAL_PARAMETER;\n        SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL3_AD_ILLEGAL_PARAMETER);\n        goto f_err;\n    }\n    *len = s->init_num = frag_len;\n    return 1;\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n    s->init_num = 0;\n    *len = -1;\n    return 0;\n}', 'static int dtls1_retrieve_buffered_fragment(SSL *s, int *ok)\n{\n    pitem *item;\n    hm_fragment *frag;\n    int al;\n    *ok = 0;\n    do {\n        item = pqueue_peek(s->d1->buffered_messages);\n        if (item == NULL)\n            return 0;\n        frag = (hm_fragment *)item->data;\n        if (frag->msg_header.seq < s->d1->handshake_read_seq) {\n            pqueue_pop(s->d1->buffered_messages);\n            dtls1_hm_fragment_free(frag);\n            pitem_free(item);\n            item = NULL;\n            frag = NULL;\n        }\n    } while (item == NULL);\n    if (frag->reassembly != NULL)\n        return 0;\n    if (s->d1->handshake_read_seq == frag->msg_header.seq) {\n        unsigned long frag_len = frag->msg_header.frag_len;\n        pqueue_pop(s->d1->buffered_messages);\n        al = dtls1_preprocess_fragment(s, &frag->msg_header);\n        if (al == 0) {\n            unsigned char *p =\n                (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n            memcpy(&p[frag->msg_header.frag_off], frag->fragment,\n                   frag->msg_header.frag_len);\n        }\n        dtls1_hm_fragment_free(frag);\n        pitem_free(item);\n        if (al == 0) {\n            *ok = 1;\n            return frag_len;\n        }\n        ssl3_send_alert(s, SSL3_AL_FATAL, al);\n        s->init_num = 0;\n        *ok = 0;\n        return -1;\n    } else\n        return 0;\n}', 'static int dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr)\n{\n    size_t frag_off, frag_len, msg_len;\n    msg_len = msg_hdr->msg_len;\n    frag_off = msg_hdr->frag_off;\n    frag_len = msg_hdr->frag_len;\n    if ((frag_off + frag_len) > msg_len\n            || msg_len > dtls1_max_handshake_message_len(s)) {\n        SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n        return SSL_AD_ILLEGAL_PARAMETER;\n    }\n    if (s->d1->r_msg_hdr.frag_off == 0) {\n        if (!BUF_MEM_grow_clean(s->init_buf, msg_len + DTLS1_HM_HEADER_LENGTH)) {\n            SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, ERR_R_BUF_LIB);\n            return SSL_AD_INTERNAL_ERROR;\n        }\n        s->s3->tmp.message_size = msg_len;\n        s->d1->r_msg_hdr.msg_len = msg_len;\n        s->s3->tmp.message_type = msg_hdr->type;\n        s->d1->r_msg_hdr.type = msg_hdr->type;\n        s->d1->r_msg_hdr.seq = msg_hdr->seq;\n    } else if (msg_len != s->d1->r_msg_hdr.msg_len) {\n        SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n        return SSL_AD_ILLEGAL_PARAMETER;\n    }\n    return 0;\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        if (str->data != NULL)\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->flags & BUF_MEM_FLAG_SECURE))\n        ret = sec_alloc_realloc(str, n);\n    else\n        ret = OPENSSL_clear_realloc(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}', 'void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,\n                           const char *file, int line)\n{\n    void *ret = NULL;\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_clear_free(str, old_len, file, line);\n        return NULL;\n    }\n    if (num < old_len) {\n        OPENSSL_cleanse((char*)str + num, old_len - num);\n        return str;\n    }\n    ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL) {\n        memcpy(ret, str, old_len);\n        CRYPTO_clear_free(str, old_len, file, line);\n    }\n    return ret;\n}']