ssl/d1_pkt.c:1396: error: INTEGER_OVERFLOW_L2
  ([0, max(0, `s->ctx->sessions->num_items`)] - 1):unsigned64 by call to `ssl3_send_alert`.
Showing all 11 steps of the trace


ssl/d1_pkt.c:767:1: Parameter `s->ctx->sessions->num_items`
765.    *             none of our business
766.    */
767. > int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
768.   {
769.       int al, i, j, ret;

ssl/d1_pkt.c:1396:5: Call
1394.   
1395.    f_err:
1396.       ssl3_send_alert(s, SSL3_AL_FATAL, al);
            ^
1397.    err:
1398.       return (-1);

ssl/s3_pkt.c:1760:1: Parameter `s->ctx->sessions->num_items`
  1758.   }
  1759.   
  1760. > int ssl3_send_alert(SSL *s, int level, int desc)
  1761.   {
  1762.       /* Map tls/ssl alert value to correct one */

ssl/s3_pkt.c:1771:9: Call
  1769.       /* If a fatal one, remove from cache */
  1770.       if ((level == SSL3_AL_FATAL) && (s->session != NULL))
  1771.           SSL_CTX_remove_session(s->ctx, s->session);
                  ^
  1772.   
  1773.       s->s3->alert_dispatch = 1;

ssl/ssl_sess.c:673:1: Parameter `ctx->sessions->num_items`
    671.   }
    672.   
    673. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
    674.   {
    675.       return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:675:12: Call
    673.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
    674.   {
    675.       return remove_session_lock(ctx, c, 1);
                      ^
    676.   }
    677.   

ssl/ssl_sess.c:678:1: Parameter `ctx->sessions->num_items`
      676.   }
      677.   
      678. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
      679.   {
      680.       SSL_SESSION *r;

ssl/ssl_sess.c:688:17: Call
      686.           if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
      687.               ret = 1;
      688.               r = lh_SSL_SESSION_delete(ctx->sessions, c);
                             ^
      689.               SSL_SESSION_list_remove(ctx, c);
      690.           }

crypto/lhash/lhash.c:213:1: <LHS trace>
211.   }
212.   
213. > void *lh_delete(_LHASH *lh, const void *data)
214.   {
215.       unsigned long hash;

crypto/lhash/lhash.c:213:1: Parameter `lh->num_items`
        211.   }
        212.   
        213. > void *lh_delete(_LHASH *lh, const void *data)
        214.   {
        215.       unsigned long hash;

crypto/lhash/lhash.c:233:5: Binary operation: ([0, max(0, s->ctx->sessions->num_items)] - 1):unsigned64 by call to `ssl3_send_alert` 
        231.       }
        232.   
        233.       lh->num_items--;
                   ^
        234.       if ((lh->num_nodes > MIN_NODES) &&
        235.           (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))

void *lh_delete(_LHASH *lh, const void *data)
{
    unsigned long hash;
    LHASH_NODE *nn, **rn;
    void *ret;
    lh->error = 0;
    rn = getrn(lh, data, &hash);
    if (*rn == NULL) {
        lh->num_no_delete++;
        return (NULL);
    } else {
        nn = *rn;
        *rn = nn->next;
        ret = nn->data;
        OPENSSL_free(nn);
        lh->num_delete++;
    }
    lh->num_items--;
    if ((lh->num_nodes > MIN_NODES) &&
        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
        contract(lh);
    return (ret);
}
['int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)\n{\n    int al, i, j, ret;\n    unsigned int n;\n    SSL3_RECORD *rr;\n    void (*cb) (const SSL *ssl, int type2, int val) = NULL;\n    if (s->s3->rbuf.buf == NULL)\n        if (!ssl3_setup_buffers(s))\n            return (-1);\n    if ((type && (type != SSL3_RT_APPLICATION_DATA) &&\n         (type != SSL3_RT_HANDSHAKE)) ||\n        (peek && (type != SSL3_RT_APPLICATION_DATA))) {\n        SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n        return -1;\n    }\n    if ((ret = have_handshake_fragment(s, type, buf, len, peek)))\n        return ret;\n#ifndef OPENSSL_NO_SCTP\n    if ((!s->in_handshake && SSL_in_init(s)) ||\n        (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n         (s->state == DTLS1_SCTP_ST_SR_READ_SOCK\n          || s->state == DTLS1_SCTP_ST_CR_READ_SOCK)\n         && s->s3->in_read_app_data != 2))\n#else\n    if (!s->in_handshake && SSL_in_init(s))\n#endif\n    {\n        i = s->handshake_func(s);\n        if (i < 0)\n            return (i);\n        if (i == 0) {\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n            return (-1);\n        }\n    }\n start:\n    s->rwstate = SSL_NOTHING;\n    rr = &(s->s3->rrec);\n    if (s->state == SSL_ST_OK && rr->length == 0) {\n        pitem *item;\n        item = pqueue_pop(s->d1->buffered_app_data.q);\n        if (item) {\n#ifndef OPENSSL_NO_SCTP\n            if (BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n                DTLS1_RECORD_DATA *rdata = (DTLS1_RECORD_DATA *)item->data;\n                BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SCTP_SET_RCVINFO,\n                         sizeof(rdata->recordinfo), &rdata->recordinfo);\n            }\n#endif\n            dtls1_copy_record(s, item);\n            OPENSSL_free(item->data);\n            pitem_free(item);\n        }\n    }\n    if (dtls1_handle_timeout(s) > 0)\n        goto start;\n    if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) {\n        ret = dtls1_get_record(s);\n        if (ret <= 0) {\n            ret = dtls1_read_failed(s, ret);\n            if (ret <= 0)\n                return (ret);\n            else\n                goto start;\n        }\n    }\n    if (s->d1->listen && rr->type != SSL3_RT_HANDSHAKE) {\n        rr->length = 0;\n        goto start;\n    }\n    if (s->s3->change_cipher_spec\n        && (rr->type != SSL3_RT_HANDSHAKE)) {\n        if (dtls1_buffer_record(s, &(s->d1->buffered_app_data), rr->seq_num) <\n            0) {\n            SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n            return -1;\n        }\n        rr->length = 0;\n        goto start;\n    }\n    if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {\n        rr->length = 0;\n        s->rwstate = SSL_NOTHING;\n        return (0);\n    }\n    if (type == rr->type) {\n        if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&\n            (s->enc_read_ctx == NULL)) {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_APP_DATA_IN_HANDSHAKE);\n            goto f_err;\n        }\n        if (len <= 0)\n            return (len);\n        if ((unsigned int)len > rr->length)\n            n = rr->length;\n        else\n            n = (unsigned int)len;\n        memcpy(buf, &(rr->data[rr->off]), n);\n        if (!peek) {\n            rr->length -= n;\n            rr->off += n;\n            if (rr->length == 0) {\n                s->rstate = SSL_ST_READ_HEADER;\n                rr->off = 0;\n            }\n        }\n#ifndef OPENSSL_NO_SCTP\n        if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n            rr->type == SSL3_RT_APPLICATION_DATA &&\n            (s->state == DTLS1_SCTP_ST_SR_READ_SOCK\n             || s->state == DTLS1_SCTP_ST_CR_READ_SOCK)) {\n            s->rwstate = SSL_READING;\n            BIO_clear_retry_flags(SSL_get_rbio(s));\n            BIO_set_retry_read(SSL_get_rbio(s));\n        }\n        if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n            s->d1->shutdown_received\n            && !BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n            s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n            return (0);\n        }\n#endif\n        return (n);\n    }\n    {\n        unsigned int k, dest_maxlen = 0;\n        unsigned char *dest = NULL;\n        unsigned int *dest_len = NULL;\n        if (rr->type == SSL3_RT_HANDSHAKE) {\n            dest_maxlen = sizeof s->d1->handshake_fragment;\n            dest = s->d1->handshake_fragment;\n            dest_len = &s->d1->handshake_fragment_len;\n        } else if (rr->type == SSL3_RT_ALERT) {\n            dest_maxlen = sizeof(s->d1->alert_fragment);\n            dest = s->d1->alert_fragment;\n            dest_len = &s->d1->alert_fragment_len;\n        }\n#ifndef OPENSSL_NO_HEARTBEATS\n        else if (rr->type == TLS1_RT_HEARTBEAT) {\n            dtls1_process_heartbeat(s);\n            rr->length = 0;\n            s->rwstate = SSL_READING;\n            BIO_clear_retry_flags(SSL_get_rbio(s));\n            BIO_set_retry_read(SSL_get_rbio(s));\n            return (-1);\n        }\n#endif\n        else if (rr->type != SSL3_RT_CHANGE_CIPHER_SPEC) {\n            if (rr->type == SSL3_RT_APPLICATION_DATA) {\n                BIO *bio;\n                s->s3->in_read_app_data = 2;\n                bio = SSL_get_rbio(s);\n                s->rwstate = SSL_READING;\n                BIO_clear_retry_flags(bio);\n                BIO_set_retry_read(bio);\n                return (-1);\n            }\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n            goto f_err;\n        }\n        if (dest_maxlen > 0) {\n            if (rr->length < dest_maxlen) {\n#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE\n                FIX ME\n#endif\n                 s->rstate = SSL_ST_READ_HEADER;\n                rr->length = 0;\n                goto start;\n            }\n            for (k = 0; k < dest_maxlen; k++) {\n                dest[k] = rr->data[rr->off++];\n                rr->length--;\n            }\n            *dest_len = dest_maxlen;\n        }\n    }\n    if ((!s->server) &&\n        (s->d1->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n        (s->d1->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) &&\n        (s->session != NULL) && (s->session->cipher != NULL)) {\n        s->d1->handshake_fragment_len = 0;\n        if ((s->d1->handshake_fragment[1] != 0) ||\n            (s->d1->handshake_fragment[2] != 0) ||\n            (s->d1->handshake_fragment[3] != 0)) {\n            al = SSL_AD_DECODE_ERROR;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_BAD_HELLO_REQUEST);\n            goto err;\n        }\n        if (s->msg_callback)\n            s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n                            s->d1->handshake_fragment, 4, s,\n                            s->msg_callback_arg);\n        if (SSL_is_init_finished(s) &&\n            !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&\n            !s->s3->renegotiate) {\n            s->d1->handshake_read_seq++;\n            s->new_session = 1;\n            ssl3_renegotiate(s);\n            if (ssl3_renegotiate_check(s)) {\n                i = s->handshake_func(s);\n                if (i < 0)\n                    return (i);\n                if (i == 0) {\n                    SSLerr(SSL_F_DTLS1_READ_BYTES,\n                           SSL_R_SSL_HANDSHAKE_FAILURE);\n                    return (-1);\n                }\n                if (!(s->mode & SSL_MODE_AUTO_RETRY)) {\n                    if (s->s3->rbuf.left == 0) {\n                        BIO *bio;\n                        s->rwstate = SSL_READING;\n                        bio = SSL_get_rbio(s);\n                        BIO_clear_retry_flags(bio);\n                        BIO_set_retry_read(bio);\n                        return (-1);\n                    }\n                }\n            }\n        }\n        goto start;\n    }\n    if (s->d1->alert_fragment_len >= DTLS1_AL_HEADER_LENGTH) {\n        int alert_level = s->d1->alert_fragment[0];\n        int alert_descr = s->d1->alert_fragment[1];\n        s->d1->alert_fragment_len = 0;\n        if (s->msg_callback)\n            s->msg_callback(0, s->version, SSL3_RT_ALERT,\n                            s->d1->alert_fragment, 2, s, s->msg_callback_arg);\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 (cb != NULL) {\n            j = (alert_level << 8) | alert_descr;\n            cb(s, SSL_CB_READ_ALERT, j);\n        }\n        if (alert_level == 1) {\n            s->s3->warn_alert = alert_descr;\n            if (alert_descr == SSL_AD_CLOSE_NOTIFY) {\n#ifndef OPENSSL_NO_SCTP\n                if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n                    BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n                    s->d1->shutdown_received = 1;\n                    s->rwstate = SSL_READING;\n                    BIO_clear_retry_flags(SSL_get_rbio(s));\n                    BIO_set_retry_read(SSL_get_rbio(s));\n                    return -1;\n                }\n#endif\n                s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n                return (0);\n            }\n#if 0\n            if (alert_descr == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) {\n                unsigned short seq;\n                unsigned int frag_off;\n                unsigned char *p = &(s->d1->alert_fragment[2]);\n                n2s(p, seq);\n                n2l3(p, frag_off);\n                dtls1_retransmit_message(s,\n                                         dtls1_get_queue_priority\n                                         (frag->msg_header.seq, 0), frag_off,\n                                         &found);\n                if (!found && SSL_in_init(s)) {\n                    ssl3_send_alert(s, SSL3_AL_WARNING,\n                                    DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);\n                }\n            }\n#endif\n        } else if (alert_level == 2) {\n            char tmp[16];\n            s->rwstate = SSL_NOTHING;\n            s->s3->fatal_alert = alert_descr;\n            SSLerr(SSL_F_DTLS1_READ_BYTES,\n                   SSL_AD_REASON_OFFSET + alert_descr);\n            BIO_snprintf(tmp, sizeof tmp, "%d", alert_descr);\n            ERR_add_error_data(2, "SSL alert number ", tmp);\n            s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n            SSL_CTX_remove_session(s->ctx, s->session);\n            return (0);\n        } else {\n            al = SSL_AD_ILLEGAL_PARAMETER;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNKNOWN_ALERT_TYPE);\n            goto f_err;\n        }\n        goto start;\n    }\n    if (s->shutdown & SSL_SENT_SHUTDOWN) {\n        s->rwstate = SSL_NOTHING;\n        rr->length = 0;\n        return (0);\n    }\n    if (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC) {\n        struct ccs_header_st ccs_hdr;\n        unsigned int ccs_hdr_len = DTLS1_CCS_HEADER_LENGTH;\n        dtls1_get_ccs_header(rr->data, &ccs_hdr);\n        if (s->version == DTLS1_BAD_VER)\n            ccs_hdr_len = 3;\n        if ((rr->length != ccs_hdr_len) ||\n            (rr->off != 0) || (rr->data[0] != SSL3_MT_CCS)) {\n            i = SSL_AD_ILLEGAL_PARAMETER;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_BAD_CHANGE_CIPHER_SPEC);\n            goto err;\n        }\n        rr->length = 0;\n        if (s->msg_callback)\n            s->msg_callback(0, s->version, SSL3_RT_CHANGE_CIPHER_SPEC,\n                            rr->data, 1, s, s->msg_callback_arg);\n        if (!s->d1->change_cipher_spec_ok) {\n            goto start;\n        }\n        s->d1->change_cipher_spec_ok = 0;\n        s->s3->change_cipher_spec = 1;\n        if (!ssl3_do_change_cipher_spec(s))\n            goto err;\n        dtls1_reset_seq_numbers(s, SSL3_CC_READ);\n        if (s->version == DTLS1_BAD_VER)\n            s->d1->handshake_read_seq++;\n#ifndef OPENSSL_NO_SCTP\n        BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD, 1, NULL);\n#endif\n        goto start;\n    }\n    if ((s->d1->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n        !s->in_handshake) {\n        struct hm_header_st msg_hdr;\n        dtls1_get_message_header(rr->data, &msg_hdr);\n        if (rr->epoch != s->d1->r_epoch) {\n            rr->length = 0;\n            goto start;\n        }\n        if (msg_hdr.type == SSL3_MT_FINISHED) {\n            if (dtls1_check_timeout_num(s) < 0)\n                return -1;\n            dtls1_retransmit_buffered_messages(s);\n            rr->length = 0;\n            goto start;\n        }\n        if (((s->state & SSL_ST_MASK) == SSL_ST_OK) &&\n            !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) {\n#if 0\n            s->state = SSL_ST_BEFORE | (s->server)\n                ? SSL_ST_ACCEPT : SSL_ST_CONNECT;\n#else\n            s->state = s->server ? SSL_ST_ACCEPT : SSL_ST_CONNECT;\n#endif\n            s->renegotiate = 1;\n            s->new_session = 1;\n        }\n        i = s->handshake_func(s);\n        if (i < 0)\n            return (i);\n        if (i == 0) {\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n            return (-1);\n        }\n        if (!(s->mode & SSL_MODE_AUTO_RETRY)) {\n            if (s->s3->rbuf.left == 0) {\n                BIO *bio;\n                s->rwstate = SSL_READING;\n                bio = SSL_get_rbio(s);\n                BIO_clear_retry_flags(bio);\n                BIO_set_retry_read(bio);\n                return (-1);\n            }\n        }\n        goto start;\n    }\n    switch (rr->type) {\n    default:\n#ifndef OPENSSL_NO_TLS\n        if (s->version == TLS1_VERSION) {\n            rr->length = 0;\n            goto start;\n        }\n#endif\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n        goto f_err;\n    case SSL3_RT_CHANGE_CIPHER_SPEC:\n    case SSL3_RT_ALERT:\n    case SSL3_RT_HANDSHAKE:\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n        goto f_err;\n    case SSL3_RT_APPLICATION_DATA:\n        if (s->s3->in_read_app_data &&\n            (s->s3->total_renegotiations != 0) &&\n            (((s->state & SSL_ST_CONNECT) &&\n              (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&\n              (s->state <= SSL3_ST_CR_SRVR_HELLO_A)\n             ) || ((s->state & SSL_ST_ACCEPT) &&\n                   (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&\n                   (s->state >= SSL3_ST_SR_CLNT_HELLO_A)\n             )\n            )) {\n            s->s3->in_read_app_data = 2;\n            return (-1);\n        } else {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n            goto f_err;\n        }\n    }\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n    return (-1);\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n    desc = s->method->ssl3_enc->alert_value(desc);\n    if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n        desc = SSL_AD_HANDSHAKE_FAILURE;\n    if (desc < 0)\n        return -1;\n    if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n        SSL_CTX_remove_session(s->ctx, s->session);\n    s->s3->alert_dispatch = 1;\n    s->s3->send_alert[0] = level;\n    s->s3->send_alert[1] = desc;\n    if (s->s3->wbuf.left == 0)\n        return s->method->ssl_dispatch_alert(s);\n    return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n    return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n    SSL_SESSION *r;\n    int ret = 0;\n    if ((c != NULL) && (c->session_id_length != 0)) {\n        if (lck)\n            CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n        if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n            ret = 1;\n            r = lh_SSL_SESSION_delete(ctx->sessions, c);\n            SSL_SESSION_list_remove(ctx, c);\n        }\n        if (lck)\n            CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n        if (ret) {\n            r->not_resumable = 1;\n            if (ctx->remove_session_cb != NULL)\n                ctx->remove_session_cb(ctx, r);\n            SSL_SESSION_free(r);\n        }\n    } else\n        ret = 0;\n    return (ret);\n}', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    LHASH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        lh->num_no_delete++;\n        return (NULL);\n    } else {\n        nn = *rn;\n        *rn = nn->next;\n        ret = nn->data;\n        OPENSSL_free(nn);\n        lh->num_delete++;\n    }\n    lh->num_items--;\n    if ((lh->num_nodes > MIN_NODES) &&\n        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n        contract(lh);\n    return (ret);\n}']