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


ssl/d1_both.c:409:1: Parameter `s->ctx->sessions->num_items`
407.    * fragments.
408.    */
409. > long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)
410.   	{
411.   	int i, al;

ssl/d1_both.c:437:6: Call
435.   
436.   again:
437.   	i = dtls1_get_message_fragment(s, st1, stn, max, ok);
            ^
438.   	if ( i == DTLS1_HM_BAD_FRAGMENT ||
439.   		i == DTLS1_HM_FRAGMENT_RETRY)  /* bad fragment received */

ssl/d1_both.c:784:1: Parameter `s->ctx->sessions->num_items`
  782.   
  783.   
  784. > static long
  785.   dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)
  786.   	{

ssl/d1_both.c:793:18: Call
  791.   
  792.   	/* see if we have the required fragment already */
  793.   	if ((frag_len = dtls1_retrieve_buffered_fragment(s,max,ok)) || *ok)
                          ^
  794.   		{
  795.   		if (*ok)	s->init_num = frag_len;

ssl/d1_both.c:540:1: Parameter `s->ctx->sessions->num_items`
    538.   
    539.   
    540. > static int
    541.   dtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok)
    542.   	{

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

ssl/s3_pkt.c:1421:1: Parameter `s->ctx->sessions->num_items`
      1419.   	}
      1420.   
      1421. > int ssl3_send_alert(SSL *s, int level, int desc)
      1422.   	{
      1423.   	/* Map tls/ssl alert value to correct one */

ssl/s3_pkt.c:1430:3: Call
      1428.   	/* If a fatal one, remove from cache */
      1429.   	if ((level == 2) && (s->session != NULL))
      1430.   		SSL_CTX_remove_session(s->ctx,s->session);
                ^
      1431.   
      1432.   	s->s3->alert_dispatch=1;

ssl/ssl_sess.c:658:1: Parameter `ctx->sessions->num_items`
        656.   	}
        657.   
        658. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
        659.   {
        660.   	return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:660:9: Call
        658.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
        659.   {
        660.   	return remove_session_lock(ctx, c, 1);
                       ^
        661.   }
        662.   

ssl/ssl_sess.c:663:1: Parameter `ctx->sessions->num_items`
          661.   }
          662.   
          663. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
          664.   	{
          665.   	SSL_SESSION *r;

ssl/ssl_sess.c:674:6: Call
          672.   			{
          673.   			ret=1;
          674.   			r=lh_SSL_SESSION_delete(ctx->sessions,c);
                      ^
          675.   			SSL_SESSION_list_remove(ctx,c);
          676.   			}

crypto/lhash/lhash.c:217:1: <LHS trace>
215.   	}
216.   
217. > void *lh_delete(_LHASH *lh, const void *data)
218.   	{
219.   	unsigned long hash;

crypto/lhash/lhash.c:217:1: Parameter `lh->num_items`
            215.   	}
            216.   
            217. > void *lh_delete(_LHASH *lh, const void *data)
            218.   	{
            219.   	unsigned long hash;

crypto/lhash/lhash.c:240:2: Binary operation: ([0, max(0, s->ctx->sessions->num_items)] - 1):unsigned64 by call to `dtls1_get_message_fragment` 
            238.   		}
            239.   
            240.   	lh->num_items--;
                    ^
            241.   	if ((lh->num_nodes > MIN_NODES) &&
            242.   		(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);
	}
['long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tint i, al;\n\tstruct hm_header_st *msg_hdr;\n\tunsigned char *p;\n\tunsigned long msg_len;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_DTLS1_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\ts->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n\t\ts->init_num = (int)s->s3->tmp.message_size;\n\t\treturn s->init_num;\n\t\t}\n\tmsg_hdr = &s->d1->r_msg_hdr;\n\tmemset(msg_hdr, 0x00, sizeof(struct hm_header_st));\nagain:\n\ti = dtls1_get_message_fragment(s, st1, stn, max, ok);\n\tif ( i == DTLS1_HM_BAD_FRAGMENT ||\n\t\ti == DTLS1_HM_FRAGMENT_RETRY)\n\t\tgoto again;\n\telse if ( i <= 0 && !*ok)\n\t\treturn i;\n\tp = (unsigned char *)s->init_buf->data;\n\tmsg_len = msg_hdr->msg_len;\n\t*(p++) = msg_hdr->type;\n\tl2n3(msg_len,p);\n\ts2n (msg_hdr->seq,p);\n\tl2n3(0,p);\n\tl2n3(msg_len,p);\n\tif (s->version != DTLS1_BAD_VER) {\n\t\tp       -= DTLS1_HM_HEADER_LENGTH;\n\t\tmsg_len += DTLS1_HM_HEADER_LENGTH;\n\t}\n\tssl3_finish_mac(s, p, msg_len);\n\tif (s->msg_callback)\n\t\ts->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n\t\t\tp, msg_len,\n\t\t\ts, s->msg_callback_arg);\n\tmemset(msg_hdr, 0x00, sizeof(struct hm_header_st));\n\ts->d1->handshake_read_seq++;\n\tdtls1_clear_record_buffer(s);\n\ts->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n\treturn s->init_num;\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t*ok = 0;\n\treturn -1;\n\t}', 'static long\ndtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)\n\t{\n\tunsigned char wire[DTLS1_HM_HEADER_LENGTH];\n\tunsigned long len, frag_off, frag_len;\n\tint i,al;\n\tstruct hm_header_st msg_hdr;\n\tif ((frag_len = dtls1_retrieve_buffered_fragment(s,max,ok)) || *ok)\n\t\t{\n\t\tif (*ok)\ts->init_num = frag_len;\n\t\treturn frag_len;\n\t\t}\n\ti=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,wire,\n\t\tDTLS1_HM_HEADER_LENGTH, 0);\n\tif (i <= 0)\n\t\t{\n\t\ts->rwstate=SSL_READING;\n\t\t*ok = 0;\n\t\treturn i;\n\t\t}\n\tOPENSSL_assert(i == DTLS1_HM_HEADER_LENGTH);\n\tdtls1_get_message_header(wire, &msg_hdr);\n\tif ( msg_hdr.seq != s->d1->handshake_read_seq)\n\t\treturn dtls1_process_out_of_seq_message(s, &msg_hdr, ok);\n\tlen = msg_hdr.msg_len;\n\tfrag_off = msg_hdr.frag_off;\n\tfrag_len = msg_hdr.frag_len;\n\tif (frag_len && frag_len < len)\n\t\treturn dtls1_reassemble_fragment(s, &msg_hdr, ok);\n\tif (!s->server && s->d1->r_msg_hdr.frag_off == 0 &&\n\t\twire[0] == SSL3_MT_HELLO_REQUEST)\n\t\t{\n\t\tif (wire[1] == 0 && wire[2] == 0 && wire[3] == 0)\n\t\t\t{\n\t\t\tif (s->msg_callback)\n\t\t\t\ts->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n\t\t\t\t\twire, DTLS1_HM_HEADER_LENGTH, s,\n\t\t\t\t\ts->msg_callback_arg);\n\t\t\ts->init_num = 0;\n\t\t\treturn dtls1_get_message_fragment(s, st1, stn,\n\t\t\t\tmax, ok);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif ((al=dtls1_preprocess_fragment(s,&msg_hdr,max)))\n\t\tgoto f_err;\n\ts->state=stn;\n\tif ( frag_len > 0)\n\t\t{\n\t\tunsigned char *p=(unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH;\n\t\ti=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,\n\t\t\t&p[frag_off],frag_len,0);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\ts->rwstate=SSL_READING;\n\t\t\t*ok = 0;\n\t\t\treturn i;\n\t\t\t}\n\t\t}\n\telse\n\t\ti = 0;\n\tOPENSSL_assert(i == (int)frag_len);\n\t*ok = 1;\n\ts->init_num = frag_len;\n\treturn frag_len;\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\ts->init_num = 0;\n\t*ok=0;\n\treturn(-1);\n\t}', 'static int\ndtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok)\n\t{\n\tpitem *item;\n\thm_fragment *frag;\n\tint al;\n\t*ok = 0;\n\titem = pqueue_peek(s->d1->buffered_messages);\n\tif ( item == NULL)\n\t\treturn 0;\n\tfrag = (hm_fragment *)item->data;\n\tif (frag->reassembly != NULL)\n\t\treturn 0;\n\tif ( s->d1->handshake_read_seq == frag->msg_header.seq)\n\t\t{\n\t\tunsigned long frag_len = frag->msg_header.frag_len;\n\t\tpqueue_pop(s->d1->buffered_messages);\n\t\tal=dtls1_preprocess_fragment(s,&frag->msg_header,max);\n\t\tif (al==0)\n\t\t\t{\n\t\t\tunsigned char *p = (unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH;\n\t\t\tmemcpy(&p[frag->msg_header.frag_off],\n\t\t\t\tfrag->fragment,frag->msg_header.frag_len);\n\t\t\t}\n\t\tdtls1_hm_fragment_free(frag);\n\t\tpitem_free(item);\n\t\tif (al==0)\n\t\t\t{\n\t\t\t*ok = 1;\n\t\t\treturn frag_len;\n\t\t\t}\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\ts->init_num = 0;\n\t\t*ok = 0;\n\t\treturn -1;\n\t\t}\n\telse\n\t\treturn 0;\n\t}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return -1;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\treturn s->method->ssl_dispatch_alert(s);\n\treturn -1;\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=lh_SSL_SESSION_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(_LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']