apps/pkeyutl.c:369: error: UNINITIALIZED_VALUE
  The value read from buf_outlen was never initialized.
Showing all 1 steps of the trace


apps/pkeyutl.c:369:3: 
367.   		BIO_dump(out, (char *)buf_out, buf_outlen);
368.   	else
369. > 		BIO_write(out, buf_out, buf_outlen);
370.   
371.   	end:

int MAIN(int argc, char **argv)
{
	BIO *in = NULL, *out = NULL;
	char *infile = NULL, *outfile = NULL, *sigfile = NULL;
	ENGINE *e = NULL;
	int pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;
	int keyform = FORMAT_PEM, peerform = FORMAT_PEM;
	char badarg = 0, rev = 0;
	char hexdump = 0, asn1parse = 0;
	EVP_PKEY_CTX *ctx = NULL;
	char *passargin = NULL;
	int keysize = -1;
	unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
	int buf_inlen, buf_outlen, siglen = -1;
	int ret = 1, rv = -1;
	argc--;
	argv++;
	if(!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
	if (!load_config(bio_err, NULL))
		goto end;
	ERR_load_crypto_strings();
	OpenSSL_add_all_algorithms();
	while(argc >= 1)
		{
		if (!strcmp(*argv,"-in"))
			{
			if (--argc < 1) badarg = 1;
                        infile= *(++argv);
			}
		else if (!strcmp(*argv,"-out"))
			{
			if (--argc < 1) badarg = 1;
			outfile= *(++argv);
			}
		else if (!strcmp(*argv,"-sigfile"))
			{
			if (--argc < 1) badarg = 1;
			sigfile= *(++argv);
			}
		else if(!strcmp(*argv, "-inkey"))
			{
			if (--argc < 1)
				badarg = 1;
			else
				{
				ctx = init_ctx(&keysize,
						*(++argv), keyform, key_type,
						passargin, pkey_op, e);
				if (!ctx)
					{
					BIO_puts(bio_err,
						"Error initializing context\n");
					ERR_print_errors(bio_err);
					badarg = 1;
					}
				}
			}
		else if (!strcmp(*argv,"-peerkey"))
			{
			if (--argc < 1)
				badarg = 1;
			else if (!setup_peer(bio_err, ctx, peerform, *(++argv)))
				badarg = 1;
			}
		else if (!strcmp(*argv,"-passin"))
			{
			if (--argc < 1) badarg = 1;
			passargin= *(++argv);
			}
		else if (strcmp(*argv,"-peerform") == 0)
			{
			if (--argc < 1) badarg = 1;
			peerform=str2fmt(*(++argv));
			}
		else if (strcmp(*argv,"-keyform") == 0)
			{
			if (--argc < 1) badarg = 1;
			keyform=str2fmt(*(++argv));
			}
#ifndef OPENSSL_NO_ENGINE
		else if(!strcmp(*argv, "-engine"))
			{
			if (--argc < 1)
				badarg = 1;
			else
				e = setup_engine(bio_err, *(++argv), 0);
			}
#endif
		else if(!strcmp(*argv, "-pubin"))
			key_type = KEY_PUBKEY;
		else if(!strcmp(*argv, "-certin"))
			key_type = KEY_CERT;
		else if(!strcmp(*argv, "-asn1parse"))
			asn1parse = 1;
		else if(!strcmp(*argv, "-hexdump"))
			hexdump = 1;
		else if(!strcmp(*argv, "-sign"))
			pkey_op = EVP_PKEY_OP_SIGN;
		else if(!strcmp(*argv, "-verify"))
			pkey_op = EVP_PKEY_OP_VERIFY;
		else if(!strcmp(*argv, "-verifyrecover"))
			pkey_op = EVP_PKEY_OP_VERIFYRECOVER;
		else if(!strcmp(*argv, "-rev"))
			rev = 1;
		else if(!strcmp(*argv, "-encrypt"))
			pkey_op = EVP_PKEY_OP_ENCRYPT;
		else if(!strcmp(*argv, "-decrypt"))
			pkey_op = EVP_PKEY_OP_DECRYPT;
		else if(!strcmp(*argv, "-derive"))
			pkey_op = EVP_PKEY_OP_DERIVE;
		else if (strcmp(*argv,"-pkeyopt") == 0)
			{
			if (--argc < 1)
				badarg = 1;
			else if (!ctx)
				{
				BIO_puts(bio_err,
					"-pkeyopt command before -inkey\n");
				badarg = 1;
				}
			else if (pkey_ctrl_string(ctx, *(++argv)) <= 0)
				{
				BIO_puts(bio_err, "parameter setting error\n");
				ERR_print_errors(bio_err);
				goto end;
				}
			}
		else badarg = 1;
		if(badarg)
			{
			usage();
			goto end;
			}
		argc--;
		argv++;
		}
	if (!ctx)
		{
		usage();
		goto end;
		}
	if (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY))
		{
		BIO_puts(bio_err, "Signature file specified for non verify\n");
		goto end;
		}
	if (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY))
		{
		BIO_puts(bio_err, "No signature file specified for verify\n");
		goto end;
		}
	app_RAND_load_file(NULL, bio_err, 0);
	if (pkey_op != EVP_PKEY_OP_DERIVE)
		{
		if(infile)
			{
			if(!(in = BIO_new_file(infile, "rb")))
				{
				BIO_puts(bio_err,
					"Error Opening Input File\n");
				ERR_print_errors(bio_err);
				goto end;
				}
			}
		else
			in = BIO_new_fp(stdin, BIO_NOCLOSE);
		}
	if(outfile)
		{
		if(!(out = BIO_new_file(outfile, "wb")))
			{
			BIO_printf(bio_err, "Error Creating Output File\n");
			ERR_print_errors(bio_err);
			goto end;
			}
		}
	else
		{
		out = BIO_new_fp(stdout, BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
		{
		    BIO *tmpbio = BIO_new(BIO_f_linebuffer());
		    out = BIO_push(tmpbio, out);
		}
#endif
	}
	if (sigfile)
		{
		BIO *sigbio = BIO_new_file(sigfile, "rb");
		if (!sigbio)
			{
			BIO_printf(bio_err, "Can't open signature file %s\n",
								sigfile);
			goto end;
			}
		siglen = bio_to_mem(&sig, keysize * 10, sigbio);
		BIO_free(sigbio);
		if (siglen <= 0)
			{
			BIO_printf(bio_err, "Error reading signature data\n");
			goto end;
			}
		}
	if (in)
		{
		buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
		if(buf_inlen <= 0)
			{
			BIO_printf(bio_err, "Error reading input Data\n");
			exit(1);
			}
		if(rev)
			{
			int i;
			unsigned char ctmp;
			for(i = 0; i < buf_inlen/2; i++)
				{
				ctmp = buf_in[i];
				buf_in[i] = buf_in[buf_inlen - 1 - i];
				buf_in[buf_inlen - 1 - i] = ctmp;
				}
			}
		}
	if(pkey_op == EVP_PKEY_OP_VERIFY)
		{
		rv  = EVP_PKEY_verify(ctx, sig, siglen, buf_in, buf_inlen);
		if (rv == 0)
			BIO_puts(out, "Signature Verification Failure\n");
		else if (rv == 1)
			BIO_puts(out, "Signature Verified Successfully\n");
		if (rv >= 0)
			goto end;
		}
	else
		{
		rv = do_keyop(ctx, pkey_op, NULL, &buf_outlen,
							buf_in, buf_inlen);
		if (rv > 0)
			{
			buf_out = OPENSSL_malloc(buf_outlen);
			if (!buf_out)
				rv = -1;
			else
				rv = do_keyop(ctx, pkey_op,
						buf_out, &buf_outlen,
						buf_in, buf_inlen);
			}
		}
	if(rv <= 0)
		{
		BIO_printf(bio_err, "Public Key operation error\n");
		ERR_print_errors(bio_err);
		goto end;
		}
	ret = 0;
	if(asn1parse)
		{
		if(!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))
			ERR_print_errors(bio_err);
		}
	else if(hexdump)
		BIO_dump(out, (char *)buf_out, buf_outlen);
	else
		BIO_write(out, buf_out, buf_outlen);
	end:
	if (ctx)
		EVP_PKEY_CTX_free(ctx);
	BIO_free(in);
	BIO_free_all(out);
	if (buf_in)
		OPENSSL_free(buf_in);
	if (buf_out)
		OPENSSL_free(buf_out);
	if (sig)
		OPENSSL_free(sig);
	return ret;
}
['int MAIN(int argc, char **argv)\n{\n\tBIO *in = NULL, *out = NULL;\n\tchar *infile = NULL, *outfile = NULL, *sigfile = NULL;\n\tENGINE *e = NULL;\n\tint pkey_op = EVP_PKEY_OP_SIGN, key_type = KEY_PRIVKEY;\n\tint keyform = FORMAT_PEM, peerform = FORMAT_PEM;\n\tchar badarg = 0, rev = 0;\n\tchar hexdump = 0, asn1parse = 0;\n\tEVP_PKEY_CTX *ctx = NULL;\n\tchar *passargin = NULL;\n\tint keysize = -1;\n\tunsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;\n\tint buf_inlen, buf_outlen, siglen = -1;\n\tint ret = 1, rv = -1;\n\targc--;\n\targv++;\n\tif(!bio_err) bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\tERR_load_crypto_strings();\n\tOpenSSL_add_all_algorithms();\n\twhile(argc >= 1)\n\t\t{\n\t\tif (!strcmp(*argv,"-in"))\n\t\t\t{\n\t\t\tif (--argc < 1) badarg = 1;\n                        infile= *(++argv);\n\t\t\t}\n\t\telse if (!strcmp(*argv,"-out"))\n\t\t\t{\n\t\t\tif (--argc < 1) badarg = 1;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (!strcmp(*argv,"-sigfile"))\n\t\t\t{\n\t\t\tif (--argc < 1) badarg = 1;\n\t\t\tsigfile= *(++argv);\n\t\t\t}\n\t\telse if(!strcmp(*argv, "-inkey"))\n\t\t\t{\n\t\t\tif (--argc < 1)\n\t\t\t\tbadarg = 1;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tctx = init_ctx(&keysize,\n\t\t\t\t\t\t*(++argv), keyform, key_type,\n\t\t\t\t\t\tpassargin, pkey_op, e);\n\t\t\t\tif (!ctx)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_puts(bio_err,\n\t\t\t\t\t\t"Error initializing context\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tbadarg = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\telse if (!strcmp(*argv,"-peerkey"))\n\t\t\t{\n\t\t\tif (--argc < 1)\n\t\t\t\tbadarg = 1;\n\t\t\telse if (!setup_peer(bio_err, ctx, peerform, *(++argv)))\n\t\t\t\tbadarg = 1;\n\t\t\t}\n\t\telse if (!strcmp(*argv,"-passin"))\n\t\t\t{\n\t\t\tif (--argc < 1) badarg = 1;\n\t\t\tpassargin= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-peerform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) badarg = 1;\n\t\t\tpeerform=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) badarg = 1;\n\t\t\tkeyform=str2fmt(*(++argv));\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if(!strcmp(*argv, "-engine"))\n\t\t\t{\n\t\t\tif (--argc < 1)\n\t\t\t\tbadarg = 1;\n\t\t\telse\n\t\t\t\te = setup_engine(bio_err, *(++argv), 0);\n\t\t\t}\n#endif\n\t\telse if(!strcmp(*argv, "-pubin"))\n\t\t\tkey_type = KEY_PUBKEY;\n\t\telse if(!strcmp(*argv, "-certin"))\n\t\t\tkey_type = KEY_CERT;\n\t\telse if(!strcmp(*argv, "-asn1parse"))\n\t\t\tasn1parse = 1;\n\t\telse if(!strcmp(*argv, "-hexdump"))\n\t\t\thexdump = 1;\n\t\telse if(!strcmp(*argv, "-sign"))\n\t\t\tpkey_op = EVP_PKEY_OP_SIGN;\n\t\telse if(!strcmp(*argv, "-verify"))\n\t\t\tpkey_op = EVP_PKEY_OP_VERIFY;\n\t\telse if(!strcmp(*argv, "-verifyrecover"))\n\t\t\tpkey_op = EVP_PKEY_OP_VERIFYRECOVER;\n\t\telse if(!strcmp(*argv, "-rev"))\n\t\t\trev = 1;\n\t\telse if(!strcmp(*argv, "-encrypt"))\n\t\t\tpkey_op = EVP_PKEY_OP_ENCRYPT;\n\t\telse if(!strcmp(*argv, "-decrypt"))\n\t\t\tpkey_op = EVP_PKEY_OP_DECRYPT;\n\t\telse if(!strcmp(*argv, "-derive"))\n\t\t\tpkey_op = EVP_PKEY_OP_DERIVE;\n\t\telse if (strcmp(*argv,"-pkeyopt") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1)\n\t\t\t\tbadarg = 1;\n\t\t\telse if (!ctx)\n\t\t\t\t{\n\t\t\t\tBIO_puts(bio_err,\n\t\t\t\t\t"-pkeyopt command before -inkey\\n");\n\t\t\t\tbadarg = 1;\n\t\t\t\t}\n\t\t\telse if (pkey_ctrl_string(ctx, *(++argv)) <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_puts(bio_err, "parameter setting error\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\telse badarg = 1;\n\t\tif(badarg)\n\t\t\t{\n\t\t\tusage();\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (!ctx)\n\t\t{\n\t\tusage();\n\t\tgoto end;\n\t\t}\n\tif (sigfile && (pkey_op != EVP_PKEY_OP_VERIFY))\n\t\t{\n\t\tBIO_puts(bio_err, "Signature file specified for non verify\\n");\n\t\tgoto end;\n\t\t}\n\tif (!sigfile && (pkey_op == EVP_PKEY_OP_VERIFY))\n\t\t{\n\t\tBIO_puts(bio_err, "No signature file specified for verify\\n");\n\t\tgoto end;\n\t\t}\n\tapp_RAND_load_file(NULL, bio_err, 0);\n\tif (pkey_op != EVP_PKEY_OP_DERIVE)\n\t\t{\n\t\tif(infile)\n\t\t\t{\n\t\t\tif(!(in = BIO_new_file(infile, "rb")))\n\t\t\t\t{\n\t\t\t\tBIO_puts(bio_err,\n\t\t\t\t\t"Error Opening Input File\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\tin = BIO_new_fp(stdin, BIO_NOCLOSE);\n\t\t}\n\tif(outfile)\n\t\t{\n\t\tif(!(out = BIO_new_file(outfile, "wb")))\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error Creating Output File\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tout = BIO_new_fp(stdout, BIO_NOCLOSE);\n#ifdef OPENSSL_SYS_VMS\n\t\t{\n\t\t    BIO *tmpbio = BIO_new(BIO_f_linebuffer());\n\t\t    out = BIO_push(tmpbio, out);\n\t\t}\n#endif\n\t}\n\tif (sigfile)\n\t\t{\n\t\tBIO *sigbio = BIO_new_file(sigfile, "rb");\n\t\tif (!sigbio)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Can\'t open signature file %s\\n",\n\t\t\t\t\t\t\t\tsigfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\tsiglen = bio_to_mem(&sig, keysize * 10, sigbio);\n\t\tBIO_free(sigbio);\n\t\tif (siglen <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error reading signature data\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (in)\n\t\t{\n\t\tbuf_inlen = bio_to_mem(&buf_in, keysize * 10, in);\n\t\tif(buf_inlen <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error reading input Data\\n");\n\t\t\texit(1);\n\t\t\t}\n\t\tif(rev)\n\t\t\t{\n\t\t\tint i;\n\t\t\tunsigned char ctmp;\n\t\t\tfor(i = 0; i < buf_inlen/2; i++)\n\t\t\t\t{\n\t\t\t\tctmp = buf_in[i];\n\t\t\t\tbuf_in[i] = buf_in[buf_inlen - 1 - i];\n\t\t\t\tbuf_in[buf_inlen - 1 - i] = ctmp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif(pkey_op == EVP_PKEY_OP_VERIFY)\n\t\t{\n\t\trv  = EVP_PKEY_verify(ctx, sig, siglen, buf_in, buf_inlen);\n\t\tif (rv == 0)\n\t\t\tBIO_puts(out, "Signature Verification Failure\\n");\n\t\telse if (rv == 1)\n\t\t\tBIO_puts(out, "Signature Verified Successfully\\n");\n\t\tif (rv >= 0)\n\t\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\trv = do_keyop(ctx, pkey_op, NULL, &buf_outlen,\n\t\t\t\t\t\t\tbuf_in, buf_inlen);\n\t\tif (rv > 0)\n\t\t\t{\n\t\t\tbuf_out = OPENSSL_malloc(buf_outlen);\n\t\t\tif (!buf_out)\n\t\t\t\trv = -1;\n\t\t\telse\n\t\t\t\trv = do_keyop(ctx, pkey_op,\n\t\t\t\t\t\tbuf_out, &buf_outlen,\n\t\t\t\t\t\tbuf_in, buf_inlen);\n\t\t\t}\n\t\t}\n\tif(rv <= 0)\n\t\t{\n\t\tBIO_printf(bio_err, "Public Key operation error\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tret = 0;\n\tif(asn1parse)\n\t\t{\n\t\tif(!ASN1_parse_dump(out, buf_out, buf_outlen, 1, -1))\n\t\t\tERR_print_errors(bio_err);\n\t\t}\n\telse if(hexdump)\n\t\tBIO_dump(out, (char *)buf_out, buf_outlen);\n\telse\n\t\tBIO_write(out, buf_out, buf_outlen);\n\tend:\n\tif (ctx)\n\t\tEVP_PKEY_CTX_free(ctx);\n\tBIO_free(in);\n\tBIO_free_all(out);\n\tif (buf_in)\n\t\tOPENSSL_free(buf_in);\n\tif (buf_out)\n\t\tOPENSSL_free(buf_out);\n\tif (sig)\n\t\tOPENSSL_free(sig);\n\treturn ret;\n}']