crypto/rsa/rsa_eay.c:402: error: MEMORY_LEAK
  memory dynamically allocated by call to `BN_CTX_new()` at line 352, column 6 is not reachable after line 402, column 19.
Showing all 36 steps of the trace


crypto/rsa/rsa_eay.c:341:1: start of procedure RSA_eay_public_decrypt()
339.   	}
340.   
341. > static int RSA_eay_public_decrypt(int flen, unsigned char *from,
342.   	     unsigned char *to, RSA *rsa, int padding)
343.   	{

crypto/rsa/rsa_eay.c:345:2: 
343.   	{
344.   	BIGNUM f,ret;
345. > 	int i,num=0,r= -1;
346.   	unsigned char *p;
347.   	unsigned char *buf=NULL;

crypto/rsa/rsa_eay.c:347:2: 
345.   	int i,num=0,r= -1;
346.   	unsigned char *p;
347. > 	unsigned char *buf=NULL;
348.   	BN_CTX *ctx=NULL;
349.   

crypto/rsa/rsa_eay.c:348:2: 
346.   	unsigned char *p;
347.   	unsigned char *buf=NULL;
348. > 	BN_CTX *ctx=NULL;
349.   
350.   	BN_init(&f);

crypto/rsa/rsa_eay.c:350:2: 
348.   	BN_CTX *ctx=NULL;
349.   
350. > 	BN_init(&f);
351.   	BN_init(&ret);
352.   	ctx=BN_CTX_new();

crypto/bn/bn_lib.c:285:1: start of procedure BN_init()
  283.   	}
  284.   
  285. > void BN_init(BIGNUM *a)
  286.   	{
  287.   	memset(a,0,sizeof(BIGNUM));

crypto/bn/bn_lib.c:287:2: 
  285.   void BN_init(BIGNUM *a)
  286.   	{
  287. > 	memset(a,0,sizeof(BIGNUM));
  288.   	}
  289.   

crypto/bn/bn_lib.c:288:2: return from a call to BN_init
  286.   	{
  287.   	memset(a,0,sizeof(BIGNUM));
  288.   	}
          ^
  289.   
  290.   BIGNUM *BN_new(void)

crypto/rsa/rsa_eay.c:351:2: 
349.   
350.   	BN_init(&f);
351. > 	BN_init(&ret);
352.   	ctx=BN_CTX_new();
353.   	if (ctx == NULL) goto err;

crypto/bn/bn_lib.c:285:1: start of procedure BN_init()
  283.   	}
  284.   
  285. > void BN_init(BIGNUM *a)
  286.   	{
  287.   	memset(a,0,sizeof(BIGNUM));

crypto/bn/bn_lib.c:287:2: 
  285.   void BN_init(BIGNUM *a)
  286.   	{
  287. > 	memset(a,0,sizeof(BIGNUM));
  288.   	}
  289.   

crypto/bn/bn_lib.c:288:2: return from a call to BN_init
  286.   	{
  287.   	memset(a,0,sizeof(BIGNUM));
  288.   	}
          ^
  289.   
  290.   BIGNUM *BN_new(void)

crypto/rsa/rsa_eay.c:352:2: 
350.   	BN_init(&f);
351.   	BN_init(&ret);
352. > 	ctx=BN_CTX_new();
353.   	if (ctx == NULL) goto err;
354.   

crypto/bn/bn_lib.c:308:1: start of procedure BN_CTX_new()
  306.   
  307.   
  308. > BN_CTX *BN_CTX_new(void)
  309.   	{
  310.   	BN_CTX *ret;

crypto/bn/bn_lib.c:312:2: 
  310.   	BN_CTX *ret;
  311.   
  312. > 	ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
  313.   	if (ret == NULL)
  314.   		{

crypto/bn/bn_lib.c:313:6: Taking false branch
  311.   
  312.   	ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
  313.   	if (ret == NULL)
              ^
  314.   		{
  315.   		BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);

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

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

crypto/bn/bn_lib.c:321:2: 
  319.   	BN_CTX_init(ret);
  320.   	ret->flags=BN_FLG_MALLOCED;
  321. > 	return(ret);
  322.   	}
  323.   

crypto/bn/bn_lib.c:322:2: return from a call to BN_CTX_new
  320.   	ret->flags=BN_FLG_MALLOCED;
  321.   	return(ret);
  322.   	}
          ^
  323.   
  324.   void BN_CTX_init(BN_CTX *ctx)

crypto/rsa/rsa_eay.c:353:6: Taking false branch
351.   	BN_init(&ret);
352.   	ctx=BN_CTX_new();
353.   	if (ctx == NULL) goto err;
            ^
354.   
355.   	num=BN_num_bytes(rsa->n);

crypto/rsa/rsa_eay.c:355:2: 
353.   	if (ctx == NULL) goto err;
354.   
355. > 	num=BN_num_bytes(rsa->n);
356.   	buf=(unsigned char *)Malloc(num);
357.   	if (buf == NULL)

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

crypto/bn/bn_lib.c:245:6: Taking false branch
  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;

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

crypto/bn/bn_lib.c:247:2: 
  245.   	if (a->top == 0) return(0);
  246.   	l=a->d[a->top-1];
  247. > 	i=(a->top-1)*BN_BITS2;
  248.   	if (l == 0)
  249.   		{

crypto/bn/bn_lib.c:248:6: Taking false branch
  246.   	l=a->d[a->top-1];
  247.   	i=(a->top-1)*BN_BITS2;
  248.   	if (l == 0)
              ^
  249.   		{
  250.   #if !defined(NO_STDIO) && !defined(WIN16)

crypto/bn/bn_lib.c:255:2: Skipping BN_num_bits_word(): empty list of specs
  253.   		abort();
  254.   		}
  255.   	return(i+BN_num_bits_word(l));
          ^
  256.   	}
  257.   

crypto/bn/bn_lib.c:256:2: return from a call to BN_num_bits
  254.   		}
  255.   	return(i+BN_num_bits_word(l));
  256.   	}
          ^
  257.   
  258.   void BN_clear_free(BIGNUM *a)

crypto/rsa/rsa_eay.c:356:2: 
354.   
355.   	num=BN_num_bytes(rsa->n);
356. > 	buf=(unsigned char *)Malloc(num);
357.   	if (buf == NULL)
358.   		{

crypto/rsa/rsa_eay.c:357:6: Taking false branch
355.   	num=BN_num_bytes(rsa->n);
356.   	buf=(unsigned char *)Malloc(num);
357.   	if (buf == NULL)
            ^
358.   		{
359.   		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);

crypto/rsa/rsa_eay.c:365:6: Taking false branch
363.   	/* This check was for equallity but PGP does evil things
364.   	 * and chops off the top '0' bytes */
365.   	if (flen > num)
            ^
366.   		{
367.   		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);

crypto/rsa/rsa_eay.c:371:6: Taking true branch
369.   		}
370.   
371.   	if (BN_bin2bn(from,flen,&f) == NULL) goto err;
            ^
372.   	/* do the decrypt */
373.   	if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))

crypto/rsa/rsa_eay.c:401:1: 
399.   		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
400.   
401. > err:
402.   	if (ctx != NULL) BN_CTX_free(ctx);
403.   	BN_clear_free(&f);

crypto/rsa/rsa_eay.c:402:6: Taking true branch
400.   
401.   err:
402.   	if (ctx != NULL) BN_CTX_free(ctx);
            ^
403.   	BN_clear_free(&f);
404.   	BN_clear_free(&ret);

crypto/rsa/rsa_eay.c:402:19: Skipping BN_CTX_free(): empty list of specs
400.   
401.   err:
402.   	if (ctx != NULL) BN_CTX_free(ctx);
                         ^
403.   	BN_clear_free(&f);
404.   	BN_clear_free(&ret);

static int RSA_eay_public_decrypt(int flen, unsigned char *from,
	     unsigned char *to, RSA *rsa, int padding)
	{
	BIGNUM f,ret;
	int i,num=0,r= -1;
	unsigned char *p;
	unsigned char *buf=NULL;
	BN_CTX *ctx=NULL;
	BN_init(&f);
	BN_init(&ret);
	ctx=BN_CTX_new();
	if (ctx == NULL) goto err;
	num=BN_num_bytes(rsa->n);
	buf=(unsigned char *)Malloc(num);
	if (buf == NULL)
		{
		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
		goto err;
		}
	if (flen > num)
		{
		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
		goto err;
		}
	if (BN_bin2bn(from,flen,&f) == NULL) goto err;
	if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
		{
		if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
			if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
			    goto err;
		}
	if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
		rsa->_method_mod_n)) goto err;
	p=buf;
	i=BN_bn2bin(&ret,p);
	switch (padding)
		{
	case RSA_PKCS1_PADDING:
		r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
		break;
	case RSA_NO_PADDING:
		r=RSA_padding_check_none(to,num,buf,i,num);
		break;
	default:
		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
		goto err;
		}
	if (r < 0)
		RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
err:
	if (ctx != NULL) BN_CTX_free(ctx);
	BN_clear_free(&f);
	BN_clear_free(&ret);
	if (buf != NULL)
		{
		memset(buf,0,num);
		Free(buf);
		}
	return(r);
	}
['static int RSA_eay_public_decrypt(int flen, unsigned char *from,\n\t     unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM f,ret;\n\tint i,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tBN_init(&f);\n\tBN_init(&ret);\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tbuf=(unsigned char *)Malloc(num);\n\tif (buf == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (flen > num)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,flen,&f) == NULL) goto err;\n\tif ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))\n\t\t{\n\t\tif ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))\n\t\t\t    goto err;\n\t\t}\n\tif (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tp=buf;\n\ti=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,i,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&f);\n\tBN_clear_free(&ret);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tFree(buf);\n\t\t}\n\treturn(r);\n\t}', 'void BN_init(BIGNUM *a)\n\t{\n\tmemset(a,0,sizeof(BIGNUM));\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}', 'int BN_num_bits(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}']