ssl/statem/statem.c:559: 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:518:1: Parameter `s->rlayer.rrec[*].length`
516.    * will resume in the same state where we left off.
517.    */
518. > static SUB_STATE_RETURN read_state_machine(SSL *s) {
519.       OSSL_STATEM *st = &s->statem;
520.       int ret, mt;

ssl/statem/statem.c:559:23: Call
557.                   ret = dtls_get_message(s, &mt, &len);
558.               } else {
559.                   ret = tls_get_message_header(s, &mt);
                             ^
560.               }
561.   

ssl/statem/statem_lib.c:439:1: Parameter `s->init_buf->length`
  437.   }
  438.   
  439. > int tls_get_message_header(SSL *s, int *mt)
  440.   {
  441.       /* s->init_num < SSL3_HM_HEADER_LENGTH */

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

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

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

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

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

crypto/buffer/buffer.c:163:9: Binary operation: ([0, +oo] - [s->rlayer.rrec[*].length + 4, s->rlayer.rrec[*].length + 4]):unsigned64 by call to `tls_get_message_header` 
    161.   
    162.       if (str->length >= len) {
    163.           memset(&str->data[len], 0, str->length - len);
                   ^
    164.           str->length = len;
    165.           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_clear_realloc(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 SUB_STATE_RETURN read_state_machine(SSL *s) {\n    OSSL_STATEM *st = &s->statem;\n    int ret, mt;\n    unsigned long len = 0;\n    int (*transition)(SSL *s, int mt);\n    PACKET pkt;\n    MSG_PROCESS_RETURN (*process_message)(SSL *s, PACKET *pkt);\n    WORK_STATE (*post_process_message)(SSL *s, WORK_STATE wst);\n    unsigned long (*max_message_size)(SSL *s);\n    void (*cb) (const SSL *ssl, int type, int val) = NULL;\n    cb = get_callback(s);\n    if(s->server) {\n        transition = ossl_statem_server_read_transition;\n        process_message = ossl_statem_server_process_message;\n        max_message_size = ossl_statem_server_max_message_size;\n        post_process_message = ossl_statem_server_post_process_message;\n    } else {\n        transition = ossl_statem_client_read_transition;\n        process_message = ossl_statem_client_process_message;\n        max_message_size = ossl_statem_client_max_message_size;\n        post_process_message = ossl_statem_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            ossl_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_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}']