ssl/s23_srvr.c:459: error: BUFFER_OVERRUN_L2
  Offset added: [-oo, 4096] Size: 11.
Showing all 6 steps of the trace


ssl/s23_srvr.c:208:2: <Offset trace>
206.   	unsigned int i;
207.   	unsigned int csl,sil,cl;
208.   	int n=0,j;
        ^
209.   	int type=0;
210.   	int v[2];

ssl/s23_srvr.c:208:2: Assignment
206.   	unsigned int i;
207.   	unsigned int csl,sil,cl;
208.   	int n=0,j;
        ^
209.   	int type=0;
210.   	int v[2];

ssl/s23_srvr.c:189:1: <Length trace>
187.   
188.   
189. > int ssl23_get_client_hello(SSL *s)
190.   	{
191.   	char buf_space[11]; /* Request this many bytes in initial read.

ssl/s23_srvr.c:189:1: Array declaration
187.   
188.   
189. > int ssl23_get_client_hello(SSL *s)
190.   	{
191.   	char buf_space[11]; /* Request this many bytes in initial read.

ssl/s23_srvr.c:204:2: Assignment
202.   	                     *  9/10  client_version  /
203.   	                     */
204.   	char *buf= &(buf_space[0]);
        ^
205.   	unsigned char *p,*d,*d_len,*dd;
206.   	unsigned int i;

ssl/s23_srvr.c:459:3: Array access: Offset added: [-oo, 4096] Size: 11
457.   		s->packet_length=n;
458.   		s->packet= &(s->s2->rbuf[0]);
459.   		memcpy(s->packet,buf,n);
         ^
460.   		s->s2->rbuf_left=n;
461.   		s->s2->rbuf_offs=0;

int ssl23_get_client_hello(SSL *s)
	{
	char buf_space[11];
	char *buf= &(buf_space[0]);
	unsigned char *p,*d,*d_len,*dd;
	unsigned int i;
	unsigned int csl,sil,cl;
	int n=0,j;
	int type=0;
	int v[2];
#ifndef OPENSSL_NO_RSA
	int use_sslv2_strong=0;
#endif
	if (s->state ==	SSL23_ST_SR_CLNT_HELLO_A)
		{
		v[0]=v[1]=0;
		if (!ssl3_setup_buffers(s)) goto err;
		n=ssl23_read_bytes(s, sizeof buf_space);
		if (n != sizeof buf_space) return(n);
		p=s->packet;
		memcpy(buf,p,n);
		if ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))
			{
			if ((p[3] == 0x00) && (p[4] == 0x02))
				{
				v[0]=p[3]; v[1]=p[4];
				if (!(s->options & SSL_OP_NO_SSLv2))
					type=1;
				}
			else if (p[3] == SSL3_VERSION_MAJOR)
				{
				v[0]=p[3]; v[1]=p[4];
				if (p[4] >= TLS1_VERSION_MINOR)
					{
					if (!(s->options & SSL_OP_NO_TLSv1))
						{
						s->version=TLS1_VERSION;
						s->state=SSL23_ST_SR_CLNT_HELLO_B;
						}
					else if (!(s->options & SSL_OP_NO_SSLv3))
						{
						s->version=SSL3_VERSION;
						s->state=SSL23_ST_SR_CLNT_HELLO_B;
						}
					else if (!(s->options & SSL_OP_NO_SSLv2))
						{
						type=1;
						}
					}
				else if (!(s->options & SSL_OP_NO_SSLv3))
					{
					s->version=SSL3_VERSION;
					s->state=SSL23_ST_SR_CLNT_HELLO_B;
					}
				else if (!(s->options & SSL_OP_NO_SSLv2))
					type=1;
				}
			}
		else if ((p[0] == SSL3_RT_HANDSHAKE) &&
			 (p[1] == SSL3_VERSION_MAJOR) &&
			 (p[5] == SSL3_MT_CLIENT_HELLO) &&
			 ((p[3] == 0 && p[4] < 5  )
				|| (p[9] == p[1])))
			{
			v[0]=p[1];
			if (p[3] == 0 && p[4] < 6)
				{
				SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_SMALL);
				goto err;
				}
			v[1]=p[10];
			if (v[1] >= TLS1_VERSION_MINOR)
				{
				if (!(s->options & SSL_OP_NO_TLSv1))
					{
					s->version=TLS1_VERSION;
					type=3;
					}
				else if (!(s->options & SSL_OP_NO_SSLv3))
					{
					s->version=SSL3_VERSION;
					type=3;
					}
				}
			else if (!(s->options & SSL_OP_NO_SSLv3))
				{
				s->version=SSL3_VERSION;
				type=3;
				}
			}
		else if ((strncmp("GET ", (char *)p,4) == 0) ||
			 (strncmp("POST ",(char *)p,5) == 0) ||
			 (strncmp("HEAD ",(char *)p,5) == 0) ||
			 (strncmp("PUT ", (char *)p,4) == 0))
			{
			SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);
			goto err;
			}
		else if (strncmp("CONNECT",(char *)p,7) == 0)
			{
			SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);
			goto err;
			}
		}
	if (s->state == SSL23_ST_SR_CLNT_HELLO_B)
		{
		type=2;
		p=s->packet;
		v[0] = p[3];
		v[1] = p[4];
		n=((p[0]&0x7f)<<8)|p[1];
		if (n > (1024*4))
			{
			SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);
			goto err;
			}
		j=ssl23_read_bytes(s,n+2);
		if (j <= 0) return(j);
		ssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);
		p=s->packet;
		p+=5;
		n2s(p,csl);
		n2s(p,sil);
		n2s(p,cl);
		d=(unsigned char *)s->init_buf->data;
		if ((csl+sil+cl+11) != s->packet_length)
			{
			SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);
			goto err;
			}
		*(d++) = SSL3_VERSION_MAJOR;
		*(d++) = v[1];
		d_len = d++;
		d++;
		*(d++) = SSL3_VERSION_MAJOR;
		*(d++) = v[1];
		i=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;
		memset(d,0,SSL3_RANDOM_SIZE);
		memcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);
		d+=SSL3_RANDOM_SIZE;
		*(d++)=0;
		j=0;
		dd=d;
		d+=2;
		for (i=0; i<csl; i+=3)
			{
			if (p[i] != 0) continue;
			*(d++)=p[i+1];
			*(d++)=p[i+2];
			j+=2;
			}
		s2n(j,dd);
		*(d++)=1;
		*(d++)=0;
		i=(d-(unsigned char *)s->init_buf->data);
		s2n(i, d_len);
		s->s3->tmp.reuse_message=1;
		s->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;
		s->s3->tmp.message_size=i;
		}
	if (type == 1)
		{
#ifdef OPENSSL_NO_SSL2
		SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);
		goto err;
#else
		if (s->s2 == NULL)
			{
			if (!ssl2_new(s))
				goto err;
			}
		else
			ssl2_clear(s);
		if (s->s3 != NULL) ssl3_free(s);
		if (!BUF_MEM_grow(s->init_buf,
			SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
			{
			goto err;
			}
		s->state=SSL2_ST_GET_CLIENT_HELLO_A;
		if ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) ||
			use_sslv2_strong ||
			(s->options & SSL_OP_NO_TLSv1 && s->options & SSL_OP_NO_SSLv3))
			s->s2->ssl2_rollback=0;
		else
			s->s2->ssl2_rollback=1;
		s->rstate=SSL_ST_READ_HEADER;
		s->packet_length=n;
		s->packet= &(s->s2->rbuf[0]);
		memcpy(s->packet,buf,n);
		s->s2->rbuf_left=n;
		s->s2->rbuf_offs=0;
		s->method=SSLv2_server_method();
		s->handshake_func=s->method->ssl_accept;
#endif
		}
	if ((type == 2) || (type == 3))
		{
		if (!ssl_init_wbio_buffer(s,1)) goto err;
		s->state=SSL3_ST_SR_CLNT_HELLO_A;
		if (type == 3)
			{
			s->rstate=SSL_ST_READ_HEADER;
			s->packet_length=n;
			s->packet= &(s->s3->rbuf.buf[0]);
			memcpy(s->packet,buf,n);
			s->s3->rbuf.left=n;
			s->s3->rbuf.offset=0;
			}
		else
			{
			s->packet_length=0;
			s->s3->rbuf.left=0;
			s->s3->rbuf.offset=0;
			}
		if (s->version == TLS1_VERSION)
			s->method = TLSv1_server_method();
		else
			s->method = SSLv3_server_method();
#if 0
		s->client_version=(v[0]<<8)|v[1];
#endif
		s->handshake_func=s->method->ssl_accept;
		}
	if ((type < 1) || (type > 3))
		{
		SSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);
		goto err;
		}
	s->init_num=0;
	if (buf != buf_space) OPENSSL_free(buf);
	s->first_packet=1;
	return(SSL_accept(s));
err:
	if (buf != buf_space) OPENSSL_free(buf);
	return(-1);
	}
['int ssl23_get_client_hello(SSL *s)\n\t{\n\tchar buf_space[11];\n\tchar *buf= &(buf_space[0]);\n\tunsigned char *p,*d,*d_len,*dd;\n\tunsigned int i;\n\tunsigned int csl,sil,cl;\n\tint n=0,j;\n\tint type=0;\n\tint v[2];\n#ifndef OPENSSL_NO_RSA\n\tint use_sslv2_strong=0;\n#endif\n\tif (s->state ==\tSSL23_ST_SR_CLNT_HELLO_A)\n\t\t{\n\t\tv[0]=v[1]=0;\n\t\tif (!ssl3_setup_buffers(s)) goto err;\n\t\tn=ssl23_read_bytes(s, sizeof buf_space);\n\t\tif (n != sizeof buf_space) return(n);\n\t\tp=s->packet;\n\t\tmemcpy(buf,p,n);\n\t\tif ((p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO))\n\t\t\t{\n\t\t\tif ((p[3] == 0x00) && (p[4] == 0x02))\n\t\t\t\t{\n\t\t\t\tv[0]=p[3]; v[1]=p[4];\n\t\t\t\tif (!(s->options & SSL_OP_NO_SSLv2))\n\t\t\t\t\ttype=1;\n\t\t\t\t}\n\t\t\telse if (p[3] == SSL3_VERSION_MAJOR)\n\t\t\t\t{\n\t\t\t\tv[0]=p[3]; v[1]=p[4];\n\t\t\t\tif (p[4] >= TLS1_VERSION_MINOR)\n\t\t\t\t\t{\n\t\t\t\t\tif (!(s->options & SSL_OP_NO_TLSv1))\n\t\t\t\t\t\t{\n\t\t\t\t\t\ts->version=TLS1_VERSION;\n\t\t\t\t\t\ts->state=SSL23_ST_SR_CLNT_HELLO_B;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (!(s->options & SSL_OP_NO_SSLv3))\n\t\t\t\t\t\t{\n\t\t\t\t\t\ts->version=SSL3_VERSION;\n\t\t\t\t\t\ts->state=SSL23_ST_SR_CLNT_HELLO_B;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (!(s->options & SSL_OP_NO_SSLv2))\n\t\t\t\t\t\t{\n\t\t\t\t\t\ttype=1;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\telse if (!(s->options & SSL_OP_NO_SSLv3))\n\t\t\t\t\t{\n\t\t\t\t\ts->version=SSL3_VERSION;\n\t\t\t\t\ts->state=SSL23_ST_SR_CLNT_HELLO_B;\n\t\t\t\t\t}\n\t\t\t\telse if (!(s->options & SSL_OP_NO_SSLv2))\n\t\t\t\t\ttype=1;\n\t\t\t\t}\n\t\t\t}\n\t\telse if ((p[0] == SSL3_RT_HANDSHAKE) &&\n\t\t\t (p[1] == SSL3_VERSION_MAJOR) &&\n\t\t\t (p[5] == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t ((p[3] == 0 && p[4] < 5  )\n\t\t\t\t|| (p[9] == p[1])))\n\t\t\t{\n\t\t\tv[0]=p[1];\n\t\t\tif (p[3] == 0 && p[4] < 6)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_SMALL);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tv[1]=p[10];\n\t\t\tif (v[1] >= TLS1_VERSION_MINOR)\n\t\t\t\t{\n\t\t\t\tif (!(s->options & SSL_OP_NO_TLSv1))\n\t\t\t\t\t{\n\t\t\t\t\ts->version=TLS1_VERSION;\n\t\t\t\t\ttype=3;\n\t\t\t\t\t}\n\t\t\t\telse if (!(s->options & SSL_OP_NO_SSLv3))\n\t\t\t\t\t{\n\t\t\t\t\ts->version=SSL3_VERSION;\n\t\t\t\t\ttype=3;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if (!(s->options & SSL_OP_NO_SSLv3))\n\t\t\t\t{\n\t\t\t\ts->version=SSL3_VERSION;\n\t\t\t\ttype=3;\n\t\t\t\t}\n\t\t\t}\n\t\telse if ((strncmp("GET ", (char *)p,4) == 0) ||\n\t\t\t (strncmp("POST ",(char *)p,5) == 0) ||\n\t\t\t (strncmp("HEAD ",(char *)p,5) == 0) ||\n\t\t\t (strncmp("PUT ", (char *)p,4) == 0))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTP_REQUEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\telse if (strncmp("CONNECT",(char *)p,7) == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_HTTPS_PROXY_REQUEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (s->state == SSL23_ST_SR_CLNT_HELLO_B)\n\t\t{\n\t\ttype=2;\n\t\tp=s->packet;\n\t\tv[0] = p[3];\n\t\tv[1] = p[4];\n\t\tn=((p[0]&0x7f)<<8)|p[1];\n\t\tif (n > (1024*4))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_TOO_LARGE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tj=ssl23_read_bytes(s,n+2);\n\t\tif (j <= 0) return(j);\n\t\tssl3_finish_mac(s,&(s->packet[2]),s->packet_length-2);\n\t\tp=s->packet;\n\t\tp+=5;\n\t\tn2s(p,csl);\n\t\tn2s(p,sil);\n\t\tn2s(p,cl);\n\t\td=(unsigned char *)s->init_buf->data;\n\t\tif ((csl+sil+cl+11) != s->packet_length)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_RECORD_LENGTH_MISMATCH);\n\t\t\tgoto err;\n\t\t\t}\n\t\t*(d++) = SSL3_VERSION_MAJOR;\n\t\t*(d++) = v[1];\n\t\td_len = d++;\n\t\td++;\n\t\t*(d++) = SSL3_VERSION_MAJOR;\n\t\t*(d++) = v[1];\n\t\ti=(cl > SSL3_RANDOM_SIZE)?SSL3_RANDOM_SIZE:cl;\n\t\tmemset(d,0,SSL3_RANDOM_SIZE);\n\t\tmemcpy(&(d[SSL3_RANDOM_SIZE-i]),&(p[csl+sil]),i);\n\t\td+=SSL3_RANDOM_SIZE;\n\t\t*(d++)=0;\n\t\tj=0;\n\t\tdd=d;\n\t\td+=2;\n\t\tfor (i=0; i<csl; i+=3)\n\t\t\t{\n\t\t\tif (p[i] != 0) continue;\n\t\t\t*(d++)=p[i+1];\n\t\t\t*(d++)=p[i+2];\n\t\t\tj+=2;\n\t\t\t}\n\t\ts2n(j,dd);\n\t\t*(d++)=1;\n\t\t*(d++)=0;\n\t\ti=(d-(unsigned char *)s->init_buf->data);\n\t\ts2n(i, d_len);\n\t\ts->s3->tmp.reuse_message=1;\n\t\ts->s3->tmp.message_type=SSL3_MT_CLIENT_HELLO;\n\t\ts->s3->tmp.message_size=i;\n\t\t}\n\tif (type == 1)\n\t\t{\n#ifdef OPENSSL_NO_SSL2\n\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNSUPPORTED_PROTOCOL);\n\t\tgoto err;\n#else\n\t\tif (s->s2 == NULL)\n\t\t\t{\n\t\t\tif (!ssl2_new(s))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\telse\n\t\t\tssl2_clear(s);\n\t\tif (s->s3 != NULL) ssl3_free(s);\n\t\tif (!BUF_MEM_grow(s->init_buf,\n\t\t\tSSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))\n\t\t\t{\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->state=SSL2_ST_GET_CLIENT_HELLO_A;\n\t\tif ((s->options & SSL_OP_MSIE_SSLV2_RSA_PADDING) ||\n\t\t\tuse_sslv2_strong ||\n\t\t\t(s->options & SSL_OP_NO_TLSv1 && s->options & SSL_OP_NO_SSLv3))\n\t\t\ts->s2->ssl2_rollback=0;\n\t\telse\n\t\t\ts->s2->ssl2_rollback=1;\n\t\ts->rstate=SSL_ST_READ_HEADER;\n\t\ts->packet_length=n;\n\t\ts->packet= &(s->s2->rbuf[0]);\n\t\tmemcpy(s->packet,buf,n);\n\t\ts->s2->rbuf_left=n;\n\t\ts->s2->rbuf_offs=0;\n\t\ts->method=SSLv2_server_method();\n\t\ts->handshake_func=s->method->ssl_accept;\n#endif\n\t\t}\n\tif ((type == 2) || (type == 3))\n\t\t{\n\t\tif (!ssl_init_wbio_buffer(s,1)) goto err;\n\t\ts->state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\tif (type == 3)\n\t\t\t{\n\t\t\ts->rstate=SSL_ST_READ_HEADER;\n\t\t\ts->packet_length=n;\n\t\t\ts->packet= &(s->s3->rbuf.buf[0]);\n\t\t\tmemcpy(s->packet,buf,n);\n\t\t\ts->s3->rbuf.left=n;\n\t\t\ts->s3->rbuf.offset=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ts->packet_length=0;\n\t\t\ts->s3->rbuf.left=0;\n\t\t\ts->s3->rbuf.offset=0;\n\t\t\t}\n\t\tif (s->version == TLS1_VERSION)\n\t\t\ts->method = TLSv1_server_method();\n\t\telse\n\t\t\ts->method = SSLv3_server_method();\n#if 0\n\t\ts->client_version=(v[0]<<8)|v[1];\n#endif\n\t\ts->handshake_func=s->method->ssl_accept;\n\t\t}\n\tif ((type < 1) || (type > 3))\n\t\t{\n\t\tSSLerr(SSL_F_SSL23_GET_CLIENT_HELLO,SSL_R_UNKNOWN_PROTOCOL);\n\t\tgoto err;\n\t\t}\n\ts->init_num=0;\n\tif (buf != buf_space) OPENSSL_free(buf);\n\ts->first_packet=1;\n\treturn(SSL_accept(s));\nerr:\n\tif (buf != buf_space) OPENSSL_free(buf);\n\treturn(-1);\n\t}']