crypto/rsa/rsa_eay.c:559: error: INTEGER_OVERFLOW_L2
  ([0, `rsa->n->top`] - 1):unsigned64 by call to `BN_MONT_CTX_set_locked`.
Showing all 13 steps of the trace


crypto/rsa/rsa_eay.c:480:1: Parameter `rsa->n->top`
478.   	}
479.   
480. > static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
481.   	     unsigned char *to, RSA *rsa, int padding)
482.   	{

crypto/rsa/rsa_eay.c:496:8: Call
494.   	br  = BN_CTX_get(ctx);
495.   	ret = BN_CTX_get(ctx);
496.   	num = BN_num_bytes(rsa->n);
              ^
497.   	buf = OPENSSL_malloc(num);
498.   	if(!f || !ret || !buf)

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
  246.   	}
  247.   
  248. > int BN_num_bits(const BIGNUM *a)
  249.   	{
  250.   	int i = a->top - 1;

crypto/rsa/rsa_eay.c:559:9: Call
557.   
558.   		if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
559.   			if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
               ^
560.   				goto err;
561.   		if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,

crypto/bn/bn_mont.c:536:1: Parameter `mod->top`
  534.   	}
  535.   
  536. > BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
  537.   					const BIGNUM *mod, BN_CTX *ctx)
  538.   	{

crypto/bn/bn_mont.c:552:16: Call
  550.   			{
  551.   			ret = BN_MONT_CTX_new();
  552.   			if (ret && !BN_MONT_CTX_set(ret, mod, ctx))
                        ^
  553.   				BN_MONT_CTX_free(ret);
  554.   			else

crypto/bn/bn_mont.c:413:1: Parameter `mod->top`
    411.   	}
    412.   
    413. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
    414.   	{
    415.   	int ret = 0;

crypto/bn/bn_mont.c:421:7: Call
    419.   	if((Ri = BN_CTX_get(ctx)) == NULL) goto err;
    420.   	R= &(mont->RR);					/* grab RR as a temp */
    421.   	if (!BN_copy(&(mont->N),mod)) goto err;		/* Set N */
                 ^
    422.   	mont->N.neg = 0;
    423.   

crypto/bn/bn_lib.c:497:1: Parameter `a->dmax`
      495.   	}
      496.   
      497. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      498.   	{
      499.   	int i;

crypto/bn/bn_mont.c:434:13: Call
    432.   		tmod.neg=0;
    433.   
    434.   		mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
                       ^
    435.   
    436.   #if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)

crypto/bn/bn_lib.c:248:1: <LHS trace>
246.   	}
247.   
248. > int BN_num_bits(const BIGNUM *a)
249.   	{
250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
      246.   	}
      247.   
      248. > int BN_num_bits(const BIGNUM *a)
      249.   	{
      250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:250:2: Binary operation: ([0, rsa->n->top] - 1):unsigned64 by call to `BN_MONT_CTX_set_locked` 
      248.   int BN_num_bits(const BIGNUM *a)
      249.   	{
      250.   	int i = a->top - 1;
              ^
      251.   	bn_check_top(a);
      252.   

int BN_num_bits(const BIGNUM *a)
	{
	int i = a->top - 1;
	bn_check_top(a);
	if (BN_is_zero(a)) return 0;
	return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
	}
['static int RSA_eay_private_decrypt(int flen, const unsigned char *from,\n\t     unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM *f, *ret, *br;\n\tint j,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tint local_blinding = 0;\n\tBN_BLINDING *blinding = NULL;\n\tif((ctx = BN_CTX_new()) == NULL) goto err;\n\tBN_CTX_start(ctx);\n\tf   = BN_CTX_get(ctx);\n\tbr  = BN_CTX_get(ctx);\n\tret = BN_CTX_get(ctx);\n\tnum = BN_num_bytes(rsa->n);\n\tbuf = OPENSSL_malloc(num);\n\tif(!f || !ret || !buf)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_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_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,(int)flen,f) == NULL) goto err;\n\tif (BN_ucmp(f, rsa->n) >= 0)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n\t\tgoto err;\n\t\t}\n\tif (!(rsa->flags & RSA_FLAG_NO_BLINDING))\n\t\t{\n\t\tblinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n\t\tif (blinding == NULL)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (blinding != NULL)\n\t\tif (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))\n\t\t\tgoto err;\n\tif ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||\n\t\t((rsa->p != NULL) &&\n\t\t(rsa->q != NULL) &&\n\t\t(rsa->dmp1 != NULL) &&\n\t\t(rsa->dmq1 != NULL) &&\n\t\t(rsa->iqmp != NULL)) )\n\t\t{\n\t\tif (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tBIGNUM local_d;\n\t\tBIGNUM *d = NULL;\n\t\tif (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))\n\t\t\t{\n\t\t\td = &local_d;\n\t\t\tBN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n\t\t\t}\n\t\telse\n\t\t\td = rsa->d;\n\t\tif (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n\t\t\tif (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))\n\t\t\t\tgoto err;\n\t\tif (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,\n\t\t\t\trsa->_method_mod_n))\n\t\t  goto err;\n\t\t}\n\tif (blinding)\n\t\tif (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))\n\t\t\tgoto err;\n\tp=buf;\n\tj=BN_bn2bin(ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);\n\t\tbreak;\n#ifndef OPENSSL_NO_SHA\n        case RSA_PKCS1_OAEP_PADDING:\n\t        r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);\n                break;\n#endif\n \tcase RSA_SSLV23_PADDING:\n\t\tr=RSA_padding_check_SSLv23(to,num,buf,j,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,j,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint got_write_lock = 0;\n\tBN_MONT_CTX *ret;\n\tCRYPTO_r_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\tCRYPTO_r_unlock(lock);\n\t\tCRYPTO_w_lock(lock);\n\t\tgot_write_lock = 1;\n\t\tif (!*pmont)\n\t\t\t{\n\t\t\tret = BN_MONT_CTX_new();\n\t\t\tif (ret && !BN_MONT_CTX_set(ret, mod, ctx))\n\t\t\t\tBN_MONT_CTX_free(ret);\n\t\t\telse\n\t\t\t\t*pmont = ret;\n\t\t\t}\n\t\t}\n\tret = *pmont;\n\tif (got_write_lock)\n\t\tCRYPTO_w_unlock(lock);\n\telse\n\t\tCRYPTO_r_unlock(lock);\n\treturn ret;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tBN_init(&tmod);\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\ta->neg=b->neg;\n\tbn_check_top(a);\n\treturn(a);\n\t}']