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


ssl/statem/statem_dtls.c:810:1: Parameter `s->ctx->sessions->num_items`
808.   }
809.   
810. > static int dtls_get_reassembled_message(SSL *s, long *len)
811.   {
812.       unsigned char wire[DTLS1_HM_HEADER_LENGTH];

ssl/statem/statem_dtls.c:820:21: Call
818.    redo:
819.       /* see if we have the required fragment already */
820.       if ((frag_len = dtls1_retrieve_buffered_fragment(s, &ok)) || ok) {
                           ^
821.           if (ok)
822.               s->init_num = frag_len;

ssl/statem/statem_dtls.c:542:1: Parameter `s->ctx->sessions->num_items`
  540.   }
  541.   
  542. > static int dtls1_retrieve_buffered_fragment(SSL *s, int *ok)
  543.   {
  544.       /*-

ssl/statem/statem_dtls.c:586:9: Call
  584.           }
  585.   
  586.           ssl3_send_alert(s, SSL3_AL_FATAL, al);
                 ^
  587.           s->init_num = 0;
  588.           *ok = 0;

ssl/s3_msg.c:166:1: Parameter `s->ctx->sessions->num_items`
    164.   }
    165.   
    166. > int ssl3_send_alert(SSL *s, int level, int desc)
    167.   {
    168.       /* Map tls/ssl alert value to correct one */

ssl/s3_msg.c:177:9: Call
    175.       /* If a fatal one, remove from cache */
    176.       if ((level == SSL3_AL_FATAL) && (s->session != NULL))
    177.           SSL_CTX_remove_session(s->ctx, s->session);
                   ^
    178.   
    179.       s->s3->alert_dispatch = 1;

ssl/ssl_sess.c:785:1: Parameter `ctx->sessions->num_items`
      783.   }
      784.   
      785. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
      786.   {
      787.       return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:787:12: Call
      785.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
      786.   {
      787.       return remove_session_lock(ctx, c, 1);
                        ^
      788.   }
      789.   

ssl/ssl_sess.c:790:1: Parameter `ctx->sessions->num_items`
        788.   }
        789.   
        790. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
        791.   {
        792.       SSL_SESSION *r;

ssl/ssl_sess.c:800:17: Call
        798.           if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
        799.               ret = 1;
        800.               r = lh_SSL_SESSION_delete(ctx->sessions, c);
                               ^
        801.               SSL_SESSION_list_remove(ctx, c);
        802.           }

ssl/ssl_locl.h:694:1: Parameter `lh->num_items`
          692.   };
          693.   
          694. > DEFINE_LHASH_OF(SSL_SESSION);
          695.   
          696.   

ssl/ssl_locl.h:694:1: Call
          692.   };
          693.   
          694. > DEFINE_LHASH_OF(SSL_SESSION);
          695.   
          696.   

crypto/lhash/lhash.c:189:1: <LHS trace>
187.   }
188.   
189. > void *lh_delete(_LHASH *lh, const void *data)
190.   {
191.       unsigned long hash;

crypto/lhash/lhash.c:189:1: Parameter `lh->num_items`
            187.   }
            188.   
            189. > void *lh_delete(_LHASH *lh, const void *data)
            190.   {
            191.       unsigned long hash;

crypto/lhash/lhash.c:209:5: Binary operation: ([0, max(0, s->ctx->sessions->num_items)] - 1):unsigned64 by call to `dtls1_retrieve_buffered_fragment` 
            207.       }
            208.   
            209.       lh->num_items--;
                       ^
            210.       if ((lh->num_nodes > MIN_NODES) &&
            211.           (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);
}
['static int dtls_get_reassembled_message(SSL *s, long *len)\n{\n    unsigned char wire[DTLS1_HM_HEADER_LENGTH];\n    unsigned long mlen, frag_off, frag_len;\n    int i, al, recvd_type;\n    struct hm_header_st msg_hdr;\n    int ok;\n redo:\n    if ((frag_len = dtls1_retrieve_buffered_fragment(s, &ok)) || ok) {\n        if (ok)\n            s->init_num = frag_len;\n        *len = frag_len;\n        return ok;\n    }\n    i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, &recvd_type, wire,\n                                  DTLS1_HM_HEADER_LENGTH, 0);\n    if (i <= 0) {\n        s->rwstate = SSL_READING;\n        *len = i;\n        return 0;\n    }\n    if(recvd_type == SSL3_RT_CHANGE_CIPHER_SPEC) {\n        if (wire[0] != SSL3_MT_CCS) {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE,\n                   SSL_R_BAD_CHANGE_CIPHER_SPEC);\n            goto f_err;\n        }\n        memcpy(s->init_buf->data, wire, i);\n        s->init_num = i - 1;\n        s->init_msg = s->init_buf->data + 1;\n        s->s3->tmp.message_type = SSL3_MT_CHANGE_CIPHER_SPEC;\n        s->s3->tmp.message_size = i - 1;\n        *len = i - 1;\n        return 1;\n    }\n    if (i != DTLS1_HM_HEADER_LENGTH) {\n        al = SSL_AD_UNEXPECTED_MESSAGE;\n        SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL_R_UNEXPECTED_MESSAGE);\n        goto f_err;\n    }\n    dtls1_get_message_header(wire, &msg_hdr);\n    mlen = msg_hdr.msg_len;\n    frag_off = msg_hdr.frag_off;\n    frag_len = msg_hdr.frag_len;\n    if (frag_len > RECORD_LAYER_get_rrec_length(&s->rlayer)) {\n        al = SSL3_AD_ILLEGAL_PARAMETER;\n        SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL_R_BAD_LENGTH);\n        goto f_err;\n    }\n    if (msg_hdr.seq != s->d1->handshake_read_seq) {\n        *len = dtls1_process_out_of_seq_message(s, &msg_hdr, &ok);\n        return ok;\n    }\n    if (frag_len && frag_len < mlen) {\n        *len = dtls1_reassemble_fragment(s, &msg_hdr, &ok);\n        return ok;\n    }\n    if (!s->server && s->d1->r_msg_hdr.frag_off == 0 &&\n        wire[0] == SSL3_MT_HELLO_REQUEST) {\n        if (wire[1] == 0 && wire[2] == 0 && wire[3] == 0) {\n            if (s->msg_callback)\n                s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n                                wire, DTLS1_HM_HEADER_LENGTH, s,\n                                s->msg_callback_arg);\n            s->init_num = 0;\n            goto redo;\n        } else {\n            al = SSL_AD_UNEXPECTED_MESSAGE;\n            SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE,\n                   SSL_R_UNEXPECTED_MESSAGE);\n            goto f_err;\n        }\n    }\n    if ((al = dtls1_preprocess_fragment(s, &msg_hdr)))\n        goto f_err;\n    if (frag_len > 0) {\n        unsigned char *p =\n            (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n        i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,\n                                      &p[frag_off], frag_len, 0);\n        if (i <= 0) {\n            s->rwstate = SSL_READING;\n            *len = i;\n            return 0;\n        }\n    } else\n        i = 0;\n    if (i != (int)frag_len) {\n        al = SSL3_AD_ILLEGAL_PARAMETER;\n        SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL3_AD_ILLEGAL_PARAMETER);\n        goto f_err;\n    }\n    *len = s->init_num = frag_len;\n    return 1;\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n    s->init_num = 0;\n    *len = -1;\n    return 0;\n}', 'static int dtls1_retrieve_buffered_fragment(SSL *s, int *ok)\n{\n    pitem *item;\n    hm_fragment *frag;\n    int al;\n    *ok = 0;\n    item = pqueue_peek(s->d1->buffered_messages);\n    if (item == NULL)\n        return 0;\n    frag = (hm_fragment *)item->data;\n    if (frag->reassembly != NULL)\n        return 0;\n    if (s->d1->handshake_read_seq == frag->msg_header.seq) {\n        unsigned long frag_len = frag->msg_header.frag_len;\n        pqueue_pop(s->d1->buffered_messages);\n        al = dtls1_preprocess_fragment(s, &frag->msg_header);\n        if (al == 0) {\n            unsigned char *p =\n                (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n            memcpy(&p[frag->msg_header.frag_off], frag->fragment,\n                   frag->msg_header.frag_len);\n        }\n        dtls1_hm_fragment_free(frag);\n        pitem_free(item);\n        if (al == 0) {\n            *ok = 1;\n            return frag_len;\n        }\n        ssl3_send_alert(s, SSL3_AL_FATAL, al);\n        s->init_num = 0;\n        *ok = 0;\n        return -1;\n    } else\n        return 0;\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 (!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_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}', 'DEFINE_LHASH_OF(SSL_SESSION)', '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}']