ssl/record/rec_layer_d1.c:864: error: INTEGER_OVERFLOW_L2
  ([0, max(0, `s->session_ctx->sessions->num_items`)] - 1):unsigned64 by call to `ssl3_send_alert`.
Showing all 13 steps of the trace


ssl/record/rec_layer_d1.c:339:1: Parameter `s->session_ctx->sessions->num_items`
337.    *             none of our business
338.    */
339. > int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
340.                        size_t len, int peek, size_t *readbytes)
341.   {

ssl/record/rec_layer_d1.c:864:5: Call
862.   
863.    f_err:
864.       ssl3_send_alert(s, SSL3_AL_FATAL, al);
           ^
865.       return -1;
866.   }

ssl/s3_msg.c:63:1: Parameter `s->session_ctx->sessions->num_items`
  61.   }
  62.   
  63. > int ssl3_send_alert(SSL *s, int level, int desc)
  64.   {
  65.       /* Map tls/ssl alert value to correct one */

ssl/s3_msg.c:74:9: Call
  72.       /* If a fatal one, remove from cache */
  73.       if ((level == SSL3_AL_FATAL) && (s->session != NULL))
  74.           SSL_CTX_remove_session(s->session_ctx, s->session);
                ^
  75.   
  76.       s->s3->alert_dispatch = 1;

ssl/ssl_sess.c:725:1: Parameter `ctx->sessions->num_items`
    723.   }
    724.   
    725. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
    726.   {
    727.       return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:727:12: Call
    725.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
    726.   {
    727.       return remove_session_lock(ctx, c, 1);
                      ^
    728.   }
    729.   

ssl/ssl_sess.c:730:1: Parameter `ctx->sessions->num_items`
      728.   }
      729.   
      730. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
      731.   {
      732.       SSL_SESSION *r;

ssl/ssl_sess.c:740:17: Call
      738.           if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
      739.               ret = 1;
      740.               r = lh_SSL_SESSION_delete(ctx->sessions, c);
                             ^
      741.               SSL_SESSION_list_remove(ctx, c);
      742.           }

ssl/ssl_locl.h:626:1: Parameter `lh->num_items`
        624.   };
        625.   
        626. > DEFINE_LHASH_OF(SSL_SESSION);
        627.   /* Needed in ssl_cert.c */
        628.   DEFINE_LHASH_OF(X509_NAME);

ssl/ssl_locl.h:626:1: Call
        624.   };
        625.   
        626. > DEFINE_LHASH_OF(SSL_SESSION);
        627.   /* Needed in ssl_cert.c */
        628.   DEFINE_LHASH_OF(X509_NAME);

crypto/lhash/lhash.c:103:1: <LHS trace>
101.   }
102.   
103. > void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
104.   {
105.       unsigned long hash;

crypto/lhash/lhash.c:103:1: Parameter `lh->num_items`
          101.   }
          102.   
          103. > void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
          104.   {
          105.       unsigned long hash;

crypto/lhash/lhash.c:123:5: Binary operation: ([0, max(0, s->session_ctx->sessions->num_items)] - 1):unsigned64 by call to `ssl3_send_alert` 
          121.       }
          122.   
          123.       lh->num_items--;
                     ^
          124.       if ((lh->num_nodes > MIN_NODES) &&
          125.           (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))

void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
    unsigned long hash;
    OPENSSL_LH_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, int *recvd_type, unsigned char *buf,\n                     size_t len, int peek, size_t *readbytes)\n{\n    int al, i, j, iret;\n    size_t ret, n;\n    SSL3_RECORD *rr;\n    void (*cb) (const SSL *ssl, int type2, int val) = NULL;\n    if (!SSL3_BUFFER_is_initialised(&s->rlayer.rbuf)) {\n        if (!ssl3_setup_buffers(s))\n            return (-1);\n    }\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    ret = have_handshake_fragment(s, type, buf, len);\n    if (ret > 0) {\n        *recvd_type = SSL3_RT_HANDSHAKE;\n        *readbytes = ret;\n        return 1;\n    }\n#ifndef OPENSSL_NO_SCTP\n    if ((!ossl_statem_get_in_handshake(s) && SSL_in_init(s)) ||\n        (BIO_dgram_is_sctp(SSL_get_rbio(s))\n         && ossl_statem_in_sctp_read_sock(s)\n         && s->s3->in_read_app_data != 2))\n#else\n    if (!ossl_statem_get_in_handshake(s) && 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->rlayer.rrec;\n    if (SSL_is_init_finished(s) && SSL3_RECORD_get_length(rr) == 0) {\n        pitem *item;\n        item = pqueue_pop(s->rlayer.d->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 ((SSL3_RECORD_get_length(rr) == 0)\n        || (s->rlayer.rstate == SSL_ST_READ_BODY)) {\n        iret = dtls1_get_record(s);\n        if (iret <= 0) {\n            iret = dtls1_read_failed(s, iret);\n            if (iret <= 0)\n                return iret;\n            else\n                goto start;\n        }\n    }\n    if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT\n            && SSL3_RECORD_get_length(rr) != 0)\n        s->rlayer.alert_count = 0;\n    if (s->s3->change_cipher_spec\n        && (SSL3_RECORD_get_type(rr) != SSL3_RT_HANDSHAKE)) {\n        if (dtls1_buffer_record(s, &(s->rlayer.d->buffered_app_data),\n                                SSL3_RECORD_get_seq_num(rr)) < 0) {\n            SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n            return -1;\n        }\n        SSL3_RECORD_set_length(rr, 0);\n        goto start;\n    }\n    if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {\n        SSL3_RECORD_set_length(rr, 0);\n        s->rwstate = SSL_NOTHING;\n        return 0;\n    }\n    if (type == SSL3_RECORD_get_type(rr)\n        || (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC\n            && type == SSL3_RT_HANDSHAKE && recvd_type != NULL)) {\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 (recvd_type != NULL)\n            *recvd_type = SSL3_RECORD_get_type(rr);\n        if (len == 0)\n            return 0;\n        if (len > SSL3_RECORD_get_length(rr))\n            n = SSL3_RECORD_get_length(rr);\n        else\n            n = len;\n        memcpy(buf, &(SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)]), n);\n        if (!peek) {\n            SSL3_RECORD_sub_length(rr, n);\n            SSL3_RECORD_add_off(rr, n);\n            if (SSL3_RECORD_get_length(rr) == 0) {\n                s->rlayer.rstate = SSL_ST_READ_HEADER;\n                SSL3_RECORD_set_off(rr, 0);\n            }\n        }\n#ifndef OPENSSL_NO_SCTP\n        if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n            SSL3_RECORD_get_type(rr) == SSL3_RT_APPLICATION_DATA &&\n            ossl_statem_in_sctp_read_sock(s)) {\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        *readbytes = n;\n        return 1;\n    }\n    {\n        size_t k, dest_maxlen = 0;\n        unsigned char *dest = NULL;\n        size_t *dest_len = NULL;\n        if (SSL3_RECORD_get_type(rr) == SSL3_RT_HANDSHAKE) {\n            dest_maxlen = sizeof s->rlayer.d->handshake_fragment;\n            dest = s->rlayer.d->handshake_fragment;\n            dest_len = &s->rlayer.d->handshake_fragment_len;\n        } else if (SSL3_RECORD_get_type(rr) == SSL3_RT_ALERT) {\n            dest_maxlen = sizeof(s->rlayer.d->alert_fragment);\n            dest = s->rlayer.d->alert_fragment;\n            dest_len = &s->rlayer.d->alert_fragment_len;\n        }\n        else if (SSL3_RECORD_get_type(rr) != SSL3_RT_CHANGE_CIPHER_SPEC) {\n            if (SSL3_RECORD_get_type(rr) == 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 (SSL3_RECORD_get_length(rr) < dest_maxlen) {\n#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE\n                FIX ME;\n#endif\n                s->rlayer.rstate = SSL_ST_READ_HEADER;\n                SSL3_RECORD_set_length(rr, 0);\n                goto start;\n            }\n            for (k = 0; k < dest_maxlen; k++) {\n                dest[k] = SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)];\n                SSL3_RECORD_add_off(rr, 1);\n                SSL3_RECORD_add_length(rr, -1);\n            }\n            *dest_len = dest_maxlen;\n        }\n    }\n    if (s->rlayer.d->alert_fragment_len >= DTLS1_AL_HEADER_LENGTH) {\n        int alert_level = s->rlayer.d->alert_fragment[0];\n        int alert_descr = s->rlayer.d->alert_fragment[1];\n        s->rlayer.d->alert_fragment_len = 0;\n        if (s->msg_callback)\n            s->msg_callback(0, s->version, SSL3_RT_ALERT,\n                            s->rlayer.d->alert_fragment, 2, s,\n                            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 == SSL3_AL_WARNING) {\n            s->s3->warn_alert = alert_descr;\n            s->rlayer.alert_count++;\n            if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {\n                al = SSL_AD_UNEXPECTED_MESSAGE;\n                SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_TOO_MANY_WARN_ALERTS);\n                goto f_err;\n            }\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->rlayer.d->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 == SSL3_AL_FATAL) {\n            char tmp[16];\n            s->rwstate = SSL_NOTHING;\n            s->s3->fatal_alert = alert_descr;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, 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->session_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        SSL3_RECORD_set_length(rr, 0);\n        return 0;\n    }\n    if (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC) {\n        SSL3_RECORD_set_length(rr, 0);\n        goto start;\n    }\n    if ((s->rlayer.d->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n        !ossl_statem_get_in_handshake(s)) {\n        struct hm_header_st msg_hdr;\n        dtls1_get_message_header(rr->data, &msg_hdr);\n        if (SSL3_RECORD_get_epoch(rr) != s->rlayer.d->r_epoch) {\n            SSL3_RECORD_set_length(rr, 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            SSL3_RECORD_set_length(rr, 0);\n            goto start;\n        }\n        assert(SSL_is_init_finished(s));\n        if (!SSL_is_init_finished(s)) {\n            al = SSL_AD_INTERNAL_ERROR;\n            SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n            goto f_err;\n        }\n        ossl_statem_set_in_init(s, 1);\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 (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 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 (SSL3_RECORD_get_type(rr)) {\n    default:\n        if (s->version == TLS1_VERSION) {\n            SSL3_RECORD_set_length(rr, 0);\n            goto start;\n        }\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            ossl_statem_app_data_allowed(s)) {\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    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->session_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 (!RECORD_LAYER_write_pending(&s->rlayer)) {\n        return s->method->ssl_dispatch_alert(s);\n    }\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_THREAD_write_lock(ctx->lock);\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        c->not_resumable = 1;\n        if (lck)\n            CRYPTO_THREAD_unlock(ctx->lock);\n        if (ret)\n            SSL_SESSION_free(r);\n        if (ctx->remove_session_cb != NULL)\n            ctx->remove_session_cb(ctx, c);\n    } else\n        ret = 0;\n    return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_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}']