crypto/rsa/rsa_eay.c:463: error: BUFFER_OVERRUN_L3
  Offset: [-1, 11] Size: 12 by call to `BN_mul`.
Showing all 25 steps of the trace


crypto/rsa/rsa_eay.c:416:11: Call
414.   	BN_CTX *ctx;
415.   
416.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
                 ^
417.   	BN_init(&m1);
418.   	BN_init(&r1);

crypto/bn/bn_ctx.c:79:2: Call
  77.   		}
  78.   
  79.   	BN_CTX_init(ret);
         ^
  80.   	ret->flags=BN_FLG_MALLOCED;
  81.   	return(ret);

crypto/bn/bn_ctx.c:89:2: Assignment
    87.   	ctx->tos = 0;
    88.   	ctx->flags = 0;
    89.   	ctx->depth = 0;
           ^
    90.   	ctx->too_many = 0;
    91.   	for (i = 0; i < BN_CTX_NUM; i++)

crypto/rsa/rsa_eay.c:438:7: Call
436.   		}
437.   
438.   	if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
             ^
439.   	if (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,
440.   		rsa->_method_mod_q)) goto err;

crypto/bn/bn_div.c:346:1: Parameter `ctx->depth`
  344.   
  345.   /* rem != m */
  346. > int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
  347.   	{
  348.   #if 0 /* The old slow way */

crypto/bn/bn_div.c:377:9: Call
  375.   	return(0);
  376.   #else
  377.   	return(BN_div(NULL,rem,m,d,ctx));
                 ^
  378.   #endif
  379.   	}

crypto/bn/bn_div.c:155:1: Parameter `ctx->depth`
    153.   #endif /* NO_ASM */
    154.   
    155. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    156.   	   BN_CTX *ctx)
    157.   	{

crypto/rsa/rsa_eay.c:442:7: Call
440.   		rsa->_method_mod_q)) goto err;
441.   
442.   	if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
             ^
443.   	if (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,
444.   		rsa->_method_mod_p)) goto err;

crypto/bn/bn_div.c:346:1: Parameter `ctx->depth`
  344.   
  345.   /* rem != m */
  346. > int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
  347.   	{
  348.   #if 0 /* The old slow way */

crypto/bn/bn_div.c:377:9: Call
  375.   	return(0);
  376.   #else
  377.   	return(BN_div(NULL,rem,m,d,ctx));
                 ^
  378.   #endif
  379.   	}

crypto/bn/bn_div.c:155:1: Parameter `ctx->depth`
    153.   #endif /* NO_ASM */
    154.   
    155. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    156.   	   BN_CTX *ctx)
    157.   	{

crypto/rsa/rsa_eay.c:452:7: Call
450.   		if (!BN_add(r0,r0,rsa->p)) goto err;
451.   
452.   	if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
             ^
453.   	if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
454.   	/* If p < q it is occasionally possible for the correction of

crypto/bn/bn_mul.c:565:1: Parameter `ctx->depth`
  563.   #endif /* BN_RECURSION */
  564.   
  565. > int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
  566.   	{
  567.   	int top,al,bl;

crypto/rsa/rsa_eay.c:453:7: Call
451.   
452.   	if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
453.   	if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
             ^
454.   	/* If p < q it is occasionally possible for the correction of
455.            * adding 'p' if r0 is negative above to leave the result still

crypto/bn/bn_div.c:346:1: Parameter `ctx->depth`
  344.   
  345.   /* rem != m */
  346. > int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
  347.   	{
  348.   #if 0 /* The old slow way */

crypto/bn/bn_div.c:377:9: Call
  375.   	return(0);
  376.   #else
  377.   	return(BN_div(NULL,rem,m,d,ctx));
                 ^
  378.   #endif
  379.   	}

crypto/bn/bn_div.c:155:1: Parameter `ctx->depth`
    153.   #endif /* NO_ASM */
    154.   
    155. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    156.   	   BN_CTX *ctx)
    157.   	{

crypto/rsa/rsa_eay.c:463:7: Call
461.   	if (r0->neg)
462.   		if (!BN_add(r0,r0,rsa->p)) goto err;
463.   	if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
             ^
464.   	if (!BN_add(r0,&r1,&m1)) goto err;
465.   

crypto/bn/bn_mul.c:565:1: Parameter `ctx->depth`
  563.   #endif /* BN_RECURSION */
  564.   
  565. > int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
  566.   	{
  567.   	int top,al,bl;

crypto/bn/bn_mul.c:597:2: Call
  595.   	top=al+bl;
  596.   
  597.   	BN_CTX_start(ctx);
          ^
  598.   	if ((r == a) || (r == b))
  599.   		{

crypto/bn/bn_ctx.c:108:1: <Offset trace>
106.   	}
107.   
108. > void BN_CTX_start(BN_CTX *ctx)
109.   	{
110.   	if (ctx->depth < BN_CTX_NUM_POS)

crypto/bn/bn_ctx.c:108:1: Parameter `ctx->depth`
    106.   	}
    107.   
    108. > void BN_CTX_start(BN_CTX *ctx)
    109.   	{
    110.   	if (ctx->depth < BN_CTX_NUM_POS)

crypto/bn/bn_ctx.c:108:1: <Length trace>
106.   	}
107.   
108. > void BN_CTX_start(BN_CTX *ctx)
109.   	{
110.   	if (ctx->depth < BN_CTX_NUM_POS)

crypto/bn/bn_ctx.c:108:1: Parameter `ctx->pos[*]`
    106.   	}
    107.   
    108. > void BN_CTX_start(BN_CTX *ctx)
    109.   	{
    110.   	if (ctx->depth < BN_CTX_NUM_POS)

crypto/bn/bn_ctx.c:111:3: Array access: Offset: [-1, 11] Size: 12 by call to `BN_mul` 
    109.   	{
    110.   	if (ctx->depth < BN_CTX_NUM_POS)
    111.   		ctx->pos[ctx->depth] = ctx->tos;
             ^
    112.   	ctx->depth++;
    113.   	}

void BN_CTX_start(BN_CTX *ctx)
	{
	if (ctx->depth < BN_CTX_NUM_POS)
		ctx->pos[ctx->depth] = ctx->tos;
	ctx->depth++;
	}
['static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)\n\t{\n\tBIGNUM r1,m1;\n\tint ret=0;\n\tBN_CTX *ctx;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_init(&m1);\n\tBN_init(&r1);\n\tif (rsa->flags & RSA_FLAG_CACHE_PRIVATE)\n\t\t{\n\t\tif (rsa->_method_mod_p == NULL)\n\t\t\t{\n\t\t\tif ((rsa->_method_mod_p=BN_MONT_CTX_new()) != NULL)\n\t\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_p,rsa->p,\n\t\t\t\t\t\t     ctx))\n\t\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (rsa->_method_mod_q == NULL)\n\t\t\t{\n\t\t\tif ((rsa->_method_mod_q=BN_MONT_CTX_new()) != NULL)\n\t\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_q,rsa->q,\n\t\t\t\t\t\t     ctx))\n\t\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (!BN_mod(&r1,I,rsa->q,ctx)) goto err;\n\tif (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,\n\t\trsa->_method_mod_q)) goto err;\n\tif (!BN_mod(&r1,I,rsa->p,ctx)) goto err;\n\tif (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,\n\t\trsa->_method_mod_p)) goto err;\n\tif (!BN_sub(r0,r0,&m1)) goto err;\n\tif (r0->neg)\n\t\tif (!BN_add(r0,r0,rsa->p)) goto err;\n\tif (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;\n\tif (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;\n\tif (r0->neg)\n\t\tif (!BN_add(r0,r0,rsa->p)) goto err;\n\tif (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;\n\tif (!BN_add(r0,&r1,&m1)) goto err;\n\tret=1;\nerr:\n\tBN_clear_free(&m1);\n\tBN_clear_free(&r1);\n\tBN_CTX_free(ctx);\n\treturn(ret);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'void BN_CTX_init(BN_CTX *ctx)\n\t{\n\tint i;\n\tctx->tos = 0;\n\tctx->flags = 0;\n\tctx->depth = 0;\n\tctx->too_many = 0;\n\tfor (i = 0; i < BN_CTX_NUM; i++)\n\t\tBN_init(&(ctx->bn[i]));\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tBN_CTX_start(ctx);\n\tdv=BN_CTX_get(ctx);\n\tif (!BN_copy(rem,m)) goto err;\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) goto err;\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) goto err;\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) goto err;\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\n err:\n\tBN_CTX_end(ctx);\n\treturn(0);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t   BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\ttmp->neg=0;\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,l0;\n#ifdef BN_DIV3W\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#ifdef BN_UMULT_HIGH\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q);  qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\twnum.d--; wnum.top++;\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n\tint ret = 0;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint j,k;\n#endif\n#ifdef BN_COUNT\n\tprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(a,k);\n\t\t\t\tbn_wexpand(b,k);\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\t\ta->d[i]=0;\n\t\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\t\tb->d[i]=0;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->pos[ctx->depth] = ctx->tos;\n\tctx->depth++;\n\t}']