crypto/bn/bntest.c:224: error: BUFFER_OVERRUN_L3
  Offset: [7, +oo] (⇐ [0, +oo] + 7) Size: [0, +oo] by call to `BN_rand`.
Showing all 11 steps of the trace


crypto/bn/bntest.c:224:3: Call
222.   	for (i=0; i<100; i++)
223.   		{
224.   		BN_rand(&b,450+i,0,0);
         ^
225.   		a.neg=rand_neg();
226.   		b.neg=rand_neg();

crypto/bn/bn_rand.c:65:1: Parameter `*rnd->d`
  63.   #include <openssl/rand.h>
  64.   
  65. > int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
  66.   	{
  67.   	unsigned char *buf=NULL;

crypto/bn/bntest.c:224:3: Call
222.   	for (i=0; i<100; i++)
223.   		{
224.   		BN_rand(&b,450+i,0,0);
         ^
225.   		a.neg=rand_neg();
226.   		b.neg=rand_neg();

crypto/bn/bn_rand.c:65:1: Parameter `*rnd->d`
  63.   #include <openssl/rand.h>
  64.   
  65. > int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
  66.   	{
  67.   	unsigned char *buf=NULL;

crypto/bn/bn_rand.c:107:7: Call
  105.   	if (bottom) /* set bottom bits to whatever odd is */
  106.   		buf[bytes-1]|=1;
  107.   	if (!BN_bin2bn(buf,bytes,rnd)) goto err;
               ^
  108.   	ret=1;
  109.   err:

crypto/bn/bn_lib.c:574:1: Parameter `*ret->d`
    572.   
    573.   /* ignore negative */
    574. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
    575.   	{
    576.   	unsigned int i,m;

crypto/bn/bn_lib.c:589:6: Call
    587.   		return(ret);
    588.   		}
    589.   	if (bn_expand(ret,(int)(n+2)*8) == NULL)
                ^
    590.   		return(NULL);
    591.   	i=((n-1)/BN_BYTES)+1;

crypto/bn/bn_lib.c:344:1: <Length trace>
342.   	}
343.   
344. > BIGNUM *bn_expand2(BIGNUM *b, int words)
345.   	{
346.   	BN_ULONG *A,*B,*a;

crypto/bn/bn_lib.c:344:1: Parameter `*b->d`
      342.   	}
      343.   
      344. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      345.   	{
      346.   	BN_ULONG *A,*B,*a;

crypto/bn/bn_lib.c:367:3: Assignment
      365.   memset(A,0x5c,sizeof(BN_ULONG)*(words+1));
      366.   #if 1
      367.   		B=b->d;
               ^
      368.   		/* Check if the previous number needs to be copied */
      369.   		if (B != NULL)

crypto/bn/bn_lib.c:377:43: Array access: Offset: [7, +oo] (⇐ [0, +oo] + 7) Size: [0, +oo] by call to `BN_rand` 
      375.   				{
      376.   				A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
      377.   				A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
                                                       ^
      378.   				A+=8;
      379.   				B+=8;

BIGNUM *bn_expand2(BIGNUM *b, int words)
	{
	BN_ULONG *A,*B,*a;
	int i,j;
	bn_check_top(b);
	if (words > b->max)
		{
		bn_check_top(b);
		if (BN_get_flags(b,BN_FLG_STATIC_DATA))
			{
			BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
			return(NULL);
			}
		a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
		if (A == NULL)
			{
			BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
			return(NULL);
			}
memset(A,0x5c,sizeof(BN_ULONG)*(words+1));
#if 1
		B=b->d;
		if (B != NULL)
			{
			for (i=b->top&(~7); i>0; i-=8)
				{
				A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
				A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
				A+=8;
				B+=8;
				}
			switch (b->top&7)
				{
			case 7:
				A[6]=B[6];
			case 6:
				A[5]=B[5];
			case 5:
				A[4]=B[4];
			case 4:
				A[3]=B[3];
			case 3:
				A[2]=B[2];
			case 2:
				A[1]=B[1];
			case 1:
				A[0]=B[0];
			case 0:
				;
				}
			Free(b->d);
			}
		b->d=a;
		b->max=words;
		B= &(b->d[b->top]);
		j=(b->max - b->top) & ~7;
		for (i=0; i<j; i+=8)
			{
			B[0]=0; B[1]=0; B[2]=0; B[3]=0;
			B[4]=0; B[5]=0; B[6]=0; B[7]=0;
			B+=8;
			}
		j=(b->max - b->top) & 7;
		for (i=0; i<j; i++)
			{
			B[0]=0;
			B++;
			}
#else
			memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
#endif
		}
	return(b);
	}
['int test_add(BIO *bp)\n\t{\n\tBIGNUM a,b,c;\n\tint i;\n\tint j;\n\tBN_init(&a);\n\tBN_init(&b);\n\tBN_init(&c);\n\tBN_rand(&a,512,0,0);\n\tfor (i=0; i<100; i++)\n\t\t{\n\t\tBN_rand(&b,450+i,0,0);\n\t\ta.neg=rand_neg();\n\t\tb.neg=rand_neg();\n\t\tif (bp == NULL)\n\t\t\tfor (j=0; j<10000; j++)\n\t\t\t\tBN_add(&c,&a,&b);\n\t\tBN_add(&c,&a,&b);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,&a);\n\t\t\t\tBIO_puts(bp," + ");\n\t\t\t\tBN_print(bp,&b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,&c);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(&a);\n\tBN_free(&b);\n\tBN_free(&c);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tif (ret == NULL) ret=BN_new();\n\tif (ret == NULL) return(NULL);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\tif (bn_expand(ret,(int)(n+2)*8) == NULL)\n\t\treturn(NULL);\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tret->top=i;\n\twhile (n-- > 0)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_fix_top(ret);\n\treturn(ret);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*B,*a;\n\tint i,j;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\nmemset(A,0x5c,sizeof(BN_ULONG)*(words+1));\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tB= &(b->d[b->top]);\n\t\tj=(b->max - b->top) & ~7;\n\t\tfor (i=0; i<j; i+=8)\n\t\t\t{\n\t\t\tB[0]=0; B[1]=0; B[2]=0; B[3]=0;\n\t\t\tB[4]=0; B[5]=0; B[6]=0; B[7]=0;\n\t\t\tB+=8;\n\t\t\t}\n\t\tj=(b->max - b->top) & 7;\n\t\tfor (i=0; i<j; i++)\n\t\t\t{\n\t\t\tB[0]=0;\n\t\t\tB++;\n\t\t\t}\n#else\n\t\t\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\t\t}\n\treturn(b);\n\t}']