crypto/dh/dh_check.c:112: error: BUFFER_OVERRUN_L3
  Offset: [-4, +oo] Size: 13 by call to `BN_is_prime`.
Showing all 15 steps of the trace


crypto/dh/dh_check.c:81:6: Call
79.   
80.   	*ret=0;
81.   	ctx=BN_CTX_new();
           ^
82.   	if (ctx == NULL) goto err;
83.   	q=BN_new();

crypto/bn/bn_lib.c:319:2: Call
  317.   		}
  318.   
  319.   	BN_CTX_init(ret);
          ^
  320.   	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);

crypto/bn/bn_lib.c:327:2: Assignment
    325.   	{
    326.   	memset(ctx,0,sizeof(BN_CTX));
    327.   	ctx->tos=0;
            ^
    328.   	ctx->flags=0;
    329.   	}

crypto/dh/dh_check.c:107:7: Call
105.   		*ret|=DH_UNABLE_TO_CHECK_GENERATOR;
106.   
107.   	if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
             ^
108.   		*ret|=DH_CHECK_P_NOT_PRIME;
109.   	else

crypto/bn/bn_prime.c:210:1: Parameter `ctx_passed->tos`
  208.   	}
  209.   
  210. > int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
  211.   	BN_CTX *ctx_passed, void *cb_arg)
  212.   	{

crypto/bn/bn_prime.c:213:9: Call
  211.   	BN_CTX *ctx_passed, void *cb_arg)
  212.   	{
  213.   	return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
                 ^
  214.   	}
  215.   

crypto/bn/bn_prime.c:216:1: Parameter `ctx_passed->tos`
    214.   	}
    215.   
    216. > int BN_is_prime_fasttest(const BIGNUM *a, int checks,
    217.   		void (*callback)(int,int,void *),
    218.   		BN_CTX *ctx_passed, void *cb_arg,

crypto/dh/dh_check.c:112:8: Call
110.   		{
111.   		if (!BN_rshift1(q,dh->p)) goto err;
112.   		if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
              ^
113.   			*ret|=DH_CHECK_P_NOT_SAFE_PRIME;
114.   		}

crypto/bn/bn_prime.c:210:1: Parameter `ctx_passed->tos`
  208.   	}
  209.   
  210. > int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
  211.   	BN_CTX *ctx_passed, void *cb_arg)
  212.   	{

crypto/bn/bn_prime.c:213:9: Call
  211.   	BN_CTX *ctx_passed, void *cb_arg)
  212.   	{
  213.   	return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
                 ^
  214.   	}
  215.   

crypto/bn/bn_prime.c:216:1: <Offset trace>
214.   	}
215.   
216. > int BN_is_prime_fasttest(const BIGNUM *a, int checks,
217.   		void (*callback)(int,int,void *),
218.   		BN_CTX *ctx_passed, void *cb_arg,

crypto/bn/bn_prime.c:216:1: Parameter `ctx_passed->tos`
    214.   	}
    215.   
    216. > int BN_is_prime_fasttest(const BIGNUM *a, int checks,
    217.   		void (*callback)(int,int,void *),
    218.   		BN_CTX *ctx_passed, void *cb_arg,

crypto/bn/bn_prime.c:216:1: <Length trace>
214.   	}
215.   
216. > int BN_is_prime_fasttest(const BIGNUM *a, int checks,
217.   		void (*callback)(int,int,void *),
218.   		BN_CTX *ctx_passed, void *cb_arg,

crypto/bn/bn_prime.c:216:1: Parameter `ctx_passed->bn[*]`
    214.   	}
    215.   
    216. > int BN_is_prime_fasttest(const BIGNUM *a, int checks,
    217.   		void (*callback)(int,int,void *),
    218.   		BN_CTX *ctx_passed, void *cb_arg,

crypto/bn/bn_prime.c:250:3: Array access: Offset: [-4, +oo] Size: 13 by call to `BN_is_prime` 
    248.   	if (a->neg)
    249.   		{
    250.   		BIGNUM *t = &(ctx->bn[ctx->tos++]);
             ^
    251.   		BN_copy(t, a);
    252.   		t->neg = 0;

int BN_is_prime_fasttest(const BIGNUM *a, int checks,
		void (*callback)(int,int,void *),
		BN_CTX *ctx_passed, void *cb_arg,
		int do_trial_division)
	{
	int i, j, ret = -1;
	int k;
	BN_CTX *ctx = NULL;
	BIGNUM *A1, *A1_odd, *check;
	BN_MONT_CTX *mont = NULL;
	const BIGNUM *A;
	if (checks == BN_prime_checks)
		checks = BN_prime_checks_for_size(BN_num_bits(a));
	if (!BN_is_odd(a))
		return(0);
	if (do_trial_division)
		{
		for (i = 1; i < NUMPRIMES; i++)
			if (BN_mod_word(a, primes[i]) == 0)
				return 0;
		if (callback != NULL) callback(1, -1, cb_arg);
		}
	if (ctx_passed != NULL)
		ctx = ctx_passed;
	else
		if ((ctx=BN_CTX_new()) == NULL)
			goto err;
	if (a->neg)
		{
		BIGNUM *t = &(ctx->bn[ctx->tos++]);
		BN_copy(t, a);
		t->neg = 0;
		A = t;
		}
	else
		A = a;
	A1 = &(ctx->bn[ctx->tos++]);
	A1_odd = &(ctx->bn[ctx->tos++]);
	check = &(ctx->bn[ctx->tos++]);;
	if (!BN_copy(A1, A))
		goto err;
	if (!BN_sub_word(A1, 1))
		goto err;
	if (BN_is_zero(A1))
		{
		ret = 0;
		goto err;
		}
	k = 1;
	while (!BN_is_bit_set(A1, k))
		k++;
	if (!BN_rshift(A1_odd, A1, k))
		goto err;
	mont = BN_MONT_CTX_new();
	if (mont == NULL)
		goto err;
	if (!BN_MONT_CTX_set(mont, A, ctx))
		goto err;
	for (i = 0; i < checks; i++)
		{
		if (!BN_pseudo_rand(check, BN_num_bits(A1), 0, 0))
			goto err;
		if (BN_cmp(check, A1) >= 0)
			if (!BN_sub(check, check, A1))
				goto err;
		if (!BN_add_word(check, 1))
			goto err;
		j = witness(check, A, A1, A1_odd, k, ctx, mont);
		if (j == -1) goto err;
		if (j)
			{
			ret=0;
			goto err;
			}
		if (callback != NULL) callback(1,i,cb_arg);
		}
	ret=1;
err:
	if (ctx_passed != NULL)
		{
		ctx_passed->tos -= 3;
		if (a != A)
			--ctx_passed->tos;
		}
	else if (ctx != NULL)
		BN_CTX_free(ctx);
	if (mont != NULL)
		BN_MONT_CTX_free(mont);
	return(ret);
	}
['int DH_check(DH *dh, int *ret)\n\t{\n\tint ok=0;\n\tBN_CTX *ctx=NULL;\n\tBN_ULONG l;\n\tBIGNUM *q=NULL;\n\t*ret=0;\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tq=BN_new();\n\tif (q == NULL) goto err;\n\tif (BN_is_word(dh->g,DH_GENERATOR_2))\n\t\t{\n\t\tl=BN_mod_word(dh->p,24);\n\t\tif (l != 11) *ret|=DH_NOT_SUITABLE_GENERATOR;\n\t\t}\n#if 0\n\telse if (BN_is_word(dh->g,DH_GENERATOR_3))\n\t\t{\n\t\tl=BN_mod_word(dh->p,12);\n\t\tif (l != 5) *ret|=DH_NOT_SUITABLE_GENERATOR;\n\t\t}\n#endif\n\telse if (BN_is_word(dh->g,DH_GENERATOR_5))\n\t\t{\n\t\tl=BN_mod_word(dh->p,10);\n\t\tif ((l != 3) && (l != 7))\n\t\t\t*ret|=DH_NOT_SUITABLE_GENERATOR;\n\t\t}\n\telse\n\t\t*ret|=DH_UNABLE_TO_CHECK_GENERATOR;\n\tif (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))\n\t\t*ret|=DH_CHECK_P_NOT_PRIME;\n\telse\n\t\t{\n\t\tif (!BN_rshift1(q,dh->p)) goto err;\n\t\tif (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))\n\t\t\t*ret|=DH_CHECK_P_NOT_SAFE_PRIME;\n\t\t}\n\tok=1;\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tif (q != NULL) BN_free(q);\n\treturn(ok);\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\tmemset(ctx,0,sizeof(BN_CTX));\n\tctx->tos=0;\n\tctx->flags=0;\n\t}', 'int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),\n\tBN_CTX *ctx_passed, void *cb_arg)\n\t{\n\treturn BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);\n\t}', 'int BN_is_prime_fasttest(const BIGNUM *a, int checks,\n\t\tvoid (*callback)(int,int,void *),\n\t\tBN_CTX *ctx_passed, void *cb_arg,\n\t\tint do_trial_division)\n\t{\n\tint i, j, ret = -1;\n\tint k;\n\tBN_CTX *ctx = NULL;\n\tBIGNUM *A1, *A1_odd, *check;\n\tBN_MONT_CTX *mont = NULL;\n\tconst BIGNUM *A;\n\tif (checks == BN_prime_checks)\n\t\tchecks = BN_prime_checks_for_size(BN_num_bits(a));\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (do_trial_division)\n\t\t{\n\t\tfor (i = 1; i < NUMPRIMES; i++)\n\t\t\tif (BN_mod_word(a, primes[i]) == 0)\n\t\t\t\treturn 0;\n\t\tif (callback != NULL) callback(1, -1, cb_arg);\n\t\t}\n\tif (ctx_passed != NULL)\n\t\tctx = ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL)\n\t\t\tgoto err;\n\tif (a->neg)\n\t\t{\n\t\tBIGNUM *t = &(ctx->bn[ctx->tos++]);\n\t\tBN_copy(t, a);\n\t\tt->neg = 0;\n\t\tA = t;\n\t\t}\n\telse\n\t\tA = a;\n\tA1 = &(ctx->bn[ctx->tos++]);\n\tA1_odd = &(ctx->bn[ctx->tos++]);\n\tcheck = &(ctx->bn[ctx->tos++]);;\n\tif (!BN_copy(A1, A))\n\t\tgoto err;\n\tif (!BN_sub_word(A1, 1))\n\t\tgoto err;\n\tif (BN_is_zero(A1))\n\t\t{\n\t\tret = 0;\n\t\tgoto err;\n\t\t}\n\tk = 1;\n\twhile (!BN_is_bit_set(A1, k))\n\t\tk++;\n\tif (!BN_rshift(A1_odd, A1, k))\n\t\tgoto err;\n\tmont = BN_MONT_CTX_new();\n\tif (mont == NULL)\n\t\tgoto err;\n\tif (!BN_MONT_CTX_set(mont, A, ctx))\n\t\tgoto err;\n\tfor (i = 0; i < checks; i++)\n\t\t{\n\t\tif (!BN_pseudo_rand(check, BN_num_bits(A1), 0, 0))\n\t\t\tgoto err;\n\t\tif (BN_cmp(check, A1) >= 0)\n\t\t\tif (!BN_sub(check, check, A1))\n\t\t\t\tgoto err;\n\t\tif (!BN_add_word(check, 1))\n\t\t\tgoto err;\n\t\tj = witness(check, A, A1, A1_odd, k, ctx, mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,i,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tif (ctx_passed != NULL)\n\t\t{\n\t\tctx_passed->tos -= 3;\n\t\tif (a != A)\n\t\t\t--ctx_passed->tos;\n\t\t}\n\telse if (ctx != NULL)\n\t\tBN_CTX_free(ctx);\n\tif (mont != NULL)\n\t\tBN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}']