crypto/dh/dh_key.c:186: error: NULL_DEREFERENCE
  pointer `tmp` last assigned on line 165 could be null and is dereferenced by call to `BN_bn2bin()` at line 186, column 6.
Showing all 41 steps of the trace


crypto/dh/dh_key.c:156:1: start of procedure compute_key()
154.   	}
155.   
156. > static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
157.   	{
158.   	BN_CTX ctx;

crypto/dh/dh_key.c:161:2: 
159.   	BN_MONT_CTX *mont;
160.   	BIGNUM *tmp;
161. > 	int ret= -1;
162.   
163.   	BN_CTX_init(&ctx);

crypto/dh/dh_key.c:163:2: Skipping BN_CTX_init(): empty list of specs
161.   	int ret= -1;
162.   
163.   	BN_CTX_init(&ctx);
        ^
164.   	BN_CTX_start(&ctx);
165.   	tmp = BN_CTX_get(&ctx);

crypto/dh/dh_key.c:164:2: 
162.   
163.   	BN_CTX_init(&ctx);
164. > 	BN_CTX_start(&ctx);
165.   	tmp = BN_CTX_get(&ctx);
166.   	

crypto/bn/bn_ctx.c:108:1: start of procedure BN_CTX_start()
  106.   	}
  107.   
  108. > void BN_CTX_start(BN_CTX *ctx)
  109.   	{
  110.   	if (ctx->depth < BN_CTX_NUM_POS)

crypto/bn/bn_ctx.c:110:6: Taking true branch
  108.   void BN_CTX_start(BN_CTX *ctx)
  109.   	{
  110.   	if (ctx->depth < BN_CTX_NUM_POS)
              ^
  111.   		ctx->pos[ctx->depth] = ctx->tos;
  112.   	ctx->depth++;

crypto/bn/bn_ctx.c:111:3: 
  109.   	{
  110.   	if (ctx->depth < BN_CTX_NUM_POS)
  111. > 		ctx->pos[ctx->depth] = ctx->tos;
  112.   	ctx->depth++;
  113.   	}

crypto/bn/bn_ctx.c:112:2: 
  110.   	if (ctx->depth < BN_CTX_NUM_POS)
  111.   		ctx->pos[ctx->depth] = ctx->tos;
  112. > 	ctx->depth++;
  113.   	}
  114.   

crypto/bn/bn_ctx.c:113:2: return from a call to BN_CTX_start
  111.   		ctx->pos[ctx->depth] = ctx->tos;
  112.   	ctx->depth++;
  113.   	}
          ^
  114.   
  115.   BIGNUM *BN_CTX_get(BN_CTX *ctx)

crypto/dh/dh_key.c:165:2: 
163.   	BN_CTX_init(&ctx);
164.   	BN_CTX_start(&ctx);
165. > 	tmp = BN_CTX_get(&ctx);
166.   	
167.   	if (dh->priv_key == NULL)

crypto/bn/bn_ctx.c:115:1: start of procedure BN_CTX_get()
  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_ctx.c:117:6: Taking false branch
  115.   BIGNUM *BN_CTX_get(BN_CTX *ctx)
  116.   	{
  117.   	if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
              ^
  118.   		{
  119.   		if (!ctx->too_many)

crypto/bn/bn_ctx.c:117:37: Taking true branch
  115.   BIGNUM *BN_CTX_get(BN_CTX *ctx)
  116.   	{
  117.   	if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
                                             ^
  118.   		{
  119.   		if (!ctx->too_many)

crypto/bn/bn_ctx.c:119:8: Taking false branch
  117.   	if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
  118.   		{
  119.   		if (!ctx->too_many)
                ^
  120.   			{
  121.   			BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);

crypto/bn/bn_ctx.c:125:3: 
  123.   			ctx->too_many = 1;
  124.   			}
  125. > 		return NULL;
  126.   		}
  127.   	return (&(ctx->bn[ctx->tos++]));

crypto/bn/bn_ctx.c:128:2: return from a call to BN_CTX_get
  126.   		}
  127.   	return (&(ctx->bn[ctx->tos++]));
  128.   	}
          ^
  129.   
  130.   void BN_CTX_end(BN_CTX *ctx)

crypto/dh/dh_key.c:167:6: Taking false branch
165.   	tmp = BN_CTX_get(&ctx);
166.   	
167.   	if (dh->priv_key == NULL)
            ^
168.   		{
169.   		DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);

crypto/dh/dh_key.c:172:7: Taking true branch
170.   		goto err;
171.   		}
172.   	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
             ^
173.   		{
174.   		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)

crypto/dh/dh_key.c:172:38: Taking true branch
170.   		goto err;
171.   		}
172.   	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
                                            ^
173.   		{
174.   		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)

crypto/dh/dh_key.c:174:7: 
172.   	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
173.   		{
174. > 		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
175.   			if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
176.   				dh->p,&ctx)) goto err;

crypto/bn/bn_mont.c:233:1: start of procedure BN_MONT_CTX_new()
  231.   	}
  232.   
  233. > BN_MONT_CTX *BN_MONT_CTX_new(void)
  234.   	{
  235.   	BN_MONT_CTX *ret;

crypto/bn/bn_mont.c:237:6: 
  235.   	BN_MONT_CTX *ret;
  236.   
  237. > 	if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
  238.   		return(NULL);
  239.   

crypto/mem.c:205:1: start of procedure CRYPTO_malloc()
    203.   	}
    204.   
    205. > void *CRYPTO_malloc(int num, const char *file, int line)
    206.   	{
    207.   	void *ret = NULL;

crypto/mem.c:207:2: 
    205.   void *CRYPTO_malloc(int num, const char *file, int line)
    206.   	{
    207. > 	void *ret = NULL;
    208.   
    209.   	allow_customize = 0;

crypto/mem.c:209:2: 
    207.   	void *ret = NULL;
    208.   
    209. > 	allow_customize = 0;
    210.   	if (malloc_debug_func != NULL)
    211.   		{

crypto/mem.c:210:6: Taking false branch
    208.   
    209.   	allow_customize = 0;
    210.   	if (malloc_debug_func != NULL)
                ^
    211.   		{
    212.   		allow_customize_debug = 0;

crypto/mem.c:215:2: Skipping __function_pointer__(): unresolved function pointer
    213.   		malloc_debug_func(NULL, num, file, line, 0);
    214.   		}
    215.   	ret = malloc_func(num);
            ^
    216.   #ifdef LEVITTE_DEBUG
    217.   	fprintf(stderr, "LEVITTE_DEBUG:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:219:6: Taking false branch
    217.   	fprintf(stderr, "LEVITTE_DEBUG:         > 0x%p (%d)\n", ret, num);
    218.   #endif
    219.   	if (malloc_debug_func != NULL)
                ^
    220.   		malloc_debug_func(ret, num, file, line, 1);
    221.   

crypto/mem.c:222:2: 
    220.   		malloc_debug_func(ret, num, file, line, 1);
    221.   
    222. > 	return ret;
    223.   	}
    224.   

crypto/mem.c:223:2: return from a call to CRYPTO_malloc
    221.   
    222.   	return ret;
    223.   	}
            ^
    224.   
    225.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/bn/bn_mont.c:237:6: Taking true branch
  235.   	BN_MONT_CTX *ret;
  236.   
  237.   	if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
              ^
  238.   		return(NULL);
  239.   

crypto/bn/bn_mont.c:238:3: 
  236.   
  237.   	if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
  238. > 		return(NULL);
  239.   
  240.   	BN_MONT_CTX_init(ret);

crypto/bn/bn_mont.c:243:2: return from a call to BN_MONT_CTX_new
  241.   	ret->flags=BN_FLG_MALLOCED;
  242.   	return(ret);
  243.   	}
          ^
  244.   
  245.   void BN_MONT_CTX_init(BN_MONT_CTX *ctx)

crypto/dh/dh_key.c:174:7: Taking false branch
172.   	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
173.   		{
174.   		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
             ^
175.   			if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
176.   				dh->p,&ctx)) goto err;

crypto/dh/dh_key.c:179:2: 
177.   		}
178.   
179. > 	mont=(BN_MONT_CTX *)dh->method_mont_p;
180.   	if (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
181.   		{

crypto/dh/dh_key.c:180:7: Taking false branch
178.   
179.   	mont=(BN_MONT_CTX *)dh->method_mont_p;
180.   	if (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
             ^
181.   		{
182.   		DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);

crypto/dh/dh_key.c:186:2: 
184.   		}
185.   
186. > 	ret=BN_bn2bin(tmp,key);
187.   err:
188.   	BN_CTX_end(&ctx);

crypto/bn/bn_lib.c:602:1: start of procedure BN_bn2bin()
  600.   
  601.   /* ignore negative */
  602. > int BN_bn2bin(const BIGNUM *a, unsigned char *to)
  603.   	{
  604.   	int n,i;

crypto/bn/bn_lib.c:607:2: 
  605.   	BN_ULONG l;
  606.   
  607. > 	n=i=BN_num_bytes(a);
  608.   	while (i-- > 0)
  609.   		{

crypto/bn/bn_lib.c:238:1: start of procedure BN_num_bits()
    236.   	}
    237.   
    238. > int BN_num_bits(const BIGNUM *a)
    239.   	{
    240.   	BN_ULONG l;

crypto/bn/bn_lib.c:245:6: 
    243.   	bn_check_top(a);
    244.   
    245. > 	if (a->top == 0) return(0);
    246.   	l=a->d[a->top-1];
    247.   	i=(a->top-1)*BN_BITS2;

static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
	{
	BN_CTX ctx;
	BN_MONT_CTX *mont;
	BIGNUM *tmp;
	int ret= -1;
	BN_CTX_init(&ctx);
	BN_CTX_start(&ctx);
	tmp = BN_CTX_get(&ctx);
	if (dh->priv_key == NULL)
		{
		DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
		goto err;
		}
	if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
		{
		if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
			if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
				dh->p,&ctx)) goto err;
		}
	mont=(BN_MONT_CTX *)dh->method_mont_p;
	if (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
		{
		DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
		goto err;
		}
	ret=BN_bn2bin(tmp,key);
err:
	BN_CTX_end(&ctx);
	BN_CTX_free(&ctx);
	return(ret);
	}
['static int compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)\n\t{\n\tBN_CTX ctx;\n\tBN_MONT_CTX *mont;\n\tBIGNUM *tmp;\n\tint ret= -1;\n\tBN_CTX_init(&ctx);\n\tBN_CTX_start(&ctx);\n\ttmp = BN_CTX_get(&ctx);\n\tif (dh->priv_key == NULL)\n\t\t{\n\t\tDHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);\n\t\tgoto err;\n\t\t}\n\tif ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,\n\t\t\t\tdh->p,&ctx)) goto err;\n\t\t}\n\tmont=(BN_MONT_CTX *)dh->method_mont_p;\n\tif (!dh->meth->bn_mod_exp(dh, tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))\n\t\t{\n\t\tDHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);\n\t\tgoto err;\n\t\t}\n\tret=BN_bn2bin(tmp,key);\nerr:\n\tBN_CTX_end(&ctx);\n\tBN_CTX_free(&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}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n\t{\n\tBN_MONT_CTX *ret;\n\tif ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)\n\t\treturn(NULL);\n\tBN_MONT_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = 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_func(num);\n#ifdef LEVITTE_DEBUG\n\tfprintf(stderr, "LEVITTE_DEBUG:         > 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\treturn ret;\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tn=i=BN_num_bytes(a);\n\twhile (i-- > 0)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\ti=(a->top-1)*BN_BITS2;\n\tif (l == 0)\n\t\t{\n#if !defined(NO_STDIO) && !defined(WIN16)\n\t\tfprintf(stderr,"BAD TOP VALUE\\n");\n#endif\n\t\tabort();\n\t\t}\n\treturn(i+BN_num_bits_word(l));\n\t}']