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


ssl/record/ssl3_record.c:1585:1: Parameter `s->session_ctx->sessions->num_items`
1583.    */
1584.   /* used only by dtls1_read_bytes */
1585. > int dtls1_get_record(SSL *s)
1586.   {
1587.       int ssl_major, ssl_minor;

ssl/record/ssl3_record.c:1603:10: Call
1601.        * This is a non-blocking operation.
1602.        */
1603.       if (!dtls1_process_buffered_records(s))
                 ^
1604.           return -1;
1605.   

ssl/record/rec_layer_d1.c:230:1: Parameter `s->session_ctx->sessions->num_items`
  228.                      &((s)->rlayer.d->unprocessed_rcds))
  229.   
  230. > int dtls1_process_buffered_records(SSL *s)
  231.   {
  232.       pitem *item;

ssl/record/ssl3_record.c:1745:10: Call
1743.       }
1744.   
1745.       if (!dtls1_process_record(s, bitmap)) {
                 ^
1746.           rr->length = 0;
1747.           RECORD_LAYER_reset_packet_length(&s->rlayer); /* dump this record */

ssl/record/ssl3_record.c:1370:1: Parameter `s->session_ctx->sessions->num_items`
  1368.   }
  1369.   
  1370. > int dtls1_process_record(SSL *s, DTLS1_BITMAP *bitmap)
  1371.   {
  1372.       int i, al;

ssl/record/ssl3_record.c:1562:5: Call
  1560.   
  1561.    f_err:
  1562.       ssl3_send_alert(s, SSL3_AL_FATAL, al);
              ^
  1563.    err:
  1564.       return (0);

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:660:1: Parameter `lh->num_items`
          658.   } CLIENTHELLO_MSG;
          659.   
          660. > DEFINE_LHASH_OF(SSL_SESSION);
          661.   /* Needed in ssl_cert.c */
          662.   DEFINE_LHASH_OF(X509_NAME);

ssl/ssl_locl.h:660:1: Call
          658.   } CLIENTHELLO_MSG;
          659.   
          660. > DEFINE_LHASH_OF(SSL_SESSION);
          661.   /* Needed in ssl_cert.c */
          662.   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 `dtls1_process_record` 
            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_get_record(SSL *s)\n{\n    int ssl_major, ssl_minor;\n    int rret;\n    size_t more, n;\n    SSL3_RECORD *rr;\n    unsigned char *p = NULL;\n    unsigned short version;\n    DTLS1_BITMAP *bitmap;\n    unsigned int is_next_epoch;\n    rr = RECORD_LAYER_get_rrec(&s->rlayer);\n again:\n    if (!dtls1_process_buffered_records(s))\n        return -1;\n    if (dtls1_get_processed_record(s))\n        return 1;\n    if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) ||\n        (RECORD_LAYER_get_packet_length(&s->rlayer) < DTLS1_RT_HEADER_LENGTH)) {\n        rret = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH,\n                           SSL3_BUFFER_get_len(&s->rlayer.rbuf), 0, 1, &n);\n        if (rret <= 0)\n            return rret;\n        if (RECORD_LAYER_get_packet_length(&s->rlayer) !=\n            DTLS1_RT_HEADER_LENGTH) {\n            RECORD_LAYER_reset_packet_length(&s->rlayer);\n            goto again;\n        }\n        RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);\n        p = RECORD_LAYER_get_packet(&s->rlayer);\n        if (s->msg_callback)\n            s->msg_callback(0, 0, SSL3_RT_HEADER, p, DTLS1_RT_HEADER_LENGTH,\n                            s, s->msg_callback_arg);\n        rr->type = *(p++);\n        ssl_major = *(p++);\n        ssl_minor = *(p++);\n        version = (ssl_major << 8) | ssl_minor;\n        n2s(p, rr->epoch);\n        memcpy(&(RECORD_LAYER_get_read_sequence(&s->rlayer)[2]), p, 6);\n        p += 6;\n        n2s(p, rr->length);\n        if (!s->first_packet) {\n            if (version != s->version) {\n                rr->length = 0;\n                RECORD_LAYER_reset_packet_length(&s->rlayer);\n                goto again;\n            }\n        }\n        if ((version & 0xff00) != (s->version & 0xff00)) {\n            rr->length = 0;\n            RECORD_LAYER_reset_packet_length(&s->rlayer);\n            goto again;\n        }\n        if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n            rr->length = 0;\n            RECORD_LAYER_reset_packet_length(&s->rlayer);\n            goto again;\n        }\n    }\n    if (rr->length >\n        RECORD_LAYER_get_packet_length(&s->rlayer) - DTLS1_RT_HEADER_LENGTH) {\n        more = rr->length;\n        rret = ssl3_read_n(s, more, more, 1, 1, &n);\n        if (rret <= 0 || n != more) {\n            rr->length = 0;\n            RECORD_LAYER_reset_packet_length(&s->rlayer);\n            goto again;\n        }\n    }\n    RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER);\n    bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);\n    if (bitmap == NULL) {\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto again;\n    }\n#ifndef OPENSSL_NO_SCTP\n    if (!BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n#endif\n        if (!dtls1_record_replay_check(s, bitmap)) {\n            rr->length = 0;\n            RECORD_LAYER_reset_packet_length(&s->rlayer);\n            goto again;\n        }\n#ifndef OPENSSL_NO_SCTP\n    }\n#endif\n    if (rr->length == 0)\n        goto again;\n    if (is_next_epoch) {\n        if ((SSL_in_init(s) || ossl_statem_get_in_handshake(s))) {\n            if (dtls1_buffer_record\n                (s, &(DTLS_RECORD_LAYER_get_unprocessed_rcds(&s->rlayer)),\n                 rr->seq_num) < 0)\n                return -1;\n        }\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto again;\n    }\n    if (!dtls1_process_record(s, bitmap)) {\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto again;\n    }\n    return (1);\n}', 'int dtls1_process_buffered_records(SSL *s)\n{\n    pitem *item;\n    SSL3_BUFFER *rb;\n    SSL3_RECORD *rr;\n    DTLS1_BITMAP *bitmap;\n    unsigned int is_next_epoch;\n    int replayok = 1;\n    item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);\n    if (item) {\n        if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)\n            return 1;\n        rr = RECORD_LAYER_get_rrec(&s->rlayer);\n        rb = RECORD_LAYER_get_rbuf(&s->rlayer);\n        if (SSL3_BUFFER_get_left(rb) > 0) {\n            return 1;\n        }\n        while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {\n            dtls1_get_unprocessed_record(s);\n            bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);\n            if (bitmap == NULL) {\n                 SSLerr(SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS,\n                        ERR_R_INTERNAL_ERROR);\n                 return 0;\n            }\n#ifndef OPENSSL_NO_SCTP\n            if (!BIO_dgram_is_sctp(SSL_get_rbio(s)))\n#endif\n            {\n                replayok = dtls1_record_replay_check(s, bitmap);\n            }\n            if (!replayok || !dtls1_process_record(s, bitmap)) {\n                rr->length = 0;\n                RECORD_LAYER_reset_packet_length(&s->rlayer);\n                continue;\n            }\n            if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),\n                    SSL3_RECORD_get_seq_num(s->rlayer.rrec)) < 0)\n                return 0;\n        }\n    }\n    s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;\n    s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;\n    return 1;\n}', 'int dtls1_process_record(SSL *s, DTLS1_BITMAP *bitmap)\n{\n    int i, al;\n    int enc_err;\n    SSL_SESSION *sess;\n    SSL3_RECORD *rr;\n    int imac_size;\n    size_t mac_size;\n    unsigned char md[EVP_MAX_MD_SIZE];\n    rr = RECORD_LAYER_get_rrec(&s->rlayer);\n    sess = s->session;\n    rr->input = &(RECORD_LAYER_get_packet(&s->rlayer)[DTLS1_RT_HEADER_LENGTH]);\n    if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n        al = SSL_AD_RECORD_OVERFLOW;\n        SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);\n        goto f_err;\n    }\n    rr->data = rr->input;\n    rr->orig_len = rr->length;\n    if (SSL_READ_ETM(s) && s->read_hash) {\n        unsigned char *mac;\n        mac_size = EVP_MD_CTX_size(s->read_hash);\n        OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n        if (rr->orig_len < mac_size) {\n            al = SSL_AD_DECODE_ERROR;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_LENGTH_TOO_SHORT);\n            goto f_err;\n        }\n        rr->length -= mac_size;\n        mac = rr->data + rr->length;\n        i = s->method->ssl3_enc->mac(s, rr, md, 0   );\n        if (i == 0 || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0) {\n            al = SSL_AD_BAD_RECORD_MAC;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD,\n                   SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);\n            goto f_err;\n        }\n    }\n    enc_err = s->method->ssl3_enc->enc(s, rr, 1, 0);\n    if (enc_err == 0) {\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto err;\n    }\n#ifdef SSL_DEBUG\n    printf("dec %ld\\n", rr->length);\n    {\n        size_t z;\n        for (z = 0; z < rr->length; z++)\n            printf("%02X%c", rr->data[z], ((z + 1) % 16) ? \' \' : \'\\n\');\n    }\n    printf("\\n");\n#endif\n    if ((sess != NULL) && !SSL_READ_ETM(s) &&\n        (s->enc_read_ctx != NULL) && (EVP_MD_CTX_md(s->read_hash) != NULL)) {\n        unsigned char *mac = NULL;\n        unsigned char mac_tmp[EVP_MAX_MD_SIZE];\n        imac_size = EVP_MD_CTX_size(s->read_hash);\n        if (imac_size < 0) {\n            al = SSL_AD_INTERNAL_ERROR;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD, ERR_LIB_EVP);\n            goto f_err;\n        }\n        mac_size = (size_t)imac_size;\n        OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n        if (rr->orig_len < mac_size ||\n            (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n             rr->orig_len < mac_size + 1)) {\n            al = SSL_AD_DECODE_ERROR;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_LENGTH_TOO_SHORT);\n            goto f_err;\n        }\n        if (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE) {\n            mac = mac_tmp;\n            ssl3_cbc_copy_mac(mac_tmp, rr, mac_size);\n            rr->length -= mac_size;\n        } else {\n            rr->length -= mac_size;\n            mac = &rr->data[rr->length];\n        }\n        i = s->method->ssl3_enc->mac(s, rr, md, 0   );\n        if (i == 0 || mac == NULL\n            || CRYPTO_memcmp(md, mac, mac_size) != 0)\n            enc_err = -1;\n        if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_size)\n            enc_err = -1;\n    }\n    if (enc_err < 0) {\n        rr->length = 0;\n        RECORD_LAYER_reset_packet_length(&s->rlayer);\n        goto err;\n    }\n    if (s->expand != NULL) {\n        if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH) {\n            al = SSL_AD_RECORD_OVERFLOW;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD,\n                   SSL_R_COMPRESSED_LENGTH_TOO_LONG);\n            goto f_err;\n        }\n        if (!ssl3_do_uncompress(s, rr)) {\n            al = SSL_AD_DECOMPRESSION_FAILURE;\n            SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_BAD_DECOMPRESSION);\n            goto f_err;\n        }\n    }\n    if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH) {\n        al = SSL_AD_RECORD_OVERFLOW;\n        SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_DATA_LENGTH_TOO_LONG);\n        goto f_err;\n    }\n    rr->off = 0;\n    RECORD_LAYER_reset_packet_length(&s->rlayer);\n    dtls1_record_bitmap_update(s, bitmap);\n    return (1);\n f_err:\n    ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\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->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}']