apps/dgst.c:404: error: NULL_DEREFERENCE
  pointer `sigkey` last assigned on line 100 could be null and is dereferenced by call to `EVP_PKEY_free()` at line 404, column 2.
Showing all 51 steps of the trace


apps/dgst.c:82:1: start of procedure dgst_main()
80.   int MAIN(int, char **);
81.   
82. > int MAIN(int argc, char **argv)
83.   	{
84.   	ENGINE *e = NULL;

apps/dgst.c:84:2: 
82.   int MAIN(int argc, char **argv)
83.   	{
84. > 	ENGINE *e = NULL;
85.   	unsigned char *buf=NULL;
86.   	int i,err=0;

apps/dgst.c:85:2: 
83.   	{
84.   	ENGINE *e = NULL;
85. > 	unsigned char *buf=NULL;
86.   	int i,err=0;
87.   	const EVP_MD *md=NULL,*m;

apps/dgst.c:86:2: 
84.   	ENGINE *e = NULL;
85.   	unsigned char *buf=NULL;
86. > 	int i,err=0;
87.   	const EVP_MD *md=NULL,*m;
88.   	BIO *in=NULL,*inp;

apps/dgst.c:87:2: 
85.   	unsigned char *buf=NULL;
86.   	int i,err=0;
87. > 	const EVP_MD *md=NULL,*m;
88.   	BIO *in=NULL,*inp;
89.   	BIO *bmd=NULL;

apps/dgst.c:88:2: 
86.   	int i,err=0;
87.   	const EVP_MD *md=NULL,*m;
88. > 	BIO *in=NULL,*inp;
89.   	BIO *bmd=NULL;
90.   	BIO *out = NULL;

apps/dgst.c:89:2: 
87.   	const EVP_MD *md=NULL,*m;
88.   	BIO *in=NULL,*inp;
89. > 	BIO *bmd=NULL;
90.   	BIO *out = NULL;
91.   	const char *name;

apps/dgst.c:90:2: 
88.   	BIO *in=NULL,*inp;
89.   	BIO *bmd=NULL;
90. > 	BIO *out = NULL;
91.   	const char *name;
92.   #define PROG_NAME_SIZE  39

apps/dgst.c:94:2: 
92.   #define PROG_NAME_SIZE  39
93.   	char pname[PROG_NAME_SIZE+1];
94. > 	int separator=0;
95.   	int debug=0;
96.   	int keyform=FORMAT_PEM;

apps/dgst.c:95:2: 
93.   	char pname[PROG_NAME_SIZE+1];
94.   	int separator=0;
95. > 	int debug=0;
96.   	int keyform=FORMAT_PEM;
97.   	const char *outfile = NULL, *keyfile = NULL;

apps/dgst.c:96:2: 
94.   	int separator=0;
95.   	int debug=0;
96. > 	int keyform=FORMAT_PEM;
97.   	const char *outfile = NULL, *keyfile = NULL;
98.   	const char *sigfile = NULL, *randfile = NULL;

apps/dgst.c:97:2: 
95.   	int debug=0;
96.   	int keyform=FORMAT_PEM;
97. > 	const char *outfile = NULL, *keyfile = NULL;
98.   	const char *sigfile = NULL, *randfile = NULL;
99.   	int out_bin = -1, want_pub = 0, do_verify = 0;

apps/dgst.c:98:2: 
96.   	int keyform=FORMAT_PEM;
97.   	const char *outfile = NULL, *keyfile = NULL;
98. > 	const char *sigfile = NULL, *randfile = NULL;
99.   	int out_bin = -1, want_pub = 0, do_verify = 0;
100.   	EVP_PKEY *sigkey = NULL;

apps/dgst.c:99:2: 
97.   	const char *outfile = NULL, *keyfile = NULL;
98.   	const char *sigfile = NULL, *randfile = NULL;
99. > 	int out_bin = -1, want_pub = 0, do_verify = 0;
100.   	EVP_PKEY *sigkey = NULL;
101.   	unsigned char *sigbuf = NULL;

apps/dgst.c:100:2: 
98.   	const char *sigfile = NULL, *randfile = NULL;
99.   	int out_bin = -1, want_pub = 0, do_verify = 0;
100. > 	EVP_PKEY *sigkey = NULL;
101.   	unsigned char *sigbuf = NULL;
102.   	int siglen = 0;

apps/dgst.c:101:2: 
99.   	int out_bin = -1, want_pub = 0, do_verify = 0;
100.   	EVP_PKEY *sigkey = NULL;
101. > 	unsigned char *sigbuf = NULL;
102.   	int siglen = 0;
103.   	char *passargin = NULL, *passin = NULL;

apps/dgst.c:102:2: 
100.   	EVP_PKEY *sigkey = NULL;
101.   	unsigned char *sigbuf = NULL;
102. > 	int siglen = 0;
103.   	char *passargin = NULL, *passin = NULL;
104.   #ifndef OPENSSL_NO_ENGINE

apps/dgst.c:103:2: 
101.   	unsigned char *sigbuf = NULL;
102.   	int siglen = 0;
103. > 	char *passargin = NULL, *passin = NULL;
104.   #ifndef OPENSSL_NO_ENGINE
105.   	char *engine=NULL;

apps/dgst.c:105:2: 
103.   	char *passargin = NULL, *passin = NULL;
104.   #ifndef OPENSSL_NO_ENGINE
105. > 	char *engine=NULL;
106.   #endif
107.   

apps/dgst.c:108:2: 
106.   #endif
107.   
108. > 	apps_startup();
109.   
110.   	if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)

apps/dgst.c:110:6: 
108.   	apps_startup();
109.   
110. > 	if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
111.   		{
112.   		BIO_printf(bio_err,"out of memory\n");

crypto/mem.c:291:1: start of procedure CRYPTO_malloc()
  289.   	}
  290.   
  291. > void *CRYPTO_malloc(int num, const char *file, int line)
  292.   	{
  293.   	void *ret = NULL;

crypto/mem.c:293:2: 
  291.   void *CRYPTO_malloc(int num, const char *file, int line)
  292.   	{
  293. > 	void *ret = NULL;
  294.   	extern unsigned char cleanse_ctr;
  295.   

crypto/mem.c:296:6: Taking false branch
  294.   	extern unsigned char cleanse_ctr;
  295.   
  296.   	if (num <= 0) return NULL;
              ^
  297.   
  298.   	allow_customize = 0;

crypto/mem.c:298:2: 
  296.   	if (num <= 0) return NULL;
  297.   
  298. > 	allow_customize = 0;
  299.   	if (malloc_debug_func != NULL)
  300.   		{

crypto/mem.c:299:6: Taking true branch
  297.   
  298.   	allow_customize = 0;
  299.   	if (malloc_debug_func != NULL)
              ^
  300.   		{
  301.   		allow_customize_debug = 0;

crypto/mem.c:301:3: 
  299.   	if (malloc_debug_func != NULL)
  300.   		{
  301. > 		allow_customize_debug = 0;
  302.   		malloc_debug_func(NULL, num, file, line, 0);
  303.   		}

crypto/mem.c:302:3: Skipping __function_pointer__(): unresolved function pointer
  300.   		{
  301.   		allow_customize_debug = 0;
  302.   		malloc_debug_func(NULL, num, file, line, 0);
           ^
  303.   		}
  304.   	ret = malloc_ex_func(num,file,line);

crypto/mem.c:304:2: Skipping __function_pointer__(): unresolved function pointer
  302.   		malloc_debug_func(NULL, num, file, line, 0);
  303.   		}
  304.   	ret = malloc_ex_func(num,file,line);
          ^
  305.   #ifdef LEVITTE_DEBUG_MEM
  306.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:308:6: Taking true branch
  306.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
  307.   #endif
  308.   	if (malloc_debug_func != NULL)
              ^
  309.   		malloc_debug_func(ret, num, file, line, 1);
  310.   

crypto/mem.c:309:3: Skipping __function_pointer__(): unresolved function pointer
  307.   #endif
  308.   	if (malloc_debug_func != NULL)
  309.   		malloc_debug_func(ret, num, file, line, 1);
           ^
  310.   
  311.           /* Create a dependency on the value of 'cleanse_ctr' so our memory

crypto/mem.c:314:12: Taking false branch
  312.            * sanitisation function can't be optimised out. NB: We only do
  313.            * this for >2Kb so the overhead doesn't bother us. */
  314.           if(ret && (num > 2048))
                    ^
  315.                   ((unsigned char *)ret)[0] = cleanse_ctr;
  316.   

crypto/mem.c:317:2: 
  315.                   ((unsigned char *)ret)[0] = cleanse_ctr;
  316.   
  317. > 	return ret;
  318.   	}
  319.   

crypto/mem.c:318:2: return from a call to CRYPTO_malloc
  316.   
  317.   	return ret;
  318.   	}
          ^
  319.   
  320.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

apps/dgst.c:110:6: Taking true branch
108.   	apps_startup();
109.   
110.   	if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
            ^
111.   		{
112.   		BIO_printf(bio_err,"out of memory\n");

apps/dgst.c:112:3: 
110.   	if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
111.   		{
112. > 		BIO_printf(bio_err,"out of memory\n");
113.   		goto end;
114.   		}

crypto/bio/b_print.c:768:1: start of procedure BIO_printf()
  766.   /***************************************************************************/
  767.   
  768. > int BIO_printf (BIO *bio, const char *format, ...)
  769.   	{
  770.   	va_list args;

crypto/bio/b_print.c:773:2: 
  771.   	int ret;
  772.   
  773. > 	va_start(args, format);
  774.   
  775.   	ret = BIO_vprintf(bio, format, args);

crypto/bio/b_print.c:775:2: Skipping BIO_vprintf(): empty list of specs
  773.   	va_start(args, format);
  774.   
  775.   	ret = BIO_vprintf(bio, format, args);
          ^
  776.   
  777.   	va_end(args);

crypto/bio/b_print.c:777:2: 
  775.   	ret = BIO_vprintf(bio, format, args);
  776.   
  777. > 	va_end(args);
  778.   	return(ret);
  779.   	}

crypto/bio/b_print.c:778:2: 
  776.   
  777.   	va_end(args);
  778. > 	return(ret);
  779.   	}
  780.   

crypto/bio/b_print.c:779:2: return from a call to BIO_printf
  777.   	va_end(args);
  778.   	return(ret);
  779.   	}
          ^
  780.   
  781.   int BIO_vprintf (BIO *bio, const char *format, va_list args)

apps/dgst.c:394:1: 
392.   			}
393.   		}
394. > end:
395.   	if (buf != NULL)
396.   		{

apps/dgst.c:395:6: Taking false branch
393.   		}
394.   end:
395.   	if (buf != NULL)
            ^
396.   		{
397.   		OPENSSL_cleanse(buf,BUFSIZE);

apps/dgst.c:400:6: Taking false branch
398.   		OPENSSL_free(buf);
399.   		}
400.   	if (in != NULL) BIO_free(in);
            ^
401.   	if (passin)
402.   		OPENSSL_free(passin);

apps/dgst.c:401:6: Taking false branch
399.   		}
400.   	if (in != NULL) BIO_free(in);
401.   	if (passin)
            ^
402.   		OPENSSL_free(passin);
403.   	BIO_free_all(out);

apps/dgst.c:403:2: 
401.   	if (passin)
402.   		OPENSSL_free(passin);
403. > 	BIO_free_all(out);
404.   	EVP_PKEY_free(sigkey);
405.   	if(sigbuf) OPENSSL_free(sigbuf);

crypto/bio/bio_lib.c:460:1: start of procedure BIO_free_all()
  458.   	}
  459.   
  460. > void BIO_free_all(BIO *bio)
  461.   	{
  462.   	BIO *b;

crypto/bio/bio_lib.c:465:9: Loop condition is false. Leaving loop
  463.   	int ref;
  464.   
  465.   	while (bio != NULL)
                 ^
  466.   		{
  467.   		b=bio;

crypto/bio/bio_lib.c:474:2: return from a call to BIO_free_all
  472.   		if (ref > 1) break;
  473.   		}
  474.   	}
          ^
  475.   
  476.   BIO *BIO_dup_chain(BIO *in)

apps/dgst.c:404:2: 
402.   		OPENSSL_free(passin);
403.   	BIO_free_all(out);
404. > 	EVP_PKEY_free(sigkey);
405.   	if(sigbuf) OPENSSL_free(sigbuf);
406.   	if (bmd != NULL) BIO_free(bmd);

int MAIN(int argc, char **argv)
	{
	ENGINE *e = NULL;
	unsigned char *buf=NULL;
	int i,err=0;
	const EVP_MD *md=NULL,*m;
	BIO *in=NULL,*inp;
	BIO *bmd=NULL;
	BIO *out = NULL;
	const char *name;
#define PROG_NAME_SIZE  39
	char pname[PROG_NAME_SIZE+1];
	int separator=0;
	int debug=0;
	int keyform=FORMAT_PEM;
	const char *outfile = NULL, *keyfile = NULL;
	const char *sigfile = NULL, *randfile = NULL;
	int out_bin = -1, want_pub = 0, do_verify = 0;
	EVP_PKEY *sigkey = NULL;
	unsigned char *sigbuf = NULL;
	int siglen = 0;
	char *passargin = NULL, *passin = NULL;
#ifndef OPENSSL_NO_ENGINE
	char *engine=NULL;
#endif
	apps_startup();
	if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)
		{
		BIO_printf(bio_err,"out of memory\n");
		goto end;
		}
	if (bio_err == NULL)
		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
	if (!load_config(bio_err, NULL))
		goto end;
	program_name(argv[0],pname,sizeof pname);
	md=EVP_get_digestbyname(pname);
	argc--;
	argv++;
	while (argc > 0)
		{
		if ((*argv)[0] != '-') break;
		if (strcmp(*argv,"-c") == 0)
			separator=1;
		else if (strcmp(*argv,"-rand") == 0)
			{
			if (--argc < 1) break;
			randfile=*(++argv);
			}
		else if (strcmp(*argv,"-out") == 0)
			{
			if (--argc < 1) break;
			outfile=*(++argv);
			}
		else if (strcmp(*argv,"-sign") == 0)
			{
			if (--argc < 1) break;
			keyfile=*(++argv);
			}
		else if (!strcmp(*argv,"-passin"))
			{
			if (--argc < 1)
				break;
			passargin=*++argv;
			}
		else if (strcmp(*argv,"-verify") == 0)
			{
			if (--argc < 1) break;
			keyfile=*(++argv);
			want_pub = 1;
			do_verify = 1;
			}
		else if (strcmp(*argv,"-prverify") == 0)
			{
			if (--argc < 1) break;
			keyfile=*(++argv);
			do_verify = 1;
			}
		else if (strcmp(*argv,"-signature") == 0)
			{
			if (--argc < 1) break;
			sigfile=*(++argv);
			}
		else if (strcmp(*argv,"-keyform") == 0)
			{
			if (--argc < 1) break;
			keyform=str2fmt(*(++argv));
			}
#ifndef OPENSSL_NO_ENGINE
		else if (strcmp(*argv,"-engine") == 0)
			{
			if (--argc < 1) break;
			engine= *(++argv);
			}
#endif
		else if (strcmp(*argv,"-hex") == 0)
			out_bin = 0;
		else if (strcmp(*argv,"-binary") == 0)
			out_bin = 1;
		else if (strcmp(*argv,"-d") == 0)
			debug=1;
		else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)
			md=m;
		else
			break;
		argc--;
		argv++;
		}
	if (md == NULL)
		md=EVP_md5();
	if(do_verify && !sigfile) {
		BIO_printf(bio_err, "No signature to verify: use the -signature option\n");
		err = 1;
		goto end;
	}
	if ((argc > 0) && (argv[0][0] == '-'))
		{
		BIO_printf(bio_err,"unknown option '%s'\n",*argv);
		BIO_printf(bio_err,"options are\n");
		BIO_printf(bio_err,"-c              to output the digest with separating colons\n");
		BIO_printf(bio_err,"-d              to output debug info\n");
		BIO_printf(bio_err,"-hex            output as hex dump\n");
		BIO_printf(bio_err,"-binary         output in binary form\n");
		BIO_printf(bio_err,"-sign   file    sign digest using private key in file\n");
		BIO_printf(bio_err,"-verify file    verify a signature using public key in file\n");
		BIO_printf(bio_err,"-prverify file  verify a signature using private key in file\n");
		BIO_printf(bio_err,"-keyform arg    key file format (PEM or ENGINE)\n");
		BIO_printf(bio_err,"-signature file signature to verify\n");
		BIO_printf(bio_err,"-binary         output in binary form\n");
#ifndef OPENSSL_NO_ENGINE
		BIO_printf(bio_err,"-engine e       use engine e, possibly a hardware device.\n");
#endif
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm (default)\n",
			LN_md5,LN_md5);
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_md4,LN_md4);
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_md2,LN_md2);
#ifndef OPENSSL_NO_SHA
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_sha1,LN_sha1);
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_sha,LN_sha);
#ifndef OPENSSL_NO_SHA256
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_sha256,LN_sha256);
#endif
#ifndef OPENSSL_NO_SHA512
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_sha512,LN_sha512);
#endif
#endif
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_mdc2,LN_mdc2);
		BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n",
			LN_ripemd160,LN_ripemd160);
		err=1;
		goto end;
		}
#ifndef OPENSSL_NO_ENGINE
        e = setup_engine(bio_err, engine, 0);
#endif
	in=BIO_new(BIO_s_file());
	bmd=BIO_new(BIO_f_md());
	if (debug)
		{
		BIO_set_callback(in,BIO_debug_callback);
		BIO_set_callback_arg(in,bio_err);
		}
	if(!app_passwd(bio_err, passargin, NULL, &passin, NULL))
		{
		BIO_printf(bio_err, "Error getting password\n");
		goto end;
		}
	if ((in == NULL) || (bmd == NULL))
		{
		ERR_print_errors(bio_err);
		goto end;
		}
	if(out_bin == -1) {
		if(keyfile) out_bin = 1;
		else out_bin = 0;
	}
	if(randfile)
		app_RAND_load_file(randfile, bio_err, 0);
	if(outfile) {
		if(out_bin)
			out = BIO_new_file(outfile, "wb");
		else    out = BIO_new_file(outfile, "w");
	} 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(!out) {
		BIO_printf(bio_err, "Error opening output file %s\n",
					outfile ? outfile : "(stdout)");
		ERR_print_errors(bio_err);
		goto end;
	}
	if(keyfile)
		{
		if (want_pub)
			sigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL,
				e, "key file");
		else
			sigkey = load_key(bio_err, keyfile, keyform, 0, passin,
				e, "key file");
		if (!sigkey)
			{
			goto end;
			}
		}
	if(sigfile && sigkey) {
		BIO *sigbio;
		sigbio = BIO_new_file(sigfile, "rb");
		siglen = EVP_PKEY_size(sigkey);
		sigbuf = OPENSSL_malloc(siglen);
		if(!sigbio) {
			BIO_printf(bio_err, "Error opening signature file %s\n",
								sigfile);
			ERR_print_errors(bio_err);
			goto end;
		}
		siglen = BIO_read(sigbio, sigbuf, siglen);
		BIO_free(sigbio);
		if(siglen <= 0) {
			BIO_printf(bio_err, "Error reading signature file %s\n",
								sigfile);
			ERR_print_errors(bio_err);
			goto end;
		}
	}
	if (!BIO_set_md(bmd,md))
		{
		BIO_printf(bio_err, "Error setting digest %s\n", pname);
		ERR_print_errors(bio_err);
		goto end;
		}
	inp=BIO_push(bmd,in);
	if (argc == 0)
		{
		BIO_set_fp(in,stdin,BIO_NOCLOSE);
		err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,
			  siglen,"","(stdin)");
		}
	else
		{
		name=OBJ_nid2sn(md->type);
		for (i=0; i<argc; i++)
			{
			char *tmp,*tofree=NULL;
			int r;
			if (BIO_read_filename(in,argv[i]) <= 0)
				{
				perror(argv[i]);
				err++;
				continue;
				}
			if(!out_bin)
				{
				size_t len = strlen(name)+strlen(argv[i])+5;
				tmp=tofree=OPENSSL_malloc(len);
				BIO_snprintf(tmp,len,"%s(%s)= ",name,argv[i]);
				}
			else
				tmp="";
			r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,
				siglen,tmp,argv[i]);
			if(r)
			    err=r;
			if(tofree)
				OPENSSL_free(tofree);
			(void)BIO_reset(bmd);
			}
		}
end:
	if (buf != NULL)
		{
		OPENSSL_cleanse(buf,BUFSIZE);
		OPENSSL_free(buf);
		}
	if (in != NULL) BIO_free(in);
	if (passin)
		OPENSSL_free(passin);
	BIO_free_all(out);
	EVP_PKEY_free(sigkey);
	if(sigbuf) OPENSSL_free(sigbuf);
	if (bmd != NULL) BIO_free(bmd);
	apps_shutdown();
	OPENSSL_EXIT(err);
	}
['int MAIN(int argc, char **argv)\n\t{\n\tENGINE *e = NULL;\n\tunsigned char *buf=NULL;\n\tint i,err=0;\n\tconst EVP_MD *md=NULL,*m;\n\tBIO *in=NULL,*inp;\n\tBIO *bmd=NULL;\n\tBIO *out = NULL;\n\tconst char *name;\n#define PROG_NAME_SIZE  39\n\tchar pname[PROG_NAME_SIZE+1];\n\tint separator=0;\n\tint debug=0;\n\tint keyform=FORMAT_PEM;\n\tconst char *outfile = NULL, *keyfile = NULL;\n\tconst char *sigfile = NULL, *randfile = NULL;\n\tint out_bin = -1, want_pub = 0, do_verify = 0;\n\tEVP_PKEY *sigkey = NULL;\n\tunsigned char *sigbuf = NULL;\n\tint siglen = 0;\n\tchar *passargin = NULL, *passin = NULL;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tapps_startup();\n\tif ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\tprogram_name(argv[0],pname,sizeof pname);\n\tmd=EVP_get_digestbyname(pname);\n\targc--;\n\targv++;\n\twhile (argc > 0)\n\t\t{\n\t\tif ((*argv)[0] != \'-\') break;\n\t\tif (strcmp(*argv,"-c") == 0)\n\t\t\tseparator=1;\n\t\telse if (strcmp(*argv,"-rand") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\trandfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\toutfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-sign") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyfile=*(++argv);\n\t\t\t}\n\t\telse if (!strcmp(*argv,"-passin"))\n\t\t\t{\n\t\t\tif (--argc < 1)\n\t\t\t\tbreak;\n\t\t\tpassargin=*++argv;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-verify") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyfile=*(++argv);\n\t\t\twant_pub = 1;\n\t\t\tdo_verify = 1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-prverify") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyfile=*(++argv);\n\t\t\tdo_verify = 1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-signature") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tsigfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyform=str2fmt(*(++argv));\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if (strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tengine= *(++argv);\n\t\t\t}\n#endif\n\t\telse if (strcmp(*argv,"-hex") == 0)\n\t\t\tout_bin = 0;\n\t\telse if (strcmp(*argv,"-binary") == 0)\n\t\t\tout_bin = 1;\n\t\telse if (strcmp(*argv,"-d") == 0)\n\t\t\tdebug=1;\n\t\telse if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)\n\t\t\tmd=m;\n\t\telse\n\t\t\tbreak;\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (md == NULL)\n\t\tmd=EVP_md5();\n\tif(do_verify && !sigfile) {\n\t\tBIO_printf(bio_err, "No signature to verify: use the -signature option\\n");\n\t\terr = 1;\n\t\tgoto end;\n\t}\n\tif ((argc > 0) && (argv[0][0] == \'-\'))\n\t\t{\n\t\tBIO_printf(bio_err,"unknown option \'%s\'\\n",*argv);\n\t\tBIO_printf(bio_err,"options are\\n");\n\t\tBIO_printf(bio_err,"-c              to output the digest with separating colons\\n");\n\t\tBIO_printf(bio_err,"-d              to output debug info\\n");\n\t\tBIO_printf(bio_err,"-hex            output as hex dump\\n");\n\t\tBIO_printf(bio_err,"-binary         output in binary form\\n");\n\t\tBIO_printf(bio_err,"-sign   file    sign digest using private key in file\\n");\n\t\tBIO_printf(bio_err,"-verify file    verify a signature using public key in file\\n");\n\t\tBIO_printf(bio_err,"-prverify file  verify a signature using private key in file\\n");\n\t\tBIO_printf(bio_err,"-keyform arg    key file format (PEM or ENGINE)\\n");\n\t\tBIO_printf(bio_err,"-signature file signature to verify\\n");\n\t\tBIO_printf(bio_err,"-binary         output in binary form\\n");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err,"-engine e       use engine e, possibly a hardware device.\\n");\n#endif\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm (default)\\n",\n\t\t\tLN_md5,LN_md5);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_md4,LN_md4);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_md2,LN_md2);\n#ifndef OPENSSL_NO_SHA\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_sha1,LN_sha1);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_sha,LN_sha);\n#ifndef OPENSSL_NO_SHA256\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_sha256,LN_sha256);\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_sha512,LN_sha512);\n#endif\n#endif\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_mdc2,LN_mdc2);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_ripemd160,LN_ripemd160);\n\t\terr=1;\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_ENGINE\n        e = setup_engine(bio_err, engine, 0);\n#endif\n\tin=BIO_new(BIO_s_file());\n\tbmd=BIO_new(BIO_f_md());\n\tif (debug)\n\t\t{\n\t\tBIO_set_callback(in,BIO_debug_callback);\n\t\tBIO_set_callback_arg(in,bio_err);\n\t\t}\n\tif(!app_passwd(bio_err, passargin, NULL, &passin, NULL))\n\t\t{\n\t\tBIO_printf(bio_err, "Error getting password\\n");\n\t\tgoto end;\n\t\t}\n\tif ((in == NULL) || (bmd == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif(out_bin == -1) {\n\t\tif(keyfile) out_bin = 1;\n\t\telse out_bin = 0;\n\t}\n\tif(randfile)\n\t\tapp_RAND_load_file(randfile, bio_err, 0);\n\tif(outfile) {\n\t\tif(out_bin)\n\t\t\tout = BIO_new_file(outfile, "wb");\n\t\telse    out = BIO_new_file(outfile, "w");\n\t} else {\n\t\tout = BIO_new_fp(stdout, BIO_NOCLOSE);\n#ifdef OPENSSL_SYS_VMS\n\t\t{\n\t\tBIO *tmpbio = BIO_new(BIO_f_linebuffer());\n\t\tout = BIO_push(tmpbio, out);\n\t\t}\n#endif\n\t}\n\tif(!out) {\n\t\tBIO_printf(bio_err, "Error opening output file %s\\n",\n\t\t\t\t\toutfile ? outfile : "(stdout)");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tif(keyfile)\n\t\t{\n\t\tif (want_pub)\n\t\t\tsigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL,\n\t\t\t\te, "key file");\n\t\telse\n\t\t\tsigkey = load_key(bio_err, keyfile, keyform, 0, passin,\n\t\t\t\te, "key file");\n\t\tif (!sigkey)\n\t\t\t{\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif(sigfile && sigkey) {\n\t\tBIO *sigbio;\n\t\tsigbio = BIO_new_file(sigfile, "rb");\n\t\tsiglen = EVP_PKEY_size(sigkey);\n\t\tsigbuf = OPENSSL_malloc(siglen);\n\t\tif(!sigbio) {\n\t\t\tBIO_printf(bio_err, "Error opening signature file %s\\n",\n\t\t\t\t\t\t\t\tsigfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t\tsiglen = BIO_read(sigbio, sigbuf, siglen);\n\t\tBIO_free(sigbio);\n\t\tif(siglen <= 0) {\n\t\t\tBIO_printf(bio_err, "Error reading signature file %s\\n",\n\t\t\t\t\t\t\t\tsigfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t}\n\tif (!BIO_set_md(bmd,md))\n\t\t{\n\t\tBIO_printf(bio_err, "Error setting digest %s\\n", pname);\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tinp=BIO_push(bmd,in);\n\tif (argc == 0)\n\t\t{\n\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\t\terr=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,\n\t\t\t  siglen,"","(stdin)");\n\t\t}\n\telse\n\t\t{\n\t\tname=OBJ_nid2sn(md->type);\n\t\tfor (i=0; i<argc; i++)\n\t\t\t{\n\t\t\tchar *tmp,*tofree=NULL;\n\t\t\tint r;\n\t\t\tif (BIO_read_filename(in,argv[i]) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(argv[i]);\n\t\t\t\terr++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tif(!out_bin)\n\t\t\t\t{\n\t\t\t\tsize_t len = strlen(name)+strlen(argv[i])+5;\n\t\t\t\ttmp=tofree=OPENSSL_malloc(len);\n\t\t\t\tBIO_snprintf(tmp,len,"%s(%s)= ",name,argv[i]);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ttmp="";\n\t\t\tr=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,\n\t\t\t\tsiglen,tmp,argv[i]);\n\t\t\tif(r)\n\t\t\t    err=r;\n\t\t\tif(tofree)\n\t\t\t\tOPENSSL_free(tofree);\n\t\t\t(void)BIO_reset(bmd);\n\t\t\t}\n\t\t}\nend:\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,BUFSIZE);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tif (in != NULL) BIO_free(in);\n\tif (passin)\n\t\tOPENSSL_free(passin);\n\tBIO_free_all(out);\n\tEVP_PKEY_free(sigkey);\n\tif(sigbuf) OPENSSL_free(sigbuf);\n\tif (bmd != NULL) BIO_free(bmd);\n\tapps_shutdown();\n\tOPENSSL_EXIT(err);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n        if(ret && (num > 2048))\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'int BIO_printf (BIO *bio, const char *format, ...)\n\t{\n\tva_list args;\n\tint ret;\n\tva_start(args, format);\n\tret = BIO_vprintf(bio, format, args);\n\tva_end(args);\n\treturn(ret);\n\t}', 'void BIO_free_all(BIO *bio)\n\t{\n\tBIO *b;\n\tint ref;\n\twhile (bio != NULL)\n\t\t{\n\t\tb=bio;\n\t\tref=b->references;\n\t\tbio=bio->next_bio;\n\t\tBIO_free(b);\n\t\tif (ref > 1) break;\n\t\t}\n\t}']