crypto/evp/evp_pkey.c:189: error: BUFFER_OVERRUN_L3
  Offset: [-3, +oo] Size: 12 by call to `BN_mod_exp`.
Showing all 19 steps of the trace


crypto/evp/evp_pkey.c:184:15: Call
182.   			goto dsaerr;
183.   		}
184.   		if (!(ctx = BN_CTX_new())) {
                     ^
185.   			EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
186.   			goto dsaerr;

crypto/bn/bn_ctx.c:79:2: Call
  77.   		}
  78.   
  79.   	BN_CTX_init(ret);
         ^
  80.   	ret->flags=BN_FLG_MALLOCED;
  81.   	return(ret);

crypto/bn/bn_ctx.c:89:2: Assignment
    87.   	ctx->tos = 0;
    88.   	ctx->flags = 0;
    89.   	ctx->depth = 0;
           ^
    90.   	ctx->too_many = 0;
    91.   	for (i = 0; i < BN_CTX_NUM; i++)

crypto/evp/evp_pkey.c:189:8: Call
187.   		}
188.   			
189.   		if (!BN_mod_exp(dsa->pub_key, dsa->g,
              ^
190.   						 dsa->priv_key, dsa->p, ctx)) {
191.   			

crypto/bn/bn_exp.c:180:1: Parameter `ctx->depth`
  178.   
  179.   
  180. > int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
  181.   	       BN_CTX *ctx)
  182.   	{

crypto/bn/bn_exp.c:209:9: Call
  207.   #endif
  208.   #ifdef RECP_MUL_MOD
  209.   		{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }
                 ^
  210.   #else
  211.   		{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }

crypto/bn/bn_exp.c:218:1: Parameter `ctx->depth`
    216.   
    217.   
    218. > int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
    219.   		    const BIGNUM *m, BN_CTX *ctx)
    220.   	{

crypto/bn/bn_exp.c:235:2: Call
    233.   		}
    234.   
    235.   	BN_CTX_start(ctx);
            ^
    236.   	if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
    237.   

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

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

crypto/bn/bn_exp.c:236:12: Call
    234.   
    235.   	BN_CTX_start(ctx);
    236.   	if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
                      ^
    237.   
    238.   	BN_RECP_CTX_init(&recp);

crypto/bn/bn_ctx.c:115:1: Parameter `ctx->depth`
      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_exp.c:321:2: Call
    319.   	ret=1;
    320.   err:
    321.   	BN_CTX_end(ctx);
            ^
    322.   	for (i=0; i<ts; i++)
    323.   		BN_clear_free(&(val[i]));

crypto/bn/bn_ctx.c:130:1: <Offset trace>
128.   	}
129.   
130. > void BN_CTX_end(BN_CTX *ctx)
131.   	{
132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:130:1: Parameter `ctx->depth`
      128.   	}
      129.   
      130. > void BN_CTX_end(BN_CTX *ctx)
      131.   	{
      132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:141:2: Assignment
      139.   
      140.   	ctx->too_many = 0;
      141.   	ctx->depth--;
              ^
      142.   	if (ctx->depth < BN_CTX_NUM_POS)
      143.   		ctx->tos = ctx->pos[ctx->depth];

crypto/bn/bn_ctx.c:130:1: <Length trace>
128.   	}
129.   
130. > void BN_CTX_end(BN_CTX *ctx)
131.   	{
132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:130:1: Parameter `ctx->pos[*]`
      128.   	}
      129.   
      130. > void BN_CTX_end(BN_CTX *ctx)
      131.   	{
      132.   	if (ctx == NULL) return;

crypto/bn/bn_ctx.c:143:14: Array access: Offset: [-3, +oo] Size: 12 by call to `BN_mod_exp` 
      141.   	ctx->depth--;
      142.   	if (ctx->depth < BN_CTX_NUM_POS)
      143.   		ctx->tos = ctx->pos[ctx->depth];
                          ^
      144.   	}

void BN_CTX_end(BN_CTX *ctx)
	{
	if (ctx == NULL) return;
	assert(ctx->depth > 0);
	if (ctx->depth == 0)
		BN_CTX_start(ctx);
	ctx->too_many = 0;
	ctx->depth--;
	if (ctx->depth < BN_CTX_NUM_POS)
		ctx->tos = ctx->pos[ctx->depth];
	}
['EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)\n{\n\tEVP_PKEY *pkey = NULL;\n#ifndef NO_RSA\n\tRSA *rsa = NULL;\n#endif\n#ifndef NO_DSA\n\tDSA *dsa = NULL;\n\tASN1_INTEGER *privkey;\n\tASN1_TYPE *t1, *t2, *param = NULL;\n\tSTACK_OF(ASN1_TYPE) *ndsa = NULL;\n\tBN_CTX *ctx = NULL;\n\tint plen;\n#endif\n\tX509_ALGOR *a;\n\tunsigned char *p;\n\tconst unsigned char *cp;\n\tint pkeylen;\n\tchar obj_tmp[80];\n\tif(p8->pkey->type == V_ASN1_OCTET_STRING) {\n\t\tp8->broken = PKCS8_OK;\n\t\tp = p8->pkey->value.octet_string->data;\n\t\tpkeylen = p8->pkey->value.octet_string->length;\n\t} else {\n\t\tp8->broken = PKCS8_NO_OCTET;\n\t\tp = p8->pkey->value.sequence->data;\n\t\tpkeylen = p8->pkey->value.sequence->length;\n\t}\n\tif (!(pkey = EVP_PKEY_new())) {\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\ta = p8->pkeyalg;\n\tswitch (OBJ_obj2nid(a->algorithm))\n\t{\n#ifndef NO_RSA\n\t\tcase NID_rsaEncryption:\n\t\tcp = p;\n\t\tif (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\treturn NULL;\n\t\t}\n\t\tEVP_PKEY_assign_RSA (pkey, rsa);\n\t\tbreak;\n#endif\n#ifndef NO_DSA\n\t\tcase NID_dsa:\n\t\tif(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {\n\t\t    if(!(ndsa = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen,\n\t\t\t\t\t\t\t  d2i_ASN1_TYPE,\n\t\t\t\t\t\t\t  ASN1_TYPE_free))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t    }\n\t\t    if(sk_ASN1_TYPE_num(ndsa) != 2 ) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t    }\n\t\t    t1 = sk_ASN1_TYPE_value(ndsa, 0);\n\t\t    t2 = sk_ASN1_TYPE_value(ndsa, 1);\n\t\t    if(t1->type == V_ASN1_SEQUENCE) {\n\t\t\tp8->broken = PKCS8_EMBEDDED_PARAM;\n\t\t\tparam = t1;\n\t\t    } else if(a->parameter->type == V_ASN1_SEQUENCE) {\n\t\t\tp8->broken = PKCS8_NS_DB;\n\t\t\tparam = a->parameter;\n\t\t    } else {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t    }\n\t\t    if(t2->type != V_ASN1_INTEGER) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t    }\n\t\t    privkey = t2->value.integer;\n\t\t} else {\n\t\t\tif (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto dsaerr;\n\t\t\t}\n\t\t\tparam = p8->pkeyalg->parameter;\n\t\t}\n\t\tif (!param || (param->type != V_ASN1_SEQUENCE)) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t}\n\t\tp = param->value.sequence->data;\n\t\tplen = param->value.sequence->length;\n\t\tif (!(dsa = d2i_DSAparams (NULL, &p, plen))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t}\n\t\tif (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);\n\t\t\tgoto dsaerr;\n\t\t}\n\t\tif (!(dsa->pub_key = BN_new())) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto dsaerr;\n\t\t}\n\t\tif (!(ctx = BN_CTX_new())) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto dsaerr;\n\t\t}\n\t\tif (!BN_mod_exp(dsa->pub_key, dsa->g,\n\t\t\t\t\t\t dsa->priv_key, dsa->p, ctx)) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);\n\t\t\tgoto dsaerr;\n\t\t}\n\t\tEVP_PKEY_assign_DSA(pkey, dsa);\n\t\tBN_CTX_free (ctx);\n\t\tif(ndsa) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);\n\t\telse ASN1_INTEGER_free(privkey);\n\t\tbreak;\n\t\tdsaerr:\n\t\tBN_CTX_free (ctx);\n\t\tsk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);\n\t\tDSA_free(dsa);\n\t\tEVP_PKEY_free(pkey);\n\t\treturn NULL;\n\t\tbreak;\n#endif\n\t\tdefault:\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\tif (!a->algorithm) strcpy (obj_tmp, "NULL");\n\t\telse i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);\n\t\tERR_add_error_data(2, "TYPE=", obj_tmp);\n\t\tEVP_PKEY_free (pkey);\n\t\treturn NULL;\n\t}\n\treturn pkey;\n}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)OPENSSL_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}', 'void BN_CTX_init(BN_CTX *ctx)\n\t{\n\tint i;\n\tctx->tos = 0;\n\tctx->flags = 0;\n\tctx->depth = 0;\n\tctx->too_many = 0;\n\tfor (i = 0; i < BN_CTX_NUM; i++)\n\t\tBN_init(&(ctx->bn[i]));\n\t}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t       BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n\t\tif (a->top == 1)\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\treturn(ret);\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t    const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((aa = BN_CTX_get(ctx)) == NULL) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\t\tgoto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tBN_init(&val[i]);\n\t\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tts=i;\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\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}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tif (ctx == NULL) return;\n\tassert(ctx->depth > 0);\n\tif (ctx->depth == 0)\n\t\tBN_CTX_start(ctx);\n\tctx->too_many = 0;\n\tctx->depth--;\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->tos = ctx->pos[ctx->depth];\n\t}']