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


engines/ccgost/gost_sign.c:135:1: start of procedure gost_do_verify()
133.    */
134.   
135. > int gost_do_verify(const unsigned char *dgst, int dgst_len,
136.   	DSA_SIG *sig, DSA *dsa)
137.   	{

engines/ccgost/gost_sign.c:138:2: 
136.   	DSA_SIG *sig, DSA *dsa)
137.   	{
138. > 	BIGNUM *md, *tmp=NULL;
139.   	BIGNUM *q2=NULL;
140.   	BIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;

engines/ccgost/gost_sign.c:139:2: 
137.   	{
138.   	BIGNUM *md, *tmp=NULL;
139. > 	BIGNUM *q2=NULL;
140.   	BIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;
141.   	BIGNUM *tmp2=NULL,*tmp3=NULL;

engines/ccgost/gost_sign.c:140:2: 
138.   	BIGNUM *md, *tmp=NULL;
139.   	BIGNUM *q2=NULL;
140. > 	BIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;
141.   	BIGNUM *tmp2=NULL,*tmp3=NULL;
142.   	int ok;

engines/ccgost/gost_sign.c:141:2: 
139.   	BIGNUM *q2=NULL;
140.   	BIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;
141. > 	BIGNUM *tmp2=NULL,*tmp3=NULL;
142.   	int ok;
143.   	BN_CTX *ctx = BN_CTX_new();

engines/ccgost/gost_sign.c:143:2: 
141.   	BIGNUM *tmp2=NULL,*tmp3=NULL;
142.   	int ok;
143. > 	BN_CTX *ctx = BN_CTX_new();
144.   
145.   	BN_CTX_start(ctx);

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:294:1: start of procedure CRYPTO_malloc()
    292.   	}
    293.   
    294. > void *CRYPTO_malloc(int num, const char *file, int line)
    295.   	{
    296.   	void *ret = NULL;

crypto/mem.c:296:2: 
    294.   void *CRYPTO_malloc(int num, const char *file, int line)
    295.   	{
    296. > 	void *ret = NULL;
    297.   
    298.   	if (num <= 0) return NULL;

crypto/mem.c:298:6: Taking false branch
    296.   	void *ret = NULL;
    297.   
    298.   	if (num <= 0) return NULL;
                ^
    299.   
    300.   	allow_customize = 0;

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

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

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

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

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

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

crypto/mem.c:311:3: Skipping __function_pointer__(): unresolved function pointer
    309.   #endif
    310.   	if (malloc_debug_func != NULL)
    311.   		malloc_debug_func(ret, num, file, line, 1);
             ^
    312.   
    313.   #ifndef OPENSSL_CPUID_OBJ

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

crypto/mem.c:323:2: 
    321.   #endif
    322.   
    323. > 	return ret;
    324.   	}
    325.   

crypto/mem.c:324:2: return from a call to CRYPTO_malloc
    322.   
    323.   	return ret;
    324.   	}
            ^
    325.   
    326.   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:706:1: start of procedure ERR_put_error()
    704.   /********************************************************/
    705.   
    706. > void ERR_put_error(int lib, int func, int reason, const char *file,
    707.   	     int line)
    708.   	{

crypto/err/err.c:730:2: Skipping ERR_get_state(): empty list of specs
    728.   	}
    729.   #endif
    730.   	es=ERR_get_state();
            ^
    731.   
    732.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:732:2: 
    730.   	es=ERR_get_state();
    731.   
    732. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
    733.   	if (es->top == es->bottom)
    734.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:733:6: Taking false branch
    731.   
    732.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
    733.   	if (es->top == es->bottom)
                ^
    734.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    735.   	es->err_flags[es->top]=0;

crypto/err/err.c:735:2: 
    733.   	if (es->top == es->bottom)
    734.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    735. > 	es->err_flags[es->top]=0;
    736.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    737.   	es->err_file[es->top]=file;

crypto/err/err.c:736:2: 
    734.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    735.   	es->err_flags[es->top]=0;
    736. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    737.   	es->err_file[es->top]=file;
    738.   	es->err_line[es->top]=line;

crypto/err/err.c:737:2: 
    735.   	es->err_flags[es->top]=0;
    736.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    737. > 	es->err_file[es->top]=file;
    738.   	es->err_line[es->top]=line;
    739.   	err_clear_data(es,es->top);

crypto/err/err.c:738:2: 
    736.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    737.   	es->err_file[es->top]=file;
    738. > 	es->err_line[es->top]=line;
    739.   	err_clear_data(es,es->top);
    740.   	}

crypto/err/err.c:739:2: Taking true branch
    737.   	es->err_file[es->top]=file;
    738.   	es->err_line[es->top]=line;
    739.   	err_clear_data(es,es->top);
            ^
    740.   	}
    741.   

crypto/err/err.c:739:2: Taking false branch
    737.   	es->err_file[es->top]=file;
    738.   	es->err_line[es->top]=line;
    739.   	err_clear_data(es,es->top);
            ^
    740.   	}
    741.   

crypto/err/err.c:739:2: Loop condition is false. Leaving loop
    737.   	es->err_file[es->top]=file;
    738.   	es->err_line[es->top]=line;
    739.   	err_clear_data(es,es->top);
            ^
    740.   	}
    741.   

crypto/err/err.c:740:2: return from a call to ERR_put_error
    738.   	es->err_line[es->top]=line;
    739.   	err_clear_data(es,es->top);
    740.   	}
            ^
    741.   
    742.   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/gost_sign.c:145:2: 
143.   	BN_CTX *ctx = BN_CTX_new();
144.   
145. > 	BN_CTX_start(ctx);
146.   	if (BN_cmp(sig->s,dsa->q)>=1||
147.   		BN_cmp(sig->r,dsa->q)>=1)

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 gost_do_verify(const unsigned char *dgst, int dgst_len,
	DSA_SIG *sig, DSA *dsa)
	{
	BIGNUM *md, *tmp=NULL;
	BIGNUM *q2=NULL;
	BIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;
	BIGNUM *tmp2=NULL,*tmp3=NULL;
	int ok;
	BN_CTX *ctx = BN_CTX_new();
	BN_CTX_start(ctx);
	if (BN_cmp(sig->s,dsa->q)>=1||
		BN_cmp(sig->r,dsa->q)>=1)
		{
		GOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);
		return 0;
		}
	md=hashsum2bn(dgst);
	tmp=BN_CTX_get(ctx);
	v=BN_CTX_get(ctx);
	q2=BN_CTX_get(ctx);
	z1=BN_CTX_get(ctx);
	z2=BN_CTX_get(ctx);
	tmp2=BN_CTX_get(ctx);
	tmp3=BN_CTX_get(ctx);
	u = BN_CTX_get(ctx);
	BN_mod(tmp,md,dsa->q,ctx);
	if (BN_is_zero(tmp))
		{
		BN_one(md);
		}
	BN_copy(q2,dsa->q);
	BN_sub_word(q2,2);
	BN_mod_exp(v,md,q2,dsa->q,ctx);
	BN_mod_mul(z1,sig->s,v,dsa->q,ctx);
	BN_sub(tmp,dsa->q,sig->r);
	BN_mod_mul(z2,tmp,v,dsa->p,ctx);
	BN_mod_exp(tmp,dsa->g,z1,dsa->p,ctx);
	BN_mod_exp(tmp2,dsa->pub_key,z2,dsa->p,ctx);
	BN_mod_mul(tmp3,tmp,tmp2,dsa->p,ctx);
	BN_mod(u,tmp3,dsa->q,ctx);
	ok= BN_cmp(u,sig->r);
	BN_free(md);
	BN_CTX_end(ctx);
	BN_CTX_free(ctx);
	if (ok!=0)
		{
		GOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);
		}
	return (ok==0);
	}
['int gost_do_verify(const unsigned char *dgst, int dgst_len,\n\tDSA_SIG *sig, DSA *dsa)\n\t{\n\tBIGNUM *md, *tmp=NULL;\n\tBIGNUM *q2=NULL;\n\tBIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;\n\tBIGNUM *tmp2=NULL,*tmp3=NULL;\n\tint ok;\n\tBN_CTX *ctx = BN_CTX_new();\n\tBN_CTX_start(ctx);\n\tif (BN_cmp(sig->s,dsa->q)>=1||\n\t\tBN_cmp(sig->r,dsa->q)>=1)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n\t\treturn 0;\n\t\t}\n\tmd=hashsum2bn(dgst);\n\ttmp=BN_CTX_get(ctx);\n\tv=BN_CTX_get(ctx);\n\tq2=BN_CTX_get(ctx);\n\tz1=BN_CTX_get(ctx);\n\tz2=BN_CTX_get(ctx);\n\ttmp2=BN_CTX_get(ctx);\n\ttmp3=BN_CTX_get(ctx);\n\tu = BN_CTX_get(ctx);\n\tBN_mod(tmp,md,dsa->q,ctx);\n\tif (BN_is_zero(tmp))\n\t\t{\n\t\tBN_one(md);\n\t\t}\n\tBN_copy(q2,dsa->q);\n\tBN_sub_word(q2,2);\n\tBN_mod_exp(v,md,q2,dsa->q,ctx);\n\tBN_mod_mul(z1,sig->s,v,dsa->q,ctx);\n\tBN_sub(tmp,dsa->q,sig->r);\n\tBN_mod_mul(z2,tmp,v,dsa->p,ctx);\n\tBN_mod_exp(tmp,dsa->g,z1,dsa->p,ctx);\n\tBN_mod_exp(tmp2,dsa->pub_key,z2,dsa->p,ctx);\n\tBN_mod_mul(tmp3,tmp,tmp2,dsa->p,ctx);\n\tBN_mod(u,tmp3,dsa->q,ctx);\n\tok= BN_cmp(u,sig->r);\n\tBN_free(md);\n\tBN_CTX_end(ctx);\n\tBN_CTX_free(ctx);\n\tif (ok!=0)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);\n\t\t}\n\treturn (ok==0);\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\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#ifndef OPENSSL_CPUID_OBJ\n        if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\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}', '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}']