ssl/statem/statem.c:540: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - [`s->rlayer.rrec.length` + 4, `s->rlayer.rrec.length` + 4]):unsigned64 by call to `tls_get_message_header`.
Showing all 9 steps of the trace


ssl/statem/statem.c:496:1: Parameter `s->init_buf->length`
494.    * will resume in the same state where we left off.
495.    */
496. > static enum SUB_STATE_RETURN read_state_machine(SSL *s) {
497.       STATEM *st = &s->statem;
498.       int ret, mt;

ssl/statem/statem.c:540:23: Call
538.                   ret = dtls_get_message(s, &mt, &len);
539.               } else {
540.                   ret = tls_get_message_header(s, &mt);
                             ^
541.               }
542.   

ssl/statem/statem_lib.c:443:1: Parameter `s->init_buf->length`
  441.   }
  442.   
  443. > int tls_get_message_header(SSL *s, int *mt)
  444.   {
  445.       /* s->init_num < SSL3_HM_HEADER_LENGTH */

ssl/statem/statem_lib.c:508:19: Call
  506.           l = RECORD_LAYER_get_rrec_length(&s->rlayer)
  507.               + SSL3_HM_HEADER_LENGTH;
  508.           if (l && !BUF_MEM_grow_clean(s->init_buf, (int)l)) {
                           ^
  509.               SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB);
  510.               goto err;

crypto/buffer/buffer.c:158:1: <LHS trace>
156.   }
157.   
158. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
159.   {
160.       char *ret;

crypto/buffer/buffer.c:158:1: Parameter `len`
    156.   }
    157.   
    158. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
    159.   {
    160.       char *ret;

crypto/buffer/buffer.c:158:1: <RHS trace>
156.   }
157.   
158. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
159.   {
160.       char *ret;

crypto/buffer/buffer.c:158:1: Parameter `len`
    156.   }
    157.   
    158. > size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
    159.   {
    160.       char *ret;

crypto/buffer/buffer.c:164:9: Binary operation: ([0, +oo] - [s->rlayer.rrec.length + 4, s->rlayer.rrec.length + 4]):unsigned64 by call to `tls_get_message_header` 
    162.   
    163.       if (str->length >= len) {
    164.           memset(&str->data[len], 0, str->length - len);
                   ^
    165.           str->length = len;
    166.           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->flags & BUF_MEM_FLAG_SECURE))
        ret = sec_alloc_realloc(str, 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);
}
['static enum SUB_STATE_RETURN read_state_machine(SSL *s) {\n    STATEM *st = &s->statem;\n    int ret, mt;\n    unsigned long len;\n    int (*transition)(SSL *s, int mt);\n    PACKET pkt;\n    enum MSG_PROCESS_RETURN (*process_message)(SSL *s, PACKET *pkt);\n    enum WORK_STATE (*post_process_message)(SSL *s, enum WORK_STATE wst);\n    unsigned long (*max_message_size)(SSL *s);\n    void (*cb) (const SSL *ssl, int type, int val) = NULL;\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    if(s->server) {\n        transition = server_read_transition;\n        process_message = server_process_message;\n        max_message_size = server_max_message_size;\n        post_process_message = server_post_process_message;\n    } else {\n        transition = client_read_transition;\n        process_message = client_process_message;\n        max_message_size = client_max_message_size;\n        post_process_message = client_post_process_message;\n    }\n    if (st->read_state_first_init) {\n        s->first_packet = 1;\n        st->read_state_first_init = 0;\n    }\n    while(1) {\n        switch(st->read_state) {\n        case READ_STATE_HEADER:\n            s->init_num = 0;\n            if (SSL_IS_DTLS(s)) {\n                ret = dtls_get_message(s, &mt, &len);\n            } else {\n                ret = tls_get_message_header(s, &mt);\n            }\n            if (ret == 0) {\n                return SUB_STATE_ERROR;\n            }\n            if (cb != NULL) {\n                if (s->server)\n                    cb(s, SSL_CB_ACCEPT_LOOP, 1);\n                else\n                    cb(s, SSL_CB_CONNECT_LOOP, 1);\n            }\n            if(!transition(s, mt)) {\n                ssl3_send_alert(s, SSL3_AL_FATAL, SSL3_AD_UNEXPECTED_MESSAGE);\n                SSLerr(SSL_F_READ_STATE_MACHINE, SSL_R_UNEXPECTED_MESSAGE);\n                return SUB_STATE_ERROR;\n            }\n            if (s->s3->tmp.message_size > max_message_size(s)) {\n                ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);\n                SSLerr(SSL_F_READ_STATE_MACHINE, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n                return SUB_STATE_ERROR;\n            }\n            st->read_state = READ_STATE_BODY;\n        case READ_STATE_BODY:\n            if (!SSL_IS_DTLS(s)) {\n                ret = tls_get_message_body(s, &len);\n                if (ret == 0) {\n                    return SUB_STATE_ERROR;\n                }\n            }\n            s->first_packet = 0;\n            if (!PACKET_buf_init(&pkt, s->init_msg, len)) {\n                ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n                SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n                return SUB_STATE_ERROR;\n            }\n            ret = process_message(s, &pkt);\n            if (ret == MSG_PROCESS_ERROR) {\n                return SUB_STATE_ERROR;\n            }\n            if (ret == MSG_PROCESS_FINISHED_READING) {\n                if (SSL_IS_DTLS(s)) {\n                    dtls1_stop_timer(s);\n                }\n                return SUB_STATE_FINISHED;\n            }\n            if (ret == MSG_PROCESS_CONTINUE_PROCESSING) {\n                st->read_state = READ_STATE_POST_PROCESS;\n                st->read_state_work = WORK_MORE_A;\n            } else {\n                st->read_state = READ_STATE_HEADER;\n            }\n            break;\n        case READ_STATE_POST_PROCESS:\n            st->read_state_work = post_process_message(s, st->read_state_work);\n            switch(st->read_state_work) {\n            default:\n                return SUB_STATE_ERROR;\n            case WORK_FINISHED_CONTINUE:\n                st->read_state = READ_STATE_HEADER;\n                break;\n            case WORK_FINISHED_STOP:\n                if (SSL_IS_DTLS(s)) {\n                    dtls1_stop_timer(s);\n                }\n                return SUB_STATE_FINISHED;\n            }\n            break;\n        default:\n            ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n            SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n            statem_set_error(s);\n            return SUB_STATE_ERROR;\n        }\n    }\n}', 'int tls_get_message_header(SSL *s, int *mt)\n{\n    int skip_message, i, recvd_type, al;\n    unsigned char *p;\n    unsigned long l;\n    p = (unsigned char *)s->init_buf->data;\n    do {\n        while (s->init_num < SSL3_HM_HEADER_LENGTH) {\n            i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, &recvd_type,\n                &p[s->init_num], SSL3_HM_HEADER_LENGTH - s->init_num, 0);\n            if (i <= 0) {\n                s->rwstate = SSL_READING;\n                return 0;\n            }\n            if (recvd_type == SSL3_RT_CHANGE_CIPHER_SPEC) {\n                s->s3->tmp.message_type = *mt = SSL3_MT_CHANGE_CIPHER_SPEC;\n                s->init_num = i - 1;\n                s->s3->tmp.message_size = i;\n                return 1;\n            } else if (recvd_type != SSL3_RT_HANDSHAKE) {\n                al = SSL_AD_UNEXPECTED_MESSAGE;\n                SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, SSL_R_CCS_RECEIVED_EARLY);\n                goto f_err;\n            }\n            s->init_num += i;\n        }\n        skip_message = 0;\n        if (!s->server)\n            if (p[0] == SSL3_MT_HELLO_REQUEST)\n                if (p[1] == 0 && p[2] == 0 && p[3] == 0) {\n                    s->init_num = 0;\n                    skip_message = 1;\n                    if (s->msg_callback)\n                        s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n                                        p, SSL3_HM_HEADER_LENGTH, s,\n                                        s->msg_callback_arg);\n                }\n    } while (skip_message);\n    *mt = *p;\n    s->s3->tmp.message_type = *(p++);\n    if(RECORD_LAYER_is_sslv2_record(&s->rlayer)) {\n        l = RECORD_LAYER_get_rrec_length(&s->rlayer)\n            + SSL3_HM_HEADER_LENGTH;\n        if (l && !BUF_MEM_grow_clean(s->init_buf, (int)l)) {\n            SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB);\n            goto err;\n        }\n        s->s3->tmp.message_size = l;\n        s->init_msg = s->init_buf->data;\n        s->init_num = SSL3_HM_HEADER_LENGTH;\n    } else {\n        n2l3(p, l);\n        if (l > (INT_MAX - SSL3_HM_HEADER_LENGTH)) {\n            al = SSL_AD_ILLEGAL_PARAMETER;\n            SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n            goto f_err;\n        }\n        if (l && !BUF_MEM_grow_clean(s->init_buf,\n                                    (int)l + SSL3_HM_HEADER_LENGTH)) {\n            SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB);\n            goto err;\n        }\n        s->s3->tmp.message_size = l;\n        s->init_msg = s->init_buf->data + SSL3_HM_HEADER_LENGTH;\n        s->init_num = 0;\n    }\n    return 1;\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\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        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_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}']