ssl/statem/statem.c:786: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `statem_do_write`.
Showing all 13 steps of the trace


ssl/statem/statem.c:716:1: Parameter `s->rlayer.numwpipes`
714.    * result in an NBIO event.
715.    */
716. > static SUB_STATE_RETURN write_state_machine(SSL *s)
717.   {
718.       OSSL_STATEM *st = &s->statem;

ssl/statem/statem.c:786:19: Call
784.                   dtls1_start_timer(s);
785.               }
786.               ret = statem_do_write(s);
                         ^
787.               if (ret <= 0) {
788.                   return SUB_STATE_ERROR;

ssl/statem/statem.c:660:1: Parameter `s->rlayer.numwpipes`
  658.    * Send a previously constructed message to the peer.
  659.    */
  660. > static int statem_do_write(SSL *s)
  661.   {
  662.       OSSL_STATEM *st = &s->statem;

ssl/statem/statem.c:667:20: Call
  665.               || st->hand_state == TLS_ST_SW_CHANGE) {
  666.           if (SSL_IS_DTLS(s))
  667.               return dtls1_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);
                            ^
  668.           else
  669.               return ssl3_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);

ssl/statem/statem_dtls.c:217:1: Parameter `s->rlayer.numwpipes`
    215.    * SSL3_RT_CHANGE_CIPHER_SPEC)
    216.    */
    217. > int dtls1_do_write(SSL *s, int type)
    218.   {
    219.       int ret;

ssl/statem/statem_dtls.c:346:15: Call
    344.           }
    345.   
    346.           ret = dtls1_write_bytes(s, type, &s->init_buf->data[s->init_off],
                         ^
    347.                                   len);
    348.           if (ret < 0) {

ssl/record/rec_layer_d1.c:1021:1: Parameter `s->rlayer.numwpipes`
      1019.    * not all data has been sent or non-blocking IO.
      1020.    */
      1021. > int dtls1_write_bytes(SSL *s, int type, const void *buf, int len)
      1022.   {
      1023.       int i;

ssl/record/rec_layer_d1.c:1027:9: Call
      1025.       OPENSSL_assert(len <= SSL3_RT_MAX_PLAIN_LENGTH);
      1026.       s->rwstate = SSL_NOTHING;
      1027.       i = do_dtls1_write(s, type, buf, len, 0);
                      ^
      1028.       return i;
      1029.   }

ssl/record/rec_layer_d1.c:1031:1: Parameter `s->rlayer.numwpipes`
        1029.   }
        1030.   
        1031. > int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
        1032.                      unsigned int len, int create_empty_fragment)
        1033.   {

ssl/record/rec_layer_d1.c:1050:17: Call
        1048.       if (SSL3_BUFFER_get_left(wb) != 0) {
        1049.           OPENSSL_assert(0);      /* XDTLS: want to see if we ever get here */
        1050.           return (ssl3_write_pending(s, type, buf, len));
                                ^
        1051.       }
        1052.   

ssl/record/rec_layer_s3.c:999:1: <LHS trace>
997.   
998.   /* if s->s3->wbuf.left != 0, we need to call this */
999. > int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
1000.                          unsigned int len)
1001.   {

ssl/record/rec_layer_s3.c:999:1: Parameter `s->rlayer.numwpipes`
          997.   
          998.   /* if s->s3->wbuf.left != 0, we need to call this */
          999. > int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
          1000.                          unsigned int len)
          1001.   {

ssl/record/rec_layer_s3.c:1018:20: Binary operation: ([0, +oo] - 1):unsigned32 by call to `statem_do_write` 
          1016.           /* Loop until we find a buffer we haven't written out yet */
          1017.           if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0
          1018.                   && currbuf < s->rlayer.numwpipes - 1) {
                                     ^
          1019.               currbuf++;
          1020.               continue;

int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
                       unsigned int len)
{
    int i;
    SSL3_BUFFER *wb = s->rlayer.wbuf;
    unsigned int currbuf = 0;
    if ((s->rlayer.wpend_tot > (int)len)
        || ((s->rlayer.wpend_buf != buf) &&
            !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))
        || (s->rlayer.wpend_type != type)) {
        SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY);
        return (-1);
    }
    for (;;) {
        if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0
                && currbuf < s->rlayer.numwpipes - 1) {
            currbuf++;
            continue;
        }
        clear_sys_error();
        if (s->wbio != NULL) {
            s->rwstate = SSL_WRITING;
            i = BIO_write(s->wbio,
                (char *)&(SSL3_BUFFER_get_buf(&wb[currbuf])[
                                SSL3_BUFFER_get_offset(&wb[currbuf])]),
                (unsigned int)SSL3_BUFFER_get_left(&wb[currbuf]));
        } else {
            SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BIO_NOT_SET);
            i = -1;
        }
        if (i == SSL3_BUFFER_get_left(&wb[currbuf])) {
            SSL3_BUFFER_set_left(&wb[currbuf], 0);
            SSL3_BUFFER_add_offset(&wb[currbuf], i);
            if (currbuf + 1 < s->rlayer.numwpipes)
                continue;
            s->rwstate = SSL_NOTHING;
            return (s->rlayer.wpend_ret);
        } else if (i <= 0) {
            if (SSL_IS_DTLS(s)) {
                SSL3_BUFFER_set_left(&wb[currbuf], 0);
            }
            return (i);
        }
        SSL3_BUFFER_add_offset(&wb[currbuf], i);
        SSL3_BUFFER_add_left(&wb[currbuf], -i);
    }
}
['static SUB_STATE_RETURN write_state_machine(SSL *s)\n{\n    OSSL_STATEM *st = &s->statem;\n    int ret;\n    WRITE_TRAN (*transition)(SSL *s);\n    WORK_STATE (*pre_work)(SSL *s, WORK_STATE wst);\n    WORK_STATE (*post_work)(SSL *s, WORK_STATE wst);\n    int (*construct_message)(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_write_transition;\n        pre_work = ossl_statem_server_pre_work;\n        post_work = ossl_statem_server_post_work;\n        construct_message = ossl_statem_server_construct_message;\n    } else {\n        transition = ossl_statem_client_write_transition;\n        pre_work = ossl_statem_client_pre_work;\n        post_work = ossl_statem_client_post_work;\n        construct_message = ossl_statem_client_construct_message;\n    }\n    while(1) {\n        switch(st->write_state) {\n        case WRITE_STATE_TRANSITION:\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            switch(transition(s)) {\n            case WRITE_TRAN_CONTINUE:\n                st->write_state = WRITE_STATE_PRE_WORK;\n                st->write_state_work = WORK_MORE_A;\n                break;\n            case WRITE_TRAN_FINISHED:\n                return SUB_STATE_FINISHED;\n                break;\n            default:\n                return SUB_STATE_ERROR;\n            }\n            break;\n        case WRITE_STATE_PRE_WORK:\n            switch(st->write_state_work = pre_work(s, st->write_state_work)) {\n            default:\n                return SUB_STATE_ERROR;\n            case WORK_FINISHED_CONTINUE:\n                st->write_state = WRITE_STATE_SEND;\n                break;\n            case WORK_FINISHED_STOP:\n                return SUB_STATE_END_HANDSHAKE;\n            }\n            if(construct_message(s) == 0)\n                return SUB_STATE_ERROR;\n        case WRITE_STATE_SEND:\n            if (SSL_IS_DTLS(s) && st->use_timer) {\n                dtls1_start_timer(s);\n            }\n            ret = statem_do_write(s);\n            if (ret <= 0) {\n                return SUB_STATE_ERROR;\n            }\n            st->write_state = WRITE_STATE_POST_WORK;\n            st->write_state_work = WORK_MORE_A;\n        case WRITE_STATE_POST_WORK:\n            switch(st->write_state_work = post_work(s, st->write_state_work)) {\n            default:\n                return SUB_STATE_ERROR;\n            case WORK_FINISHED_CONTINUE:\n                st->write_state = WRITE_STATE_TRANSITION;\n                break;\n            case WORK_FINISHED_STOP:\n                return SUB_STATE_END_HANDSHAKE;\n            }\n            break;\n        default:\n            return SUB_STATE_ERROR;\n        }\n    }\n}', 'static int statem_do_write(SSL *s)\n{\n    OSSL_STATEM *st = &s->statem;\n    if (st->hand_state == TLS_ST_CW_CHANGE\n            || st->hand_state == TLS_ST_SW_CHANGE) {\n        if (SSL_IS_DTLS(s))\n            return dtls1_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);\n        else\n            return ssl3_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);\n    } else {\n        return ssl_do_write(s);\n    }\n}', 'int dtls1_do_write(SSL *s, int type)\n{\n    int ret;\n    unsigned int curr_mtu;\n    int retry = 1;\n    unsigned int len, frag_off, mac_size, blocksize, used_len;\n    if (!dtls1_query_mtu(s))\n        return -1;\n    OPENSSL_assert(s->d1->mtu >= dtls1_min_mtu(s));\n    if (s->init_off == 0 && type == SSL3_RT_HANDSHAKE)\n        OPENSSL_assert(s->init_num ==\n                       (int)s->d1->w_msg_hdr.msg_len +\n                       DTLS1_HM_HEADER_LENGTH);\n    if (s->write_hash) {\n        if (s->enc_write_ctx\n            && (EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_write_ctx)) &\n                EVP_CIPH_FLAG_AEAD_CIPHER) != 0)\n            mac_size = 0;\n        else\n            mac_size = EVP_MD_CTX_size(s->write_hash);\n    } else\n        mac_size = 0;\n    if (s->enc_write_ctx &&\n        (EVP_CIPHER_CTX_mode(s->enc_write_ctx) == EVP_CIPH_CBC_MODE))\n        blocksize = 2 * EVP_CIPHER_CTX_block_size(s->enc_write_ctx);\n    else\n        blocksize = 0;\n    frag_off = 0;\n    s->rwstate = SSL_NOTHING;\n    while (s->init_num > 0) {\n        if (type == SSL3_RT_HANDSHAKE && s->init_off != 0) {\n            if (frag_off > 0) {\n                if (s->init_off <= DTLS1_HM_HEADER_LENGTH) {\n                    return -1;\n                }\n                s->init_off -= DTLS1_HM_HEADER_LENGTH;\n                s->init_num += DTLS1_HM_HEADER_LENGTH;\n            } else {\n                frag_off = s->d1->w_msg_hdr.frag_off;\n            }\n        }\n        used_len = BIO_wpending(SSL_get_wbio(s)) + DTLS1_RT_HEADER_LENGTH\n            + mac_size + blocksize;\n        if (s->d1->mtu > used_len)\n            curr_mtu = s->d1->mtu - used_len;\n        else\n            curr_mtu = 0;\n        if (curr_mtu <= DTLS1_HM_HEADER_LENGTH) {\n            ret = BIO_flush(SSL_get_wbio(s));\n            if (ret <= 0) {\n                s->rwstate = SSL_WRITING;\n                return ret;\n            }\n            used_len = DTLS1_RT_HEADER_LENGTH + mac_size + blocksize;\n            if (s->d1->mtu > used_len + DTLS1_HM_HEADER_LENGTH) {\n                curr_mtu = s->d1->mtu - used_len;\n            } else {\n                return -1;\n            }\n        }\n        if (((unsigned int)s->init_num) > curr_mtu)\n            len = curr_mtu;\n        else\n            len = s->init_num;\n        if (len > INT_MAX)\n            len = INT_MAX;\n        if (type == SSL3_RT_HANDSHAKE) {\n            if (len < DTLS1_HM_HEADER_LENGTH) {\n                return -1;\n            }\n            dtls1_fix_message_header(s, frag_off,\n                                     len - DTLS1_HM_HEADER_LENGTH);\n            dtls1_write_message_header(s,\n                                       (unsigned char *)&s->init_buf->\n                                       data[s->init_off]);\n        }\n        ret = dtls1_write_bytes(s, type, &s->init_buf->data[s->init_off],\n                                len);\n        if (ret < 0) {\n            if (retry && BIO_ctrl(SSL_get_wbio(s),\n                                  BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0) {\n                if (!(SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) {\n                    if (!dtls1_query_mtu(s))\n                        return -1;\n                    retry = 0;\n                } else\n                    return -1;\n            } else {\n                return (-1);\n            }\n        } else {\n            OPENSSL_assert(len == (unsigned int)ret);\n            if (type == SSL3_RT_HANDSHAKE && !s->d1->retransmitting) {\n                unsigned char *p =\n                    (unsigned char *)&s->init_buf->data[s->init_off];\n                const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;\n                int xlen;\n                if (frag_off == 0 && s->version != DTLS1_BAD_VER) {\n                    *p++ = msg_hdr->type;\n                    l2n3(msg_hdr->msg_len, p);\n                    s2n(msg_hdr->seq, p);\n                    l2n3(0, p);\n                    l2n3(msg_hdr->msg_len, p);\n                    p -= DTLS1_HM_HEADER_LENGTH;\n                    xlen = ret;\n                } else {\n                    p += DTLS1_HM_HEADER_LENGTH;\n                    xlen = ret - DTLS1_HM_HEADER_LENGTH;\n                }\n                ssl3_finish_mac(s, p, xlen);\n            }\n            if (ret == s->init_num) {\n                if (s->msg_callback)\n                    s->msg_callback(1, s->version, type, s->init_buf->data,\n                                    (size_t)(s->init_off + s->init_num), s,\n                                    s->msg_callback_arg);\n                s->init_off = 0;\n                s->init_num = 0;\n                return (1);\n            }\n            s->init_off += ret;\n            s->init_num -= ret;\n            ret -= DTLS1_HM_HEADER_LENGTH;\n            frag_off += ret;\n            dtls1_fix_message_header(s, frag_off, 0);\n        }\n    }\n    return (0);\n}', 'int dtls1_write_bytes(SSL *s, int type, const void *buf, int len)\n{\n    int i;\n    OPENSSL_assert(len <= SSL3_RT_MAX_PLAIN_LENGTH);\n    s->rwstate = SSL_NOTHING;\n    i = do_dtls1_write(s, type, buf, len, 0);\n    return i;\n}', 'int do_dtls1_write(SSL *s, int type, const unsigned char *buf,\n                   unsigned int len, int create_empty_fragment)\n{\n    unsigned char *p, *pseq;\n    int i, mac_size, clear = 0;\n    int prefix_len = 0;\n    int eivlen;\n    SSL3_RECORD wr;\n    SSL3_BUFFER *wb;\n    SSL_SESSION *sess;\n    wb = &s->rlayer.wbuf[0];\n    if (SSL3_BUFFER_get_left(wb) != 0) {\n        OPENSSL_assert(0);\n        return (ssl3_write_pending(s, type, buf, len));\n    }\n    if (s->s3->alert_dispatch) {\n        i = s->method->ssl_dispatch_alert(s);\n        if (i <= 0)\n            return (i);\n    }\n    if (len == 0 && !create_empty_fragment)\n        return 0;\n    sess = s->session;\n    if ((sess == NULL) ||\n        (s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL))\n        clear = 1;\n    if (clear)\n        mac_size = 0;\n    else {\n        mac_size = EVP_MD_CTX_size(s->write_hash);\n        if (mac_size < 0)\n            goto err;\n    }\n    p = SSL3_BUFFER_get_buf(wb) + prefix_len;\n    *(p++) = type & 0xff;\n    SSL3_RECORD_set_type(&wr, type);\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    pseq = p;\n    p += 10;\n    if (s->enc_write_ctx) {\n        int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);\n        if (mode == EVP_CIPH_CBC_MODE) {\n            eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);\n            if (eivlen <= 1)\n                eivlen = 0;\n        }\n        else if (mode == EVP_CIPH_GCM_MODE)\n            eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;\n        else if (mode == EVP_CIPH_CCM_MODE)\n            eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;\n        else\n            eivlen = 0;\n    } else\n        eivlen = 0;\n    SSL3_RECORD_set_data(&wr, p + eivlen);\n    SSL3_RECORD_set_length(&wr, (int)len);\n    SSL3_RECORD_set_input(&wr, (unsigned char *)buf);\n    if (s->compress != NULL) {\n        if (!ssl3_do_compress(s, &wr)) {\n            SSLerr(SSL_F_DO_DTLS1_WRITE, SSL_R_COMPRESSION_FAILURE);\n            goto err;\n        }\n    } else {\n        memcpy(SSL3_RECORD_get_data(&wr), SSL3_RECORD_get_input(&wr),\n               SSL3_RECORD_get_length(&wr));\n        SSL3_RECORD_reset_input(&wr);\n    }\n    if (mac_size != 0) {\n        if (s->method->ssl3_enc->mac(s, &wr,\n                &(p[SSL3_RECORD_get_length(&wr) + eivlen]), 1) < 0)\n            goto err;\n        SSL3_RECORD_add_length(&wr, mac_size);\n    }\n    SSL3_RECORD_set_data(&wr, p);\n    SSL3_RECORD_reset_input(&wr);\n    if (eivlen)\n        SSL3_RECORD_add_length(&wr, eivlen);\n    if (s->method->ssl3_enc->enc(s, &wr, 1, 1) < 1)\n        goto err;\n    s2n(s->rlayer.d->w_epoch, pseq);\n    memcpy(pseq, &(s->rlayer.write_sequence[2]), 6);\n    pseq += 6;\n    s2n(SSL3_RECORD_get_length(&wr), pseq);\n    if (s->msg_callback)\n        s->msg_callback(1, 0, SSL3_RT_HEADER, pseq - DTLS1_RT_HEADER_LENGTH,\n                        DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n    SSL3_RECORD_set_type(&wr, type);\n    SSL3_RECORD_add_length(&wr, DTLS1_RT_HEADER_LENGTH);\n    ssl3_record_sequence_update(&(s->rlayer.write_sequence[0]));\n    if (create_empty_fragment) {\n        return wr.length;\n    }\n    SSL3_BUFFER_set_left(wb, prefix_len + SSL3_RECORD_get_length(&wr));\n    SSL3_BUFFER_set_offset(wb, 0);\n    s->rlayer.wpend_tot = len;\n    s->rlayer.wpend_buf = buf;\n    s->rlayer.wpend_type = type;\n    s->rlayer.wpend_ret = len;\n    return ssl3_write_pending(s, type, buf, len);\n err:\n    return -1;\n}', 'int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,\n                       unsigned int len)\n{\n    int i;\n    SSL3_BUFFER *wb = s->rlayer.wbuf;\n    unsigned int currbuf = 0;\n    if ((s->rlayer.wpend_tot > (int)len)\n        || ((s->rlayer.wpend_buf != buf) &&\n            !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))\n        || (s->rlayer.wpend_type != type)) {\n        SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY);\n        return (-1);\n    }\n    for (;;) {\n        if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0\n                && currbuf < s->rlayer.numwpipes - 1) {\n            currbuf++;\n            continue;\n        }\n        clear_sys_error();\n        if (s->wbio != NULL) {\n            s->rwstate = SSL_WRITING;\n            i = BIO_write(s->wbio,\n                (char *)&(SSL3_BUFFER_get_buf(&wb[currbuf])[\n                                SSL3_BUFFER_get_offset(&wb[currbuf])]),\n                (unsigned int)SSL3_BUFFER_get_left(&wb[currbuf]));\n        } else {\n            SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BIO_NOT_SET);\n            i = -1;\n        }\n        if (i == SSL3_BUFFER_get_left(&wb[currbuf])) {\n            SSL3_BUFFER_set_left(&wb[currbuf], 0);\n            SSL3_BUFFER_add_offset(&wb[currbuf], i);\n            if (currbuf + 1 < s->rlayer.numwpipes)\n                continue;\n            s->rwstate = SSL_NOTHING;\n            return (s->rlayer.wpend_ret);\n        } else if (i <= 0) {\n            if (SSL_IS_DTLS(s)) {\n                SSL3_BUFFER_set_left(&wb[currbuf], 0);\n            }\n            return (i);\n        }\n        SSL3_BUFFER_add_offset(&wb[currbuf], i);\n        SSL3_BUFFER_add_left(&wb[currbuf], -i);\n    }\n}']