crypto/ec/ec_check.c:116: error: NULL_DEREFERENCE
  pointer `ctx` last assigned on line 68 could be null and is dereferenced by call to `BN_CTX_end()` at line 116, column 2.
Showing all 55 steps of the trace


crypto/ec/ec_check.c:59:1: start of procedure EC_GROUP_check()
57.   #include <openssl/err.h>
58.   
59. > int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
60.   	{
61.   	int ret = 0;

crypto/ec/ec_check.c:61:2: 
59.   int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
60.   	{
61. > 	int ret = 0;
62.   	BIGNUM *order;
63.   	BN_CTX *new_ctx = NULL;

crypto/ec/ec_check.c:63:2: 
61.   	int ret = 0;
62.   	BIGNUM *order;
63. > 	BN_CTX *new_ctx = NULL;
64.   	EC_POINT *point = NULL;
65.   

crypto/ec/ec_check.c:64:2: 
62.   	BIGNUM *order;
63.   	BN_CTX *new_ctx = NULL;
64. > 	EC_POINT *point = NULL;
65.   
66.   	if (ctx == NULL)

crypto/ec/ec_check.c:66:6: Taking true branch
64.   	EC_POINT *point = NULL;
65.   
66.   	if (ctx == NULL)
           ^
67.   		{
68.   		ctx = new_ctx = BN_CTX_new();

crypto/ec/ec_check.c:68:3: 
66.   	if (ctx == NULL)
67.   		{
68. > 		ctx = new_ctx = BN_CTX_new();
69.   		if (ctx == NULL)
70.   			{

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

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

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:220:6: Taking true branch
  218.   	{
  219.   	BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));
  220.   	if(!ret)
              ^
  221.   		{
  222.   		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);

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

crypto/err/err.c:664:1: start of procedure ERR_put_error()
    662.   /********************************************************/
    663.   
    664. > void ERR_put_error(int lib, int func, int reason, const char *file,
    665.   	     int line)
    666.   	{

crypto/err/err.c:688:2: Skipping ERR_get_state(): empty list of specs
    686.   	}
    687.   #endif
    688.   	es=ERR_get_state();
            ^
    689.   
    690.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:690:2: 
    688.   	es=ERR_get_state();
    689.   
    690. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
    691.   	if (es->top == es->bottom)
    692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:691:6: Taking false branch
    689.   
    690.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
    691.   	if (es->top == es->bottom)
                ^
    692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    693.   	es->err_flags[es->top]=0;

crypto/err/err.c:693:2: 
    691.   	if (es->top == es->bottom)
    692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    693. > 	es->err_flags[es->top]=0;
    694.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    695.   	es->err_file[es->top]=file;

crypto/err/err.c:694:2: 
    692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    693.   	es->err_flags[es->top]=0;
    694. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    695.   	es->err_file[es->top]=file;
    696.   	es->err_line[es->top]=line;

crypto/err/err.c:695:2: 
    693.   	es->err_flags[es->top]=0;
    694.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    695. > 	es->err_file[es->top]=file;
    696.   	es->err_line[es->top]=line;
    697.   	err_clear_data(es,es->top);

crypto/err/err.c:696:2: 
    694.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    695.   	es->err_file[es->top]=file;
    696. > 	es->err_line[es->top]=line;
    697.   	err_clear_data(es,es->top);
    698.   	}

crypto/err/err.c:697:2: Taking true branch
    695.   	es->err_file[es->top]=file;
    696.   	es->err_line[es->top]=line;
    697.   	err_clear_data(es,es->top);
            ^
    698.   	}
    699.   

crypto/err/err.c:697:2: Taking false branch
    695.   	es->err_file[es->top]=file;
    696.   	es->err_line[es->top]=line;
    697.   	err_clear_data(es,es->top);
            ^
    698.   	}
    699.   

crypto/err/err.c:697:2: Loop condition is false. Leaving loop
    695.   	es->err_file[es->top]=file;
    696.   	es->err_line[es->top]=line;
    697.   	err_clear_data(es,es->top);
            ^
    698.   	}
    699.   

crypto/err/err.c:698:2: return from a call to ERR_put_error
    696.   	es->err_line[es->top]=line;
    697.   	err_clear_data(es,es->top);
    698.   	}
            ^
    699.   
    700.   void ERR_clear_error(void)

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

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

crypto/ec/ec_check.c:69:7: Taking true branch
67.   		{
68.   		ctx = new_ctx = BN_CTX_new();
69.   		if (ctx == NULL)
            ^
70.   			{
71.   			ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);

crypto/ec/ec_check.c:71:4: 
69.   		if (ctx == NULL)
70.   			{
71. > 			ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);
72.   			goto err;
73.   			}

crypto/err/err.c:664:1: start of procedure ERR_put_error()
  662.   /********************************************************/
  663.   
  664. > void ERR_put_error(int lib, int func, int reason, const char *file,
  665.   	     int line)
  666.   	{

crypto/err/err.c:688:2: Skipping ERR_get_state(): empty list of specs
  686.   	}
  687.   #endif
  688.   	es=ERR_get_state();
          ^
  689.   
  690.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:690:2: 
  688.   	es=ERR_get_state();
  689.   
  690. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
  691.   	if (es->top == es->bottom)
  692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:691:6: Taking false branch
  689.   
  690.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
  691.   	if (es->top == es->bottom)
              ^
  692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
  693.   	es->err_flags[es->top]=0;

crypto/err/err.c:693:2: 
  691.   	if (es->top == es->bottom)
  692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
  693. > 	es->err_flags[es->top]=0;
  694.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  695.   	es->err_file[es->top]=file;

crypto/err/err.c:694:2: 
  692.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
  693.   	es->err_flags[es->top]=0;
  694. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  695.   	es->err_file[es->top]=file;
  696.   	es->err_line[es->top]=line;

crypto/err/err.c:695:2: 
  693.   	es->err_flags[es->top]=0;
  694.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  695. > 	es->err_file[es->top]=file;
  696.   	es->err_line[es->top]=line;
  697.   	err_clear_data(es,es->top);

crypto/err/err.c:696:2: 
  694.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
  695.   	es->err_file[es->top]=file;
  696. > 	es->err_line[es->top]=line;
  697.   	err_clear_data(es,es->top);
  698.   	}

crypto/err/err.c:697:2: Taking true branch
  695.   	es->err_file[es->top]=file;
  696.   	es->err_line[es->top]=line;
  697.   	err_clear_data(es,es->top);
          ^
  698.   	}
  699.   

crypto/err/err.c:697:2: Taking false branch
  695.   	es->err_file[es->top]=file;
  696.   	es->err_line[es->top]=line;
  697.   	err_clear_data(es,es->top);
          ^
  698.   	}
  699.   

crypto/err/err.c:697:2: Loop condition is false. Leaving loop
  695.   	es->err_file[es->top]=file;
  696.   	es->err_line[es->top]=line;
  697.   	err_clear_data(es,es->top);
          ^
  698.   	}
  699.   

crypto/err/err.c:698:2: return from a call to ERR_put_error
  696.   	es->err_line[es->top]=line;
  697.   	err_clear_data(es,es->top);
  698.   	}
          ^
  699.   
  700.   void ERR_clear_error(void)

crypto/ec/ec_check.c:115:1: 
113.   	ret = 1;
114.   
115. > err:
116.   	BN_CTX_end(ctx);
117.   	if (new_ctx != NULL)

crypto/ec/ec_check.c:116:2: 
114.   
115.   err:
116. > 	BN_CTX_end(ctx);
117.   	if (new_ctx != NULL)
118.   		BN_CTX_free(new_ctx);

crypto/bn/bn_ctx.c:270:1: start of procedure BN_CTX_end()
  268.   	}
  269.   
  270. > void BN_CTX_end(BN_CTX *ctx)
  271.   	{
  272.   	CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:273:5: Taking true branch
  271.   	{
  272.   	CTXDBG_ENTRY("BN_CTX_end", ctx);
  273.   	if(ctx->err_stack)
             ^
  274.   		ctx->err_stack--;
  275.   	else

int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
	{
	int ret = 0;
	BIGNUM *order;
	BN_CTX *new_ctx = NULL;
	EC_POINT *point = NULL;
	if (ctx == NULL)
		{
		ctx = new_ctx = BN_CTX_new();
		if (ctx == NULL)
			{
			ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);
			goto err;
			}
		}
	BN_CTX_start(ctx);
	if ((order = BN_CTX_get(ctx)) == NULL) goto err;
	if (!EC_GROUP_check_discriminant(group, ctx))
		{
		ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);
		goto err;
		}
	if (group->generator == NULL)
		{
		ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);
		goto err;
		}
	if (!EC_POINT_is_on_curve(group, group->generator, ctx))
		{
		ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);
		goto err;
		}
	if ((point = EC_POINT_new(group)) == NULL) goto err;
	if (!EC_GROUP_get_order(group, order, ctx)) goto err;
	if (BN_is_zero(order))
		{
		ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);
		goto err;
		}
	if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) goto err;
	if (!EC_POINT_is_at_infinity(group, point))
		{
		ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);
		goto err;
		}
	ret = 1;
err:
	BN_CTX_end(ctx);
	if (new_ctx != NULL)
		BN_CTX_free(new_ctx);
	if (point)
		EC_POINT_free(point);
	return ret;
	}
['int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *order;\n\tBN_CTX *new_ctx = NULL;\n\tEC_POINT *point = NULL;\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((order = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!EC_GROUP_check_discriminant(group, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);\n\t\tgoto err;\n\t\t}\n\tif (group->generator == NULL)\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_is_on_curve(group, group->generator, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);\n\t\tgoto err;\n\t\t}\n\tif ((point = EC_POINT_new(group)) == NULL) goto err;\n\tif (!EC_GROUP_get_order(group, order, ctx)) goto err;\n\tif (BN_is_zero(order))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) goto err;\n\tif (!EC_POINT_is_at_infinity(group, point))\n\t\t{\n\t\tECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);\n\t\tgoto err;\n\t\t}\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\tif (point)\n\t\tEC_POINT_free(point);\n\treturn ret;\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}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}']