crypto/cms/cms_enc.c:189: error: UNINITIALIZED_VALUE
  The value read from tkeylen was never initialized.
Showing all 1 steps of the trace


crypto/cms/cms_enc.c:189:5: 
187.   				OPENSSL_free(ec->key);
188.   				ec->key = tkey;
189. > 				ec->keylen = tkeylen;
190.   				tkey = NULL;
191.   				ERR_clear_error();

BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
	{
	BIO *b;
	EVP_CIPHER_CTX *ctx;
	const EVP_CIPHER *ciph;
	X509_ALGOR *calg = ec->contentEncryptionAlgorithm;
	unsigned char iv[EVP_MAX_IV_LENGTH], *piv = NULL;
	unsigned char *tkey = NULL;
	size_t tkeylen;
	int ok = 0;
	int enc, keep_key = 0;
	enc = ec->cipher ? 1 : 0;
	b = BIO_new(BIO_f_cipher());
	if (!b)
		{
		CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
							ERR_R_MALLOC_FAILURE);
		return NULL;
		}
	BIO_get_cipher_ctx(b, &ctx);
	if (enc)
		{
		ciph = ec->cipher;
		if (ec->key)
			ec->cipher = NULL;
		}
	else
		{
		ciph = EVP_get_cipherbyobj(calg->algorithm);
		if (!ciph)
			{
			CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
							CMS_R_UNKNOWN_CIPHER);
			goto err;
			}
		}
	if (EVP_CipherInit_ex(ctx, ciph, NULL, NULL, NULL, enc) <= 0)
		{
		CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
				CMS_R_CIPHER_INITIALISATION_ERROR);
		goto err;
		}
	if (enc)
		{
		int ivlen;
		calg->algorithm = OBJ_nid2obj(EVP_CIPHER_CTX_type(ctx));
		ivlen = EVP_CIPHER_CTX_iv_length(ctx);
		if (ivlen > 0)
			{
			if (RAND_pseudo_bytes(iv, ivlen) <= 0)
				goto err;
			piv = iv;
			}
		}
	else if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0)
		{
		CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
				CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);
		goto err;
		}
	if (!enc || !ec->key)
		{
		tkeylen = EVP_CIPHER_CTX_key_length(ctx);
		tkey = OPENSSL_malloc(tkeylen);
		if (!tkey)
			{
			CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
							ERR_R_MALLOC_FAILURE);
			goto err;
			}
		if (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0)
			goto err;
		}
	if (!ec->key)
		{
		ec->key = tkey;
		ec->keylen = tkeylen;
		tkey = NULL;
		if (enc)
			keep_key = 1;
		else
			ERR_clear_error();
		}
	if (ec->keylen != tkeylen)
		{
		if (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen) <= 0)
			{
			if (ec->debug)
				{
				CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
						CMS_R_INVALID_KEY_LENGTH);
				goto err;
				}
			else
				{
				OPENSSL_cleanse(ec->key, ec->keylen);
				OPENSSL_free(ec->key);
				ec->key = tkey;
				ec->keylen = tkeylen;
				tkey = NULL;
				ERR_clear_error();
				}
			}
		}
	if (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0)
		{
		CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
				CMS_R_CIPHER_INITIALISATION_ERROR);
		goto err;
		}
	if (piv)
		{
		calg->parameter = ASN1_TYPE_new();
		if (!calg->parameter)
			{
			CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
							ERR_R_MALLOC_FAILURE);
			goto err;
			}
		if (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0)
			{
			CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
				CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);
			goto err;
			}
		}
	ok = 1;
	err:
	if (ec->key && !keep_key)
		{
		OPENSSL_cleanse(ec->key, ec->keylen);
		OPENSSL_free(ec->key);
		ec->key = NULL;
		}
	if (tkey)
		{
		OPENSSL_cleanse(tkey, tkeylen);
		OPENSSL_free(tkey);
		}
	if (ok)
		return b;
	BIO_free(b);
	return NULL;
	}
['BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)\n\t{\n\tBIO *b;\n\tEVP_CIPHER_CTX *ctx;\n\tconst EVP_CIPHER *ciph;\n\tX509_ALGOR *calg = ec->contentEncryptionAlgorithm;\n\tunsigned char iv[EVP_MAX_IV_LENGTH], *piv = NULL;\n\tunsigned char *tkey = NULL;\n\tsize_t tkeylen;\n\tint ok = 0;\n\tint enc, keep_key = 0;\n\tenc = ec->cipher ? 1 : 0;\n\tb = BIO_new(BIO_f_cipher());\n\tif (!b)\n\t\t{\n\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tBIO_get_cipher_ctx(b, &ctx);\n\tif (enc)\n\t\t{\n\t\tciph = ec->cipher;\n\t\tif (ec->key)\n\t\t\tec->cipher = NULL;\n\t\t}\n\telse\n\t\t{\n\t\tciph = EVP_get_cipherbyobj(calg->algorithm);\n\t\tif (!ciph)\n\t\t\t{\n\t\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\t\t\t\tCMS_R_UNKNOWN_CIPHER);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (EVP_CipherInit_ex(ctx, ciph, NULL, NULL, NULL, enc) <= 0)\n\t\t{\n\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\tCMS_R_CIPHER_INITIALISATION_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (enc)\n\t\t{\n\t\tint ivlen;\n\t\tcalg->algorithm = OBJ_nid2obj(EVP_CIPHER_CTX_type(ctx));\n\t\tivlen = EVP_CIPHER_CTX_iv_length(ctx);\n\t\tif (ivlen > 0)\n\t\t\t{\n\t\t\tif (RAND_pseudo_bytes(iv, ivlen) <= 0)\n\t\t\t\tgoto err;\n\t\t\tpiv = iv;\n\t\t\t}\n\t\t}\n\telse if (EVP_CIPHER_asn1_to_param(ctx, calg->parameter) <= 0)\n\t\t{\n\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\tCMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (!enc || !ec->key)\n\t\t{\n\t\ttkeylen = EVP_CIPHER_CTX_key_length(ctx);\n\t\ttkey = OPENSSL_malloc(tkeylen);\n\t\tif (!tkey)\n\t\t\t{\n\t\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (EVP_CIPHER_CTX_rand_key(ctx, tkey) <= 0)\n\t\t\tgoto err;\n\t\t}\n\tif (!ec->key)\n\t\t{\n\t\tec->key = tkey;\n\t\tec->keylen = tkeylen;\n\t\ttkey = NULL;\n\t\tif (enc)\n\t\t\tkeep_key = 1;\n\t\telse\n\t\t\tERR_clear_error();\n\t\t}\n\tif (ec->keylen != tkeylen)\n\t\t{\n\t\tif (EVP_CIPHER_CTX_set_key_length(ctx, ec->keylen) <= 0)\n\t\t\t{\n\t\t\tif (ec->debug)\n\t\t\t\t{\n\t\t\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\t\t\tCMS_R_INVALID_KEY_LENGTH);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tOPENSSL_cleanse(ec->key, ec->keylen);\n\t\t\t\tOPENSSL_free(ec->key);\n\t\t\t\tec->key = tkey;\n\t\t\t\tec->keylen = tkeylen;\n\t\t\t\ttkey = NULL;\n\t\t\t\tERR_clear_error();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (EVP_CipherInit_ex(ctx, NULL, NULL, ec->key, piv, enc) <= 0)\n\t\t{\n\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\tCMS_R_CIPHER_INITIALISATION_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (piv)\n\t\t{\n\t\tcalg->parameter = ASN1_TYPE_new();\n\t\tif (!calg->parameter)\n\t\t\t{\n\t\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (EVP_CIPHER_param_to_asn1(ctx, calg->parameter) <= 0)\n\t\t\t{\n\t\t\tCMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,\n\t\t\t\tCMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tok = 1;\n\terr:\n\tif (ec->key && !keep_key)\n\t\t{\n\t\tOPENSSL_cleanse(ec->key, ec->keylen);\n\t\tOPENSSL_free(ec->key);\n\t\tec->key = NULL;\n\t\t}\n\tif (tkey)\n\t\t{\n\t\tOPENSSL_cleanse(tkey, tkeylen);\n\t\tOPENSSL_free(tkey);\n\t\t}\n\tif (ok)\n\t\treturn b;\n\tBIO_free(b);\n\treturn NULL;\n\t}']