engines/ccgost/gost2001.c:193: error: NULL_DEREFERENCE
  pointer `ctx` last assigned on line 184 could be null and is dereferenced by call to `BN_CTX_start()` at line 193, column 2.
Showing all 45 steps of the trace


engines/ccgost/gost2001.c:181:1: start of procedure gost2001_do_verify()
179.    *
180.    */ 
181. > int gost2001_do_verify(const unsigned char *dgst,int dgst_len,
182.   	DSA_SIG *sig, EC_KEY *ec)
183.   	{

engines/ccgost/gost2001.c:184:2: 
182.   	DSA_SIG *sig, EC_KEY *ec)
183.   	{
184. > 	BN_CTX *ctx=BN_CTX_new();
185.   	const EC_GROUP *group = EC_KEY_get0_group(ec);
186.   	BIGNUM *order;

crypto/bn/bn_ctx.c:214:1: start of procedure BN_CTX_new()
  212.   #endif
  213.   
  214. > BN_CTX *BN_CTX_new(void)
  215.   	{
  216.   	BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));

crypto/bn/bn_ctx.c:216:2: 
  214.   BN_CTX *BN_CTX_new(void)
  215.   	{
  216. > 	BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));
  217.   	if(!ret)
  218.   		{

crypto/mem.c:291:1: start of procedure CRYPTO_malloc()
    289.   	}
    290.   
    291. > void *CRYPTO_malloc(int num, const char *file, int line)
    292.   	{
    293.   	void *ret = NULL;

crypto/mem.c:293:2: 
    291.   void *CRYPTO_malloc(int num, const char *file, int line)
    292.   	{
    293. > 	void *ret = NULL;
    294.   	extern unsigned char cleanse_ctr;
    295.   

crypto/mem.c:296:6: Taking false branch
    294.   	extern unsigned char cleanse_ctr;
    295.   
    296.   	if (num <= 0) return NULL;
                ^
    297.   
    298.   	allow_customize = 0;

crypto/mem.c:298:2: 
    296.   	if (num <= 0) return NULL;
    297.   
    298. > 	allow_customize = 0;
    299.   	if (malloc_debug_func != NULL)
    300.   		{

crypto/mem.c:299:6: Taking true branch
    297.   
    298.   	allow_customize = 0;
    299.   	if (malloc_debug_func != NULL)
                ^
    300.   		{
    301.   		allow_customize_debug = 0;

crypto/mem.c:301:3: 
    299.   	if (malloc_debug_func != NULL)
    300.   		{
    301. > 		allow_customize_debug = 0;
    302.   		malloc_debug_func(NULL, num, file, line, 0);
    303.   		}

crypto/mem.c:302:3: Skipping __function_pointer__(): unresolved function pointer
    300.   		{
    301.   		allow_customize_debug = 0;
    302.   		malloc_debug_func(NULL, num, file, line, 0);
             ^
    303.   		}
    304.   	ret = malloc_ex_func(num,file,line);

crypto/mem.c:304:2: Skipping __function_pointer__(): unresolved function pointer
    302.   		malloc_debug_func(NULL, num, file, line, 0);
    303.   		}
    304.   	ret = malloc_ex_func(num,file,line);
            ^
    305.   #ifdef LEVITTE_DEBUG_MEM
    306.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:308:6: Taking true branch
    306.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
    307.   #endif
    308.   	if (malloc_debug_func != NULL)
                ^
    309.   		malloc_debug_func(ret, num, file, line, 1);
    310.   

crypto/mem.c:309:3: Skipping __function_pointer__(): unresolved function pointer
    307.   #endif
    308.   	if (malloc_debug_func != NULL)
    309.   		malloc_debug_func(ret, num, file, line, 1);
             ^
    310.   
    311.           /* Create a dependency on the value of 'cleanse_ctr' so our memory

crypto/mem.c:314:12: Taking false branch
    312.            * sanitisation function can't be optimised out. NB: We only do
    313.            * this for >2Kb so the overhead doesn't bother us. */
    314.           if(ret && (num > 2048))
                      ^
    315.                   ((unsigned char *)ret)[0] = cleanse_ctr;
    316.   

crypto/mem.c:317:2: 
    315.                   ((unsigned char *)ret)[0] = cleanse_ctr;
    316.   
    317. > 	return ret;
    318.   	}
    319.   

crypto/mem.c:318:2: return from a call to CRYPTO_malloc
    316.   
    317.   	return ret;
    318.   	}
            ^
    319.   
    320.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/bn/bn_ctx.c:217:6: Taking true branch
  215.   	{
  216.   	BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));
  217.   	if(!ret)
              ^
  218.   		{
  219.   		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);

crypto/bn/bn_ctx.c:219:3: 
  217.   	if(!ret)
  218.   		{
  219. > 		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
  220.   		return NULL;
  221.   		}

crypto/err/err.c:679:1: start of procedure ERR_put_error()
    677.   /********************************************************/
    678.   
    679. > void ERR_put_error(int lib, int func, int reason, const char *file,
    680.   	     int line)
    681.   	{

crypto/err/err.c:703:2: Skipping ERR_get_state(): empty list of specs
    701.   	}
    702.   #endif
    703.   	es=ERR_get_state();
            ^
    704.   
    705.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:705:2: 
    703.   	es=ERR_get_state();
    704.   
    705. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
    706.   	if (es->top == es->bottom)
    707.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:706:6: Taking false branch
    704.   
    705.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
    706.   	if (es->top == es->bottom)
                ^
    707.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    708.   	es->err_flags[es->top]=0;

crypto/err/err.c:708:2: 
    706.   	if (es->top == es->bottom)
    707.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    708. > 	es->err_flags[es->top]=0;
    709.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    710.   	es->err_file[es->top]=file;

crypto/err/err.c:709:2: 
    707.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    708.   	es->err_flags[es->top]=0;
    709. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    710.   	es->err_file[es->top]=file;
    711.   	es->err_line[es->top]=line;

crypto/err/err.c:710:2: 
    708.   	es->err_flags[es->top]=0;
    709.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    710. > 	es->err_file[es->top]=file;
    711.   	es->err_line[es->top]=line;
    712.   	err_clear_data(es,es->top);

crypto/err/err.c:711:2: 
    709.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    710.   	es->err_file[es->top]=file;
    711. > 	es->err_line[es->top]=line;
    712.   	err_clear_data(es,es->top);
    713.   	}

crypto/err/err.c:712:2: Taking true branch
    710.   	es->err_file[es->top]=file;
    711.   	es->err_line[es->top]=line;
    712.   	err_clear_data(es,es->top);
            ^
    713.   	}
    714.   

crypto/err/err.c:712:2: Taking false branch
    710.   	es->err_file[es->top]=file;
    711.   	es->err_line[es->top]=line;
    712.   	err_clear_data(es,es->top);
            ^
    713.   	}
    714.   

crypto/err/err.c:712:2: Loop condition is false. Leaving loop
    710.   	es->err_file[es->top]=file;
    711.   	es->err_line[es->top]=line;
    712.   	err_clear_data(es,es->top);
            ^
    713.   	}
    714.   

crypto/err/err.c:713:2: return from a call to ERR_put_error
    711.   	es->err_line[es->top]=line;
    712.   	err_clear_data(es,es->top);
    713.   	}
            ^
    714.   
    715.   void ERR_clear_error(void)

crypto/bn/bn_ctx.c:220:3: 
  218.   		{
  219.   		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
  220. > 		return NULL;
  221.   		}
  222.   	/* Initialise the structure */

crypto/bn/bn_ctx.c:229:2: return from a call to BN_CTX_new
  227.   	ret->too_many = 0;
  228.   	return ret;
  229.   	}
          ^
  230.   
  231.   void BN_CTX_free(BN_CTX *ctx)

engines/ccgost/gost2001.c:185:2: 
183.   	{
184.   	BN_CTX *ctx=BN_CTX_new();
185. > 	const EC_GROUP *group = EC_KEY_get0_group(ec);
186.   	BIGNUM *order;
187.   	BIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;

crypto/ec/ec_key.c:376:1: start of procedure EC_KEY_get0_group()
  374.   	}
  375.   
  376. > const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  377.   	{
  378.   	return key->group;

crypto/ec/ec_key.c:378:2: 
  376.   const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)
  377.   	{
  378. > 	return key->group;
  379.   	}
  380.   

crypto/ec/ec_key.c:379:2: return from a call to EC_KEY_get0_group
  377.   	{
  378.   	return key->group;
  379.   	}
          ^
  380.   
  381.   int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)

engines/ccgost/gost2001.c:187:2: 
185.   	const EC_GROUP *group = EC_KEY_get0_group(ec);
186.   	BIGNUM *order;
187. > 	BIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;
188.   	BIGNUM *X=NULL,*tmp=NULL;
189.   	EC_POINT *C = NULL;

engines/ccgost/gost2001.c:188:2: 
186.   	BIGNUM *order;
187.   	BIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;
188. > 	BIGNUM *X=NULL,*tmp=NULL;
189.   	EC_POINT *C = NULL;
190.   	const EC_POINT *pub_key=NULL;

engines/ccgost/gost2001.c:189:2: 
187.   	BIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;
188.   	BIGNUM *X=NULL,*tmp=NULL;
189. > 	EC_POINT *C = NULL;
190.   	const EC_POINT *pub_key=NULL;
191.   	int ok=0;

engines/ccgost/gost2001.c:190:2: 
188.   	BIGNUM *X=NULL,*tmp=NULL;
189.   	EC_POINT *C = NULL;
190. > 	const EC_POINT *pub_key=NULL;
191.   	int ok=0;
192.   

engines/ccgost/gost2001.c:191:2: 
189.   	EC_POINT *C = NULL;
190.   	const EC_POINT *pub_key=NULL;
191. > 	int ok=0;
192.   
193.   	BN_CTX_start(ctx);

engines/ccgost/gost2001.c:193:2: 
191.   	int ok=0;
192.   
193. > 	BN_CTX_start(ctx);
194.   	order = BN_CTX_get(ctx);
195.   	e = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:255:1: start of procedure BN_CTX_start()
  253.   	}
  254.   
  255. > void BN_CTX_start(BN_CTX *ctx)
  256.   	{
  257.   	CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_ctx.c:259:5: Taking false branch
  257.   	CTXDBG_ENTRY("BN_CTX_start", ctx);
  258.   	/* If we're already overflowing ... */
  259.   	if(ctx->err_stack || ctx->too_many)
             ^
  260.   		ctx->err_stack++;
  261.   	/* (Try to) get a new frame pointer */

int gost2001_do_verify(const unsigned char *dgst,int dgst_len,
	DSA_SIG *sig, EC_KEY *ec)
	{
	BN_CTX *ctx=BN_CTX_new();
	const EC_GROUP *group = EC_KEY_get0_group(ec);
	BIGNUM *order;
	BIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;
	BIGNUM *X=NULL,*tmp=NULL;
	EC_POINT *C = NULL;
	const EC_POINT *pub_key=NULL;
	int ok=0;
	BN_CTX_start(ctx);
	order = BN_CTX_get(ctx);
	e = BN_CTX_get(ctx);
	z1 = BN_CTX_get(ctx);
	z2 = BN_CTX_get(ctx);
	tmp = BN_CTX_get(ctx);
	X= BN_CTX_get(ctx);
	R=BN_CTX_get(ctx);
	v=BN_CTX_get(ctx);
	EC_GROUP_get_order(group,order,ctx);
	pub_key = EC_KEY_get0_public_key(ec);
	if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||
		(BN_cmp(sig->s,order)>=1) || (BN_cmp(sig->r,order)>=1))
		{
		GOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
		goto err;
		}
	md = hashsum2bn(dgst);
	BN_mod(e,md,order,ctx);
#ifdef DEBUG_SIGN
	fprintf(stderr,"digest as bignum: ");
	BN_print_fp(stderr,md);
	fprintf(stderr,"\ndigest mod q: ");
	BN_print_fp(stderr,e);
#endif
	if (BN_is_zero(e)) BN_one(e);
	v=BN_mod_inverse(v,e,order,ctx);
	BN_mod_mul(z1,sig->s,v,order,ctx);
	BN_sub(tmp,order,sig->r);
	BN_mod_mul(z2,tmp,v,order,ctx);
#ifdef DEBUG_SIGN
	fprintf(stderr,"\nInverted digest value: ");
	BN_print_fp(stderr,v);
	fprintf(stderr,"\nz1: ");
	BN_print_fp(stderr,z1);
	fprintf(stderr,"\nz2: ");
	BN_print_fp(stderr,z2);
#endif
	C = EC_POINT_new(group);
	if (!EC_POINT_mul(group,C,z1,pub_key,z2,ctx))
		{
		GOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);
		goto err;
		}
	if (!EC_POINT_get_affine_coordinates_GFp(group,C,X,NULL,ctx))
		{
		GOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);
		goto err;
		}
	BN_mod(R,X,order,ctx);
#ifdef DEBUG_SIGN
	fprintf(stderr,"\nX=");
	BN_print_fp(stderr,X);
	fprintf(stderr,"\nX mod q=");
	BN_print_fp(stderr,R);
	fprintf(stderr,"\n");
#endif
	if (BN_cmp(R,sig->r)!=0)
		{
		GOSTerr(GOST_F_GOST2001_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);
		}
	else
		{
		ok = 1;
		}
	err:
	EC_POINT_free(C);
	BN_CTX_end(ctx);
	BN_CTX_free(ctx);
	BN_free(md);
	return ok;
	}
['int gost2001_do_verify(const unsigned char *dgst,int dgst_len,\n\tDSA_SIG *sig, EC_KEY *ec)\n\t{\n\tBN_CTX *ctx=BN_CTX_new();\n\tconst EC_GROUP *group = EC_KEY_get0_group(ec);\n\tBIGNUM *order;\n\tBIGNUM *md = NULL,*e=NULL,*R=NULL,*v=NULL,*z1=NULL,*z2=NULL;\n\tBIGNUM *X=NULL,*tmp=NULL;\n\tEC_POINT *C = NULL;\n\tconst EC_POINT *pub_key=NULL;\n\tint ok=0;\n\tBN_CTX_start(ctx);\n\torder = BN_CTX_get(ctx);\n\te = BN_CTX_get(ctx);\n\tz1 = BN_CTX_get(ctx);\n\tz2 = BN_CTX_get(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tX= BN_CTX_get(ctx);\n\tR=BN_CTX_get(ctx);\n\tv=BN_CTX_get(ctx);\n\tEC_GROUP_get_order(group,order,ctx);\n\tpub_key = EC_KEY_get0_public_key(ec);\n\tif (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||\n\t\t(BN_cmp(sig->s,order)>=1) || (BN_cmp(sig->r,order)>=1))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n\t\tgoto err;\n\t\t}\n\tmd = hashsum2bn(dgst);\n\tBN_mod(e,md,order,ctx);\n#ifdef DEBUG_SIGN\n\tfprintf(stderr,"digest as bignum: ");\n\tBN_print_fp(stderr,md);\n\tfprintf(stderr,"\\ndigest mod q: ");\n\tBN_print_fp(stderr,e);\n#endif\n\tif (BN_is_zero(e)) BN_one(e);\n\tv=BN_mod_inverse(v,e,order,ctx);\n\tBN_mod_mul(z1,sig->s,v,order,ctx);\n\tBN_sub(tmp,order,sig->r);\n\tBN_mod_mul(z2,tmp,v,order,ctx);\n#ifdef DEBUG_SIGN\n\tfprintf(stderr,"\\nInverted digest value: ");\n\tBN_print_fp(stderr,v);\n\tfprintf(stderr,"\\nz1: ");\n\tBN_print_fp(stderr,z1);\n\tfprintf(stderr,"\\nz2: ");\n\tBN_print_fp(stderr,z2);\n#endif\n\tC = EC_POINT_new(group);\n\tif (!EC_POINT_mul(group,C,z1,pub_key,z2,ctx))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_get_affine_coordinates_GFp(group,C,X,NULL,ctx))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_DO_VERIFY,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tBN_mod(R,X,order,ctx);\n#ifdef DEBUG_SIGN\n\tfprintf(stderr,"\\nX=");\n\tBN_print_fp(stderr,X);\n\tfprintf(stderr,"\\nX mod q=");\n\tBN_print_fp(stderr,R);\n\tfprintf(stderr,"\\n");\n#endif\n\tif (BN_cmp(R,sig->r)!=0)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);\n\t\t}\n\telse\n\t\t{\n\t\tok = 1;\n\t\t}\n\terr:\n\tEC_POINT_free(C);\n\tBN_CTX_end(ctx);\n\tBN_CTX_free(ctx);\n\tBN_free(md);\n\treturn ok;\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));\n\tif(!ret)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tBN_POOL_init(&ret->pool);\n\tBN_STACK_init(&ret->stack);\n\tret->used = 0;\n\tret->err_stack = 0;\n\tret->too_many = 0;\n\treturn ret;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n        if(ret && (num > 2048))\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t     int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'const EC_GROUP *EC_KEY_get0_group(const EC_KEY *key)\n\t{\n\treturn key->group;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}']