ssl/record/rec_layer_s3.c:707: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `do_ssl3_write`.
Showing all 9 steps of the trace


ssl/record/rec_layer_s3.c:449:1: Parameter `s->rlayer.numwpipes`
447.    * not all data has been sent or non-blocking IO.
448.    */
449. > int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
450.   {
451.       const unsigned char *buf = buf_;

ssl/record/rec_layer_s3.c:707:13: Call
705.           }
706.   
707.           i = do_ssl3_write(s, type, &(buf[tot]), pipelens, numpipes, 0);
                   ^
708.           if (i <= 0) {
709.               /* XXX should we ssl3_release_write_buffer if i<0? */

ssl/record/rec_layer_s3.c:735:1: Parameter `s->rlayer.numwpipes`
  733.   }
  734.   
  735. > int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
  736.                     unsigned int *pipelens, unsigned int numpipes,
  737.                     int create_empty_fragment)

ssl/record/rec_layer_s3.c:756:9: Call
  754.        * will happen with non blocking IO
  755.        */
  756.       if (RECORD_LAYER_write_pending(&s->rlayer))
                 ^
  757.           return (ssl3_write_pending(s, type, buf, totlen));
  758.   

ssl/record/rec_layer_s3.c:191:1: Parameter `rl->numwpipes`
    189.   }
    190.   
    191. > int RECORD_LAYER_write_pending(const RECORD_LAYER *rl)
    192.   {
    193.       return (rl->numwpipes > 0)

ssl/record/rec_layer_s3.c:757:17: Call
  755.        */
  756.       if (RECORD_LAYER_write_pending(&s->rlayer))
  757.           return (ssl3_write_pending(s, type, buf, totlen));
                         ^
  758.   
  759.       /* If we have an alert to send, lets send it */

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 `do_ssl3_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);
    }
}
['int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)\n{\n    const unsigned char *buf = buf_;\n    int tot;\n    unsigned int n, split_send_fragment, maxpipes;\n#if !defined(OPENSSL_NO_MULTIBLOCK) && EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n    unsigned int max_send_fragment, nw;\n    unsigned int u_len = (unsigned int)len;\n#endif\n    SSL3_BUFFER *wb = &s->rlayer.wbuf[0];\n    int i;\n    if (len < 0) {\n        SSLerr(SSL_F_SSL3_WRITE_BYTES, SSL_R_SSL_NEGATIVE_LENGTH);\n        return -1;\n    }\n    s->rwstate = SSL_NOTHING;\n    tot = s->rlayer.wnum;\n    if ((unsigned int)len < s->rlayer.wnum) {\n        SSLerr(SSL_F_SSL3_WRITE_BYTES, SSL_R_BAD_LENGTH);\n        return -1;\n    }\n    s->rlayer.wnum = 0;\n    if (SSL_in_init(s) && !ossl_statem_get_in_handshake(s)) {\n        i = s->handshake_func(s);\n        if (i < 0)\n            return (i);\n        if (i == 0) {\n            SSLerr(SSL_F_SSL3_WRITE_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n            return -1;\n        }\n    }\n    if (wb->left != 0) {\n        i = ssl3_write_pending(s, type, &buf[tot], s->rlayer.wpend_tot);\n        if (i <= 0) {\n            s->rlayer.wnum = tot;\n            return i;\n        }\n        tot += i;\n    }\n#if !defined(OPENSSL_NO_MULTIBLOCK) && EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n    if (type == SSL3_RT_APPLICATION_DATA &&\n        u_len >= 4 * (max_send_fragment = s->max_send_fragment) &&\n        s->compress == NULL && s->msg_callback == NULL &&\n        !SSL_USE_ETM(s) && SSL_USE_EXPLICIT_IV(s) &&\n        EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_write_ctx)) &\n        EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK) {\n        unsigned char aad[13];\n        EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;\n        int packlen;\n        if ((max_send_fragment & 0xfff) == 0)\n            max_send_fragment -= 512;\n        if (tot == 0 || wb->buf == NULL) {\n            ssl3_release_write_buffer(s);\n            packlen = EVP_CIPHER_CTX_ctrl(s->enc_write_ctx,\n                                          EVP_CTRL_TLS1_1_MULTIBLOCK_MAX_BUFSIZE,\n                                          max_send_fragment, NULL);\n            if (u_len >= 8 * max_send_fragment)\n                packlen *= 8;\n            else\n                packlen *= 4;\n            wb->buf = OPENSSL_malloc(packlen);\n            if (wb->buf == NULL) {\n                SSLerr(SSL_F_SSL3_WRITE_BYTES, ERR_R_MALLOC_FAILURE);\n                return -1;\n            }\n            wb->len = packlen;\n        } else if (tot == len) {\n            OPENSSL_free(wb->buf);\n            wb->buf = NULL;\n            return tot;\n        }\n        n = (len - tot);\n        for (;;) {\n            if (n < 4 * max_send_fragment) {\n                OPENSSL_free(wb->buf);\n                wb->buf = NULL;\n                break;\n            }\n            if (s->s3->alert_dispatch) {\n                i = s->method->ssl_dispatch_alert(s);\n                if (i <= 0) {\n                    s->rlayer.wnum = tot;\n                    return i;\n                }\n            }\n            if (n >= 8 * max_send_fragment)\n                nw = max_send_fragment * (mb_param.interleave = 8);\n            else\n                nw = max_send_fragment * (mb_param.interleave = 4);\n            memcpy(aad, s->rlayer.write_sequence, 8);\n            aad[8] = type;\n            aad[9] = (unsigned char)(s->version >> 8);\n            aad[10] = (unsigned char)(s->version);\n            aad[11] = 0;\n            aad[12] = 0;\n            mb_param.out = NULL;\n            mb_param.inp = aad;\n            mb_param.len = nw;\n            packlen = EVP_CIPHER_CTX_ctrl(s->enc_write_ctx,\n                                          EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,\n                                          sizeof(mb_param), &mb_param);\n            if (packlen <= 0 || packlen > (int)wb->len) {\n                OPENSSL_free(wb->buf);\n                wb->buf = NULL;\n                break;\n            }\n            mb_param.out = wb->buf;\n            mb_param.inp = &buf[tot];\n            mb_param.len = nw;\n            if (EVP_CIPHER_CTX_ctrl(s->enc_write_ctx,\n                                    EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,\n                                    sizeof(mb_param), &mb_param) <= 0)\n                return -1;\n            s->rlayer.write_sequence[7] += mb_param.interleave;\n            if (s->rlayer.write_sequence[7] < mb_param.interleave) {\n                int j = 6;\n                while (j >= 0 && (++s->rlayer.write_sequence[j--]) == 0) ;\n            }\n            wb->offset = 0;\n            wb->left = packlen;\n            s->rlayer.wpend_tot = nw;\n            s->rlayer.wpend_buf = &buf[tot];\n            s->rlayer.wpend_type = type;\n            s->rlayer.wpend_ret = nw;\n            i = ssl3_write_pending(s, type, &buf[tot], nw);\n            if (i <= 0) {\n                if (i < 0 && (!s->wbio || !BIO_should_retry(s->wbio))) {\n                    OPENSSL_free(wb->buf);\n                    wb->buf = NULL;\n                }\n                s->rlayer.wnum = tot;\n                return i;\n            }\n            if (i == (int)n) {\n                OPENSSL_free(wb->buf);\n                wb->buf = NULL;\n                return tot + i;\n            }\n            n -= i;\n            tot += i;\n        }\n    } else\n#endif\n    if (tot == len) {\n        if (s->mode & SSL_MODE_RELEASE_BUFFERS && !SSL_IS_DTLS(s))\n            ssl3_release_write_buffer(s);\n        return tot;\n    }\n    n = (len - tot);\n    split_send_fragment = s->split_send_fragment;\n    maxpipes = s->max_pipelines;\n    if (maxpipes > SSL_MAX_PIPELINES) {\n        SSLerr(SSL_F_SSL3_WRITE_BYTES, ERR_R_INTERNAL_ERROR);\n        return -1;\n    }\n    if (maxpipes == 0\n            || s->enc_write_ctx == NULL\n            || !(EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_write_ctx))\n                 & EVP_CIPH_FLAG_PIPELINE)\n            || !SSL_USE_EXPLICIT_IV(s))\n        maxpipes = 1;\n    if (s->max_send_fragment == 0 || split_send_fragment > s->max_send_fragment\n            || split_send_fragment == 0) {\n        SSLerr(SSL_F_SSL3_WRITE_BYTES, ERR_R_INTERNAL_ERROR);\n        return -1;\n    }\n    for (;;) {\n        unsigned int pipelens[SSL_MAX_PIPELINES], tmppipelen, remain;\n        unsigned int numpipes, j;\n        if (n == 0)\n            numpipes = 1;\n        else\n            numpipes = ((n - 1) / split_send_fragment) + 1;\n        if (numpipes > maxpipes)\n            numpipes = maxpipes;\n        if (n / numpipes >= s->max_send_fragment) {\n            for (j = 0; j < numpipes; j++) {\n                pipelens[j] = s->max_send_fragment;\n            }\n        } else {\n            tmppipelen = n / numpipes;\n            remain = n % numpipes;\n            for (j = 0; j < numpipes; j++) {\n                pipelens[j] = tmppipelen;\n                if (j < remain)\n                    pipelens[j]++;\n            }\n        }\n        i = do_ssl3_write(s, type, &(buf[tot]), pipelens, numpipes, 0);\n        if (i <= 0) {\n            s->rlayer.wnum = tot;\n            return i;\n        }\n        if ((i == (int)n) ||\n            (type == SSL3_RT_APPLICATION_DATA &&\n             (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE))) {\n            s->s3->empty_fragment_done = 0;\n            if ((i == (int)n) && s->mode & SSL_MODE_RELEASE_BUFFERS &&\n                !SSL_IS_DTLS(s))\n                ssl3_release_write_buffer(s);\n            return tot + i;\n        }\n        n -= i;\n        tot += i;\n    }\n}', 'int do_ssl3_write(SSL *s, int type, const unsigned char *buf,\n                  unsigned int *pipelens, unsigned int numpipes,\n                  int create_empty_fragment)\n{\n    unsigned char *outbuf[SSL_MAX_PIPELINES], *plen[SSL_MAX_PIPELINES];\n    SSL3_RECORD wr[SSL_MAX_PIPELINES];\n    int i, mac_size, clear = 0;\n    int prefix_len = 0;\n    int eivlen;\n    size_t align = 0;\n    SSL3_BUFFER *wb;\n    SSL_SESSION *sess;\n    unsigned int totlen = 0;\n    unsigned int j;\n    for (j = 0; j < numpipes; j++)\n        totlen += pipelens[j];\n    if (RECORD_LAYER_write_pending(&s->rlayer))\n        return (ssl3_write_pending(s, type, buf, totlen));\n    if (s->s3->alert_dispatch) {\n        i = s->method->ssl_dispatch_alert(s);\n        if (i <= 0)\n            return (i);\n    }\n    if (s->rlayer.numwpipes < numpipes)\n        if (!ssl3_setup_write_buffer(s, numpipes))\n            return -1;\n    if (totlen == 0 && !create_empty_fragment)\n        return 0;\n    sess = s->session;\n    if ((sess == NULL) ||\n        (s->enc_write_ctx == NULL) ||\n        (EVP_MD_CTX_md(s->write_hash) == NULL)) {\n        clear = s->enc_write_ctx ? 0 : 1;\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    if (!clear && !create_empty_fragment && !s->s3->empty_fragment_done) {\n        if (s->s3->need_empty_fragments && type == SSL3_RT_APPLICATION_DATA) {\n            unsigned int tmppipelen = 0;\n            prefix_len = do_ssl3_write(s, type, buf, &tmppipelen, 1, 1);\n            if (prefix_len <= 0)\n                goto err;\n            if (prefix_len >\n                (SSL3_RT_HEADER_LENGTH + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD))\n            {\n                SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n        }\n        s->s3->empty_fragment_done = 1;\n    }\n    if (create_empty_fragment) {\n        wb = &s->rlayer.wbuf[0];\n#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0\n        align = (size_t)SSL3_BUFFER_get_buf(wb) + 2 * SSL3_RT_HEADER_LENGTH;\n        align = (0-align) & (SSL3_ALIGN_PAYLOAD - 1);\n#endif\n        outbuf[0] = SSL3_BUFFER_get_buf(wb) + align;\n        SSL3_BUFFER_set_offset(wb, align);\n    } else if (prefix_len) {\n        wb = &s->rlayer.wbuf[0];\n        outbuf[0] = SSL3_BUFFER_get_buf(wb) + SSL3_BUFFER_get_offset(wb)\n                    + prefix_len;\n    } else {\n        for (j=0; j < numpipes; j++) {\n            wb = &s->rlayer.wbuf[j];\n#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0\n            align = (size_t)SSL3_BUFFER_get_buf(wb) + SSL3_RT_HEADER_LENGTH;\n            align = (-align) & (SSL3_ALIGN_PAYLOAD - 1);\n#endif\n            outbuf[j] = SSL3_BUFFER_get_buf(wb) + align;\n            SSL3_BUFFER_set_offset(wb, align);\n        }\n    }\n    if (s->enc_write_ctx && SSL_USE_EXPLICIT_IV(s)) {\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    totlen = 0;\n    memset(wr, 0, sizeof wr);\n    for (j=0; j < numpipes; j++) {\n        *(outbuf[j]++) = type & 0xff;\n        SSL3_RECORD_set_type(&wr[j], type);\n        *(outbuf[j]++) = (s->version >> 8);\n        if (SSL_get_state(s) == TLS_ST_CW_CLNT_HELLO\n            && !s->renegotiate && TLS1_get_version(s) > TLS1_VERSION)\n            *(outbuf[j]++) = 0x1;\n        else\n            *(outbuf[j]++) = s->version & 0xff;\n        plen[j] = outbuf[j];\n        outbuf[j] += 2;\n        SSL3_RECORD_set_data(&wr[j], outbuf[j] + eivlen);\n        SSL3_RECORD_set_length(&wr[j], (int)pipelens[j]);\n        SSL3_RECORD_set_input(&wr[j], (unsigned char *)&buf[totlen]);\n        totlen += pipelens[j];\n        if (s->compress != NULL) {\n            if (!ssl3_do_compress(s, &wr[j])) {\n                SSLerr(SSL_F_DO_SSL3_WRITE, SSL_R_COMPRESSION_FAILURE);\n                goto err;\n            }\n        } else {\n            memcpy(wr[j].data, wr[j].input, wr[j].length);\n            SSL3_RECORD_reset_input(&wr[j]);\n        }\n        if (!SSL_USE_ETM(s) && mac_size != 0) {\n            if (s->method->ssl3_enc->mac(s, &wr[j],\n                    &(outbuf[j][wr[j].length + eivlen]), 1) < 0)\n                goto err;\n            SSL3_RECORD_add_length(&wr[j], mac_size);\n        }\n        SSL3_RECORD_set_data(&wr[j], outbuf[j]);\n        SSL3_RECORD_reset_input(&wr[j]);\n        if (eivlen) {\n            SSL3_RECORD_add_length(&wr[j], eivlen);\n        }\n    }\n    if (s->method->ssl3_enc->enc(s, wr, numpipes, 1) < 1)\n        goto err;\n    for (j=0; j < numpipes; j++) {\n        if (SSL_USE_ETM(s) && mac_size != 0) {\n            if (s->method->ssl3_enc->mac(s, &wr[j],\n                                         outbuf[j] + wr[j].length, 1) < 0)\n                goto err;\n            SSL3_RECORD_add_length(&wr[j], mac_size);\n        }\n        s2n(SSL3_RECORD_get_length(&wr[j]), plen[j]);\n        if (s->msg_callback)\n            s->msg_callback(1, 0, SSL3_RT_HEADER, plen[j] - 5, 5, s,\n                            s->msg_callback_arg);\n        SSL3_RECORD_set_type(&wr[j], type);\n        SSL3_RECORD_add_length(&wr[j], SSL3_RT_HEADER_LENGTH);\n        if (create_empty_fragment) {\n            if (j > 0) {\n                SSLerr(SSL_F_DO_SSL3_WRITE, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n            return SSL3_RECORD_get_length(wr);\n        }\n        SSL3_BUFFER_set_left(&s->rlayer.wbuf[j],\n            prefix_len + SSL3_RECORD_get_length(&wr[j]));\n    }\n    s->rlayer.wpend_tot = totlen;\n    s->rlayer.wpend_buf = buf;\n    s->rlayer.wpend_type = type;\n    s->rlayer.wpend_ret = totlen;\n    return ssl3_write_pending(s, type, buf, totlen);\n err:\n    return -1;\n}', 'int RECORD_LAYER_write_pending(const RECORD_LAYER *rl)\n{\n    return (rl->numwpipes > 0)\n            && SSL3_BUFFER_get_left(&rl->wbuf[rl->numwpipes-1]) != 0;\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}']