crypto/dsa/dsa_key.c:101: error: BUFFER_OVERRUN_L3
  Offset: [-2, +oo] Size: 12 by call to `BN_mod_exp`.
Showing all 23 steps of the trace


crypto/dsa/dsa_key.c:75:11: Call
73.   	BIGNUM *pub_key=NULL,*priv_key=NULL;
74.   
75.   	if ((ctx=BN_CTX_new()) == NULL) goto err;
                ^
76.   
77.   	if (dsa->priv_key == NULL)

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/dsa/dsa_key.c:101:7: Call
99.   		pub_key=dsa->pub_key;
100.   
101.   	if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;
             ^
102.   
103.   	dsa->priv_key=priv_key;

crypto/bn/bn_exp.c:354:1: Parameter `ctx->depth`
  352.   
  353.   
  354. > int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
  355.   	       BN_CTX *ctx)
  356.   	{

crypto/bn/bn_exp.c:382:8: Call
  380.   			{
  381.   			BN_ULONG A = a->d[0];
  382.   			ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);
                ^
  383.   			}
  384.   		else

crypto/bn/bn_exp.c:656:1: Parameter `ctx->depth`
    654.   	}
    655.   
    656. > int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
    657.                            const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
    658.   	{

crypto/bn/bn_exp.c:684:2: Call
    682.   		return(1);
    683.   		}
    684.   	BN_CTX_start(ctx);
            ^
    685.   	d = BN_CTX_get(ctx);
    686.   	r = BN_CTX_get(ctx);

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_exp.c:685:6: Call
    683.   		}
    684.   	BN_CTX_start(ctx);
    685.   	d = BN_CTX_get(ctx);
                ^
    686.   	r = BN_CTX_get(ctx);
    687.   	t = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:115:1: Parameter `ctx->depth`
      113.   	}
      114.   
      115. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
      116.   	{
      117.   	if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)

crypto/bn/bn_exp.c:686:6: Call
    684.   	BN_CTX_start(ctx);
    685.   	d = BN_CTX_get(ctx);
    686.   	r = BN_CTX_get(ctx);
                ^
    687.   	t = BN_CTX_get(ctx);
    688.   	if (d == NULL || r == NULL || t == NULL) goto err;

crypto/bn/bn_ctx.c:115:1: Parameter `ctx->depth`
      113.   	}
      114.   
      115. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
      116.   	{
      117.   	if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)

crypto/bn/bn_exp.c:687:6: Call
    685.   	d = BN_CTX_get(ctx);
    686.   	r = BN_CTX_get(ctx);
    687.   	t = BN_CTX_get(ctx);
                ^
    688.   	if (d == NULL || r == NULL || t == NULL) goto err;
    689.   

crypto/bn/bn_ctx.c:115:1: Parameter `ctx->depth`
      113.   	}
      114.   
      115. > BIGNUM *BN_CTX_get(BN_CTX *ctx)
      116.   	{
      117.   	if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)

crypto/bn/bn_exp.c:755:2: Call
    753.   err:
    754.   	if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
    755.   	BN_CTX_end(ctx);
            ^
    756.   	return(ret);
    757.   	}

crypto/bn/bn_ctx.c:130:1: <Offset trace>
128.   	}
129.   
130. > void BN_CTX_end(BN_CTX *ctx)
131.   	{
132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:130:1: Parameter `ctx->depth`
      128.   	}
      129.   
      130. > void BN_CTX_end(BN_CTX *ctx)
      131.   	{
      132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:141:2: Assignment
      139.   
      140.   	ctx->too_many = 0;
      141.   	ctx->depth--;
              ^
      142.   	if (ctx->depth < BN_CTX_NUM_POS)
      143.   		ctx->tos = ctx->pos[ctx->depth];

crypto/bn/bn_ctx.c:130:1: <Length trace>
128.   	}
129.   
130. > void BN_CTX_end(BN_CTX *ctx)
131.   	{
132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:130:1: Parameter `ctx->pos[*]`
      128.   	}
      129.   
      130. > void BN_CTX_end(BN_CTX *ctx)
      131.   	{
      132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:143:14: Array access: Offset: [-2, +oo] Size: 12 by call to `BN_mod_exp` 
      141.   	ctx->depth--;
      142.   	if (ctx->depth < BN_CTX_NUM_POS)
      143.   		ctx->tos = ctx->pos[ctx->depth];
                          ^
      144.   	}

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];
	}
['int DSA_generate_key(DSA *dsa)\n\t{\n\tint ok=0;\n\tunsigned int i;\n\tBN_CTX *ctx=NULL;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif (dsa->priv_key == NULL)\n\t\t{\n\t\tif ((priv_key=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tpriv_key=dsa->priv_key;\n\ti=BN_num_bits(dsa->q);\n\tfor (;;)\n\t\t{\n\t\tif (!BN_rand(priv_key,i,1,0))\n\t\t\tgoto err;\n\t\tif (BN_cmp(priv_key,dsa->q) >= 0)\n\t\t\tBN_sub(priv_key,priv_key,dsa->q);\n\t\tif (!BN_is_zero(priv_key)) break;\n\t\t}\n\tif (dsa->pub_key == NULL)\n\t\t{\n\t\tif ((pub_key=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dsa->pub_key;\n\tif (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;\n\tdsa->priv_key=priv_key;\n\tdsa->pub_key=pub_key;\n\tok=1;\nerr:\n\tif ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\treturn(ok);\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_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t       BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#ifdef ATALLA\n\tif(BN_mod_exp_atalla(r,a,p,m))\n\t    return 1;\n\ttried_atalla=1;\n#endif\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n\t\tif (a->top == 1)\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n#ifdef ATALLA\n\ttried_atalla=0;\n#endif\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n                         const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tBN_MONT_CTX *mont = NULL;\n\tint b, bits, ret=0;\n\tBN_ULONG w, next_w;\n\tBIGNUM *d, *r, *t;\n\tBIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n\t\t(BN_mul_word(r, (w)) && \\\n\t\t(BN_ucmp(r, (m)) >= 0 ? \\\n\t\t\t(BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1)) : \\\n\t\t\t1))\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits = BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(rr);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tt = BN_CTX_get(ctx);\n\tif (d == NULL || r == NULL || t == NULL) goto err;\n#ifdef ATALLA\n\tif (!tried_atalla)\n\t\t{\n\t\tBN_set_word(t, a);\n\t\tif (BN_mod_exp_atalla(rr, t, p, m))\n\t\t\t{\n\t\t\tBN_CTX_end(ctx);\n\t\t\treturn 1;\n\t\t\t}\n\t\t}\n#endif\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont = BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont, m, ctx)) goto err;\n\t\t}\n\tif (!BN_to_montgomery(r, BN_value_one(), mont, ctx)) goto err;\n\tw = a;\n\tfor (b = bits-2; b >= 0; b--)\n\t\t{\n\t\tnext_w = w*w;\n\t\tif ((next_w/w) != w)\n\t\t\t{\n\t\t\tif (!BN_MOD_MUL_WORD(r, w, m))\n\t\t\t\tgoto err;\n\t\t\tnext_w = 1;\n\t\t\t}\n\t\tw = next_w;\n\t\tif (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n\t\t\tgoto err;\n\t\tif (BN_is_bit_set(p, b))\n\t\t\t{\n\t\t\tnext_w = w*a;\n\t\t\tif ((next_w/a) != w)\n\t\t\t\t{\n\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m))\n\t\t\t\t\tgoto err;\n\t\t\t\tnext_w = a;\n\t\t\t\t}\n\t\t\tw = next_w;\n\t\t\t}\n\t\t}\n\tif (w != 1)\n\t\t{\n\t\tif (!BN_MOD_MUL_WORD(r, w, m))\n\t\t\tgoto err;\n\t\t}\n\tBN_from_montgomery(rr, r, mont, ctx);\n\tret = 1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\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}']