ssl/statem/statem.c:317: error: INTEGER_OVERFLOW_L2
  ([0, max(0, `s->session_ctx->sessions->num_items`)] - 1):unsigned64 by call to `tls_setup_handshake`.
Showing all 15 steps of the trace


ssl/statem/statem.c:218:1: Parameter `s->session_ctx->sessions->num_items`
216.    * <=0: NBIO or error
217.    */
218. > static int state_machine(SSL *s, int server)
219.   {
220.       BUF_MEM *buf = NULL;

ssl/statem/statem.c:317:18: Call
315.   
316.           if (SSL_IS_FIRST_HANDSHAKE(s) || s->renegotiate) {
317.               if (!tls_setup_handshake(s)) {
                        ^
318.                   ossl_statem_set_error(s);
319.                   goto end;

ssl/statem/statem_lib.c:75:1: Parameter `s->session_ctx->sessions->num_items`
  73.   }
  74.   
  75. > int tls_setup_handshake(SSL *s)
  76.   {
  77.       if (!ssl3_init_finished_mac(s))

ssl/statem/statem_lib.c:92:13: Call
  90.               SSLerr(SSL_F_TLS_SETUP_HANDSHAKE,
  91.                      SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
  92.               ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
                    ^
  93.               return 0;
  94.           } else {

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 `tls_setup_handshake` 
            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);
}
['static int state_machine(SSL *s, int server)\n{\n    BUF_MEM *buf = NULL;\n    unsigned long Time = (unsigned long)time(NULL);\n    void (*cb) (const SSL *ssl, int type, int val) = NULL;\n    OSSL_STATEM *st = &s->statem;\n    int ret = -1;\n    int ssret;\n    if (st->state == MSG_FLOW_ERROR) {\n        return -1;\n    }\n    RAND_add(&Time, sizeof(Time), 0);\n    ERR_clear_error();\n    clear_sys_error();\n    cb = get_callback(s);\n    st->in_handshake++;\n    if (!SSL_in_init(s) || SSL_in_before(s)) {\n        if (!SSL_clear(s))\n            return -1;\n    }\n#ifndef OPENSSL_NO_SCTP\n    if (SSL_IS_DTLS(s)) {\n        BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n                 st->in_handshake, NULL);\n    }\n#endif\n    if (st->state == MSG_FLOW_UNINITED\n            || st->state == MSG_FLOW_FINISHED) {\n        if (st->state == MSG_FLOW_UNINITED) {\n            st->hand_state = TLS_ST_BEFORE;\n            st->request_state = TLS_ST_BEFORE;\n        }\n        s->server = server;\n        if (cb != NULL)\n            cb(s, SSL_CB_HANDSHAKE_START, 1);\n        if (SSL_IS_DTLS(s)) {\n            if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00) &&\n                (server || (s->version & 0xff00) != (DTLS1_BAD_VER & 0xff00))) {\n                SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n                goto end;\n            }\n        } else {\n            if ((s->version >> 8) != SSL3_VERSION_MAJOR) {\n                SSLerr(SSL_F_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n                goto end;\n            }\n        }\n        if (!ssl_security(s, SSL_SECOP_VERSION, 0, s->version, NULL)) {\n            SSLerr(SSL_F_STATE_MACHINE, SSL_R_VERSION_TOO_LOW);\n            goto end;\n        }\n        if (s->init_buf == NULL) {\n            if ((buf = BUF_MEM_new()) == NULL) {\n                goto end;\n            }\n            if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {\n                goto end;\n            }\n            s->init_buf = buf;\n            buf = NULL;\n        }\n        if (!ssl3_setup_buffers(s)) {\n            goto end;\n        }\n        s->init_num = 0;\n        s->s3->change_cipher_spec = 0;\n#ifndef OPENSSL_NO_SCTP\n        if (!SSL_IS_DTLS(s) || !BIO_dgram_is_sctp(SSL_get_wbio(s)))\n#endif\n            if (!ssl_init_wbio_buffer(s)) {\n                goto end;\n            }\n        if (SSL_IS_FIRST_HANDSHAKE(s) || s->renegotiate) {\n            if (!tls_setup_handshake(s)) {\n                ossl_statem_set_error(s);\n                goto end;\n            }\n            if (SSL_IS_FIRST_HANDSHAKE(s))\n                st->read_state_first_init = 1;\n        }\n        st->state = MSG_FLOW_WRITING;\n        init_write_state_machine(s);\n    }\n    while (st->state != MSG_FLOW_FINISHED) {\n        if (st->state == MSG_FLOW_READING) {\n            ssret = read_state_machine(s);\n            if (ssret == SUB_STATE_FINISHED) {\n                st->state = MSG_FLOW_WRITING;\n                init_write_state_machine(s);\n            } else {\n                goto end;\n            }\n        } else if (st->state == MSG_FLOW_WRITING) {\n            ssret = write_state_machine(s);\n            if (ssret == SUB_STATE_FINISHED) {\n                st->state = MSG_FLOW_READING;\n                init_read_state_machine(s);\n            } else if (ssret == SUB_STATE_END_HANDSHAKE) {\n                st->state = MSG_FLOW_FINISHED;\n            } else {\n                goto end;\n            }\n        } else {\n            ossl_statem_set_error(s);\n            goto end;\n        }\n    }\n    ret = 1;\n end:\n    st->in_handshake--;\n#ifndef OPENSSL_NO_SCTP\n    if (SSL_IS_DTLS(s)) {\n        BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE,\n                 st->in_handshake, NULL);\n    }\n#endif\n    BUF_MEM_free(buf);\n    if (cb != NULL) {\n        if (server)\n            cb(s, SSL_CB_ACCEPT_EXIT, ret);\n        else\n            cb(s, SSL_CB_CONNECT_EXIT, ret);\n    }\n    return ret;\n}', 'int tls_setup_handshake(SSL *s)\n{\n    if (!ssl3_init_finished_mac(s))\n        return 0;\n    if (s->server) {\n        if (SSL_IS_FIRST_HANDSHAKE(s)) {\n            s->ctx->stats.sess_accept++;\n        } else if (!s->s3->send_connection_binding &&\n                   !(s->options &\n                     SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)) {\n            SSLerr(SSL_F_TLS_SETUP_HANDSHAKE,\n                   SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);\n            ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n            return 0;\n        } else {\n            s->ctx->stats.sess_accept_renegotiate++;\n            s->s3->tmp.cert_request = 0;\n        }\n    } else {\n        if (SSL_IS_FIRST_HANDSHAKE(s))\n            s->ctx->stats.sess_connect++;\n        else\n            s->ctx->stats.sess_connect_renegotiate++;\n        memset(s->s3->client_random, 0, sizeof(s->s3->client_random));\n        s->hit = 0;\n        s->s3->tmp.cert_req = 0;\n        if (SSL_IS_DTLS(s))\n            s->statem.use_timer = 1;\n    }\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}']