crypto/rsa/rsa_eay.c:305: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: 12 by call to `BN_BLINDING_invert`.
Showing all 35 steps of the trace


crypto/rsa/rsa_eay.c:263:6: Call
261.   	BN_init(&f);
262.   	BN_init(&ret);
263.   	ctx=BN_CTX_new();
            ^
264.   	if (ctx == NULL) goto err;
265.   

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:305:8: Call
303.   
304.   	if (rsa->flags & RSA_FLAG_BLINDING)
305.   		if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err;
              ^
306.   
307.   	p=buf;

crypto/bn/bn_blind.c:127:1: Parameter `ctx->depth`
  125.   	}
  126.   
  127. > int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
  128.   	{
  129.   	int ret;

crypto/bn/bn_blind.c:137:11: Call
  135.   		return(0);
  136.   		}
  137.   	if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)
                   ^
  138.   		{
  139.   		if (!BN_BLINDING_update(b,ctx))

crypto/bn/bn_mod.c:178:1: Parameter `ctx->depth`
    176.   
    177.   /* slow but works */
    178. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
    179.   	BN_CTX *ctx)
    180.   	{

crypto/bn/bn_mod.c:188:2: Call
    186.   	bn_check_top(m);
    187.   
    188.   	BN_CTX_start(ctx);
            ^
    189.   	if ((t = BN_CTX_get(ctx)) == NULL) goto err;
    190.   	if (a == b)

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:112:2: Assignment
      110.   	if (ctx->depth < BN_CTX_NUM_POS)
      111.   		ctx->pos[ctx->depth] = ctx->tos;
      112.   	ctx->depth++;
              ^
      113.   	}
      114.   

crypto/bn/bn_mod.c:189:11: Call
    187.   
    188.   	BN_CTX_start(ctx);
    189.   	if ((t = BN_CTX_get(ctx)) == NULL) goto err;
                     ^
    190.   	if (a == b)
    191.   		{ if (!BN_sqr(t,a,ctx)) goto err; }

crypto/bn/bn_ctx.c:116:1: Parameter `ctx->depth`
      114.   
      115.   
      116. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
      117.   	{
      118.   	/* Note: If BN_CTX_get is ever changed to allocate BIGNUMs dynamically,

crypto/bn/bn_mod.c:197:2: Call
    195.   	ret=1;
    196.   err:
    197.   	BN_CTX_end(ctx);
            ^
    198.   	return(ret);
    199.   	}

crypto/bn/bn_ctx.c:136:1: Parameter `ctx->depth`
      134.   	}
      135.   
      136. > void BN_CTX_end(BN_CTX *ctx)
      137.   	{
      138.   	if (ctx == NULL) return;

crypto/bn/bn_blind.c:139:8: Call
  137.   	if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)
  138.   		{
  139.   		if (!BN_BLINDING_update(b,ctx))
                ^
  140.   			return(0);
  141.   		}

crypto/bn/bn_blind.c:97:1: Parameter `ctx->depth`
    95.   	}
    96.   
    97. > int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
    98.   	{
    99.   	int ret=0;

crypto/bn/bn_blind.c:107:7: Call
    105.   		}
    106.   		
    107.   	if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;
                 ^
    108.   	if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;
    109.   

crypto/bn/bn_mod.c:178:1: Parameter `ctx->depth`
      176.   
      177.   /* slow but works */
      178. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
      179.   	BN_CTX *ctx)
      180.   	{

crypto/bn/bn_mod.c:188:2: Call
      186.   	bn_check_top(m);
      187.   
      188.   	BN_CTX_start(ctx);
              ^
      189.   	if ((t = BN_CTX_get(ctx)) == NULL) goto err;
      190.   	if (a == b)

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:112:2: Assignment
        110.   	if (ctx->depth < BN_CTX_NUM_POS)
        111.   		ctx->pos[ctx->depth] = ctx->tos;
        112.   	ctx->depth++;
                ^
        113.   	}
        114.   

crypto/bn/bn_mod.c:189:11: Call
      187.   
      188.   	BN_CTX_start(ctx);
      189.   	if ((t = BN_CTX_get(ctx)) == NULL) goto err;
                       ^
      190.   	if (a == b)
      191.   		{ if (!BN_sqr(t,a,ctx)) goto err; }

crypto/bn/bn_ctx.c:116:1: Parameter `ctx->depth`
        114.   
        115.   
        116. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
        117.   	{
        118.   	/* Note: If BN_CTX_get is ever changed to allocate BIGNUMs dynamically,

crypto/bn/bn_mod.c:193:10: Call
      191.   		{ if (!BN_sqr(t,a,ctx)) goto err; }
      192.   	else
      193.   		{ if (!BN_mul(t,a,b,ctx)) goto err; }
                      ^
      194.   	if (!BN_nnmod(r,t,m,ctx)) goto err;
      195.   	ret=1;

crypto/bn/bn_mul.c:932:1: Parameter `ctx->depth`
        930.   #endif /* BN_RECURSION */
        931.   
        932. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
        933.   	{
        934.   	int ret=0;

crypto/bn/bn_mul.c:963:2: Call
        961.   	top=al+bl;
        962.   
        963.   	BN_CTX_start(ctx);
                ^
        964.   	if ((r == a) || (r == b))
        965.   		{

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:112:2: Assignment
          110.   	if (ctx->depth < BN_CTX_NUM_POS)
          111.   		ctx->pos[ctx->depth] = ctx->tos;
          112.   	ctx->depth++;
                  ^
          113.   	}
          114.   

crypto/bn/bn_mul.c:1088:2: Call
        1086.   	ret=1;
        1087.   err:
        1088.   	BN_CTX_end(ctx);
                 ^
        1089.   	return(ret);
        1090.   	}

crypto/bn/bn_ctx.c:136:1: <Offset trace>
134.   	}
135.   
136. > void BN_CTX_end(BN_CTX *ctx)
137.   	{
138.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:136:1: Parameter `ctx->depth`
          134.   	}
          135.   
          136. > void BN_CTX_end(BN_CTX *ctx)
          137.   	{
          138.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:147:2: Assignment
          145.   
          146.   	ctx->too_many = 0;
          147.   	ctx->depth--;
                  ^
          148.   	if (ctx->depth < BN_CTX_NUM_POS)
          149.   		ctx->tos = ctx->pos[ctx->depth];

crypto/bn/bn_ctx.c:136:1: <Length trace>
134.   	}
135.   
136. > void BN_CTX_end(BN_CTX *ctx)
137.   	{
138.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:136:1: Parameter `ctx->pos[*]`
          134.   	}
          135.   
          136. > void BN_CTX_end(BN_CTX *ctx)
          137.   	{
          138.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:149:14: Array access: Offset: [-1, +oo] Size: 12 by call to `BN_BLINDING_invert` 
          147.   	ctx->depth--;
          148.   	if (ctx->depth < BN_CTX_NUM_POS)
          149.   		ctx->tos = ctx->pos[ctx->depth];
                              ^
          150.   	}

void BN_CTX_end(BN_CTX *ctx)
	{
	if (ctx == NULL) return;
	assert(ctx->depth > 0);
	if (ctx->depth == 0)
		BN_CTX_start(ctx);
	ctx->too_many = 0;
	ctx->depth--;
	if (ctx->depth < BN_CTX_NUM_POS)
		ctx->tos = ctx->pos[ctx->depth];
	}
['static int RSA_eay_private_decrypt(int flen, const unsigned char *from,\n\t     unsigned char *to, RSA *rsa, int padding)\n\t{\n\tconst RSA_METHOD *meth;\n\tBIGNUM f,ret;\n\tint j,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tmeth = ENGINE_get_RSA(rsa->engine);\n\tBN_init(&f);\n\tBN_init(&ret);\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tif ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (flen > num)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,(int)flen,&f) == NULL) goto err;\n\tif ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))\n\t\tRSA_blinding_on(rsa,ctx);\n\tif (rsa->flags & RSA_FLAG_BLINDING)\n\t\tif (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;\n\tif ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||\n\t\t((rsa->p != NULL) &&\n\t\t(rsa->q != NULL) &&\n\t\t(rsa->dmp1 != NULL) &&\n\t\t(rsa->dmq1 != NULL) &&\n\t\t(rsa->iqmp != NULL)) )\n\t\t{ if (!meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }\n\telse\n\t\t{\n\t\tif (!meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL))\n\t\t\tgoto err;\n\t\t}\n\tif (rsa->flags & RSA_FLAG_BLINDING)\n\t\tif (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err;\n\tp=buf;\n\tj=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);\n\t\tbreak;\n#ifndef NO_SHA\n        case RSA_PKCS1_OAEP_PADDING:\n\t        r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);\n                break;\n#endif\n \tcase RSA_SSLV23_PADDING:\n\t\tr=RSA_padding_check_SSLv23(to,num,buf,j,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,j,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&f);\n\tBN_clear_free(&ret);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)OPENSSL_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_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(n);\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);\n\t\treturn(0);\n\t\t}\n\tif ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)\n\t\t{\n\t\tif (!BN_BLINDING_update(b,ctx))\n\t\t\treturn(0);\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n\tBN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint ret=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tBN_CTX_start(ctx);\n\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_nnmod(r,t,m,ctx)) goto err;\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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n\t{\n\tif (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)\n\t\t{\n\t\tif (!ctx->too_many)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\t\tctx->too_many = 1;\n\t\t\t}\n\t\treturn NULL;\n\t\t}\n\treturn (&(ctx->bn[ctx->tos++]));\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tif (ctx == NULL) return;\n\tassert(ctx->depth > 0);\n\tif (ctx->depth == 0)\n\t\tBN_CTX_start(ctx);\n\tctx->too_many = 0;\n\tctx->depth--;\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->tos = ctx->pos[ctx->depth];\n\t}', 'int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);\n\t\tgoto err;\n\t\t}\n\tif (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;\n\tif (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;\n\tret=1;\nerr:\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\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\tfprintf(stderr,"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\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\trr->neg=a->neg^b->neg;\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 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\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,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tbn_wexpand(tmp_bn,al);\n\t\t\ttmp_bn->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\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tbn_wexpand(tmp_bn,bl);\n\t\t\ttmp_bn->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(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\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#endif\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}']