apps/crl2p7.c:144: error: NULL_DEREFERENCE
  pointer `certflst` last assigned on line 143 could be null and is dereferenced by call to `sk_push()` at line 144, column 4.
Showing all 53 steps of the trace


apps/crl2p7.c:86:1: start of procedure crl2pkcs7_main()
84.   int MAIN(int, char **);
85.   
86. > int MAIN(int argc, char **argv)
87.   	{
88.   	int i,badops=0;

apps/crl2p7.c:88:2: 
86.   int MAIN(int argc, char **argv)
87.   	{
88. > 	int i,badops=0;
89.   	BIO *in=NULL,*out=NULL;
90.   	int informat,outformat;

apps/crl2p7.c:89:2: 
87.   	{
88.   	int i,badops=0;
89. > 	BIO *in=NULL,*out=NULL;
90.   	int informat,outformat;
91.   	char *infile,*outfile,*prog,*certfile;

apps/crl2p7.c:92:2: 
90.   	int informat,outformat;
91.   	char *infile,*outfile,*prog,*certfile;
92. > 	PKCS7 *p7 = NULL;
93.   	PKCS7_SIGNED *p7s = NULL;
94.   	X509_CRL *crl=NULL;

apps/crl2p7.c:93:2: 
91.   	char *infile,*outfile,*prog,*certfile;
92.   	PKCS7 *p7 = NULL;
93. > 	PKCS7_SIGNED *p7s = NULL;
94.   	X509_CRL *crl=NULL;
95.   	STACK_OF(OPENSSL_STRING) *certflst=NULL;

apps/crl2p7.c:94:2: 
92.   	PKCS7 *p7 = NULL;
93.   	PKCS7_SIGNED *p7s = NULL;
94. > 	X509_CRL *crl=NULL;
95.   	STACK_OF(OPENSSL_STRING) *certflst=NULL;
96.   	STACK_OF(X509_CRL) *crl_stack=NULL;

apps/crl2p7.c:95:2: 
93.   	PKCS7_SIGNED *p7s = NULL;
94.   	X509_CRL *crl=NULL;
95. > 	STACK_OF(OPENSSL_STRING) *certflst=NULL;
96.   	STACK_OF(X509_CRL) *crl_stack=NULL;
97.   	STACK_OF(X509) *cert_stack=NULL;

apps/crl2p7.c:96:2: 
94.   	X509_CRL *crl=NULL;
95.   	STACK_OF(OPENSSL_STRING) *certflst=NULL;
96. > 	STACK_OF(X509_CRL) *crl_stack=NULL;
97.   	STACK_OF(X509) *cert_stack=NULL;
98.   	int ret=1,nocrl=0;

apps/crl2p7.c:97:2: 
95.   	STACK_OF(OPENSSL_STRING) *certflst=NULL;
96.   	STACK_OF(X509_CRL) *crl_stack=NULL;
97. > 	STACK_OF(X509) *cert_stack=NULL;
98.   	int ret=1,nocrl=0;
99.   

apps/crl2p7.c:98:2: 
96.   	STACK_OF(X509_CRL) *crl_stack=NULL;
97.   	STACK_OF(X509) *cert_stack=NULL;
98. > 	int ret=1,nocrl=0;
99.   
100.   	apps_startup();

apps/crl2p7.c:100:2: 
98.   	int ret=1,nocrl=0;
99.   
100. > 	apps_startup();
101.   
102.   	if (bio_err == NULL)

apps/crl2p7.c:102:6: Taking false branch
100.   	apps_startup();
101.   
102.   	if (bio_err == NULL)
            ^
103.   		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
104.   			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);

apps/crl2p7.c:106:2: 
104.   			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
105.   
106. > 	infile=NULL;
107.   	outfile=NULL;
108.   	informat=FORMAT_PEM;

apps/crl2p7.c:107:2: 
105.   
106.   	infile=NULL;
107. > 	outfile=NULL;
108.   	informat=FORMAT_PEM;
109.   	outformat=FORMAT_PEM;

apps/crl2p7.c:108:2: 
106.   	infile=NULL;
107.   	outfile=NULL;
108. > 	informat=FORMAT_PEM;
109.   	outformat=FORMAT_PEM;
110.   

apps/crl2p7.c:109:2: 
107.   	outfile=NULL;
108.   	informat=FORMAT_PEM;
109. > 	outformat=FORMAT_PEM;
110.   
111.   	prog=argv[0];

apps/crl2p7.c:111:2: 
109.   	outformat=FORMAT_PEM;
110.   
111. > 	prog=argv[0];
112.   	argc--;
113.   	argv++;

apps/crl2p7.c:112:2: 
110.   
111.   	prog=argv[0];
112. > 	argc--;
113.   	argv++;
114.   	while (argc >= 1)

apps/crl2p7.c:113:2: 
111.   	prog=argv[0];
112.   	argc--;
113. > 	argv++;
114.   	while (argc >= 1)
115.   		{

apps/crl2p7.c:114:9: Loop condition is true. Entering loop body
112.   	argc--;
113.   	argv++;
114.   	while (argc >= 1)
               ^
115.   		{
116.   		if 	(strcmp(*argv,"-inform") == 0)

apps/crl2p7.c:116:8: Taking false branch
114.   	while (argc >= 1)
115.   		{
116.   		if 	(strcmp(*argv,"-inform") == 0)
              ^
117.   			{
118.   			if (--argc < 1) goto bad;

apps/crl2p7.c:121:12: Taking false branch
119.   			informat=str2fmt(*(++argv));
120.   			}
121.   		else if (strcmp(*argv,"-outform") == 0)
                  ^
122.   			{
123.   			if (--argc < 1) goto bad;

apps/crl2p7.c:126:12: Taking false branch
124.   			outformat=str2fmt(*(++argv));
125.   			}
126.   		else if (strcmp(*argv,"-in") == 0)
                  ^
127.   			{
128.   			if (--argc < 1) goto bad;

apps/crl2p7.c:131:12: Taking false branch
129.   			infile= *(++argv);
130.   			}
131.   		else if (strcmp(*argv,"-nocrl") == 0)
                  ^
132.   			{
133.   			nocrl=1;

apps/crl2p7.c:135:12: Taking false branch
133.   			nocrl=1;
134.   			}
135.   		else if (strcmp(*argv,"-out") == 0)
                  ^
136.   			{
137.   			if (--argc < 1) goto bad;

apps/crl2p7.c:140:12: Taking true branch
138.   			outfile= *(++argv);
139.   			}
140.   		else if (strcmp(*argv,"-certfile") == 0)
                  ^
141.   			{
142.   			if (--argc < 1) goto bad;

apps/crl2p7.c:142:8: Taking false branch
140.   		else if (strcmp(*argv,"-certfile") == 0)
141.   			{
142.   			if (--argc < 1) goto bad;
              ^
143.   			if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
144.   			sk_OPENSSL_STRING_push(certflst,*(++argv));

apps/crl2p7.c:143:8: Taking true branch
141.   			{
142.   			if (--argc < 1) goto bad;
143.   			if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
              ^
144.   			sk_OPENSSL_STRING_push(certflst,*(++argv));
145.   			}

apps/crl2p7.c:143:18: 
141.   			{
142.   			if (--argc < 1) goto bad;
143. > 			if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
144.   			sk_OPENSSL_STRING_push(certflst,*(++argv));
145.   			}

crypto/stack/stack.c:115:1: start of procedure sk_new_null()
  113.   	}
  114.   
  115. > _STACK *sk_new_null(void)
  116.   	{
  117.   	return sk_new((int (*)(const void *, const void *))0);

crypto/stack/stack.c:117:2: 
  115.   _STACK *sk_new_null(void)
  116.   	{
  117. > 	return sk_new((int (*)(const void *, const void *))0);
  118.   	}
  119.   

crypto/stack/stack.c:120:1: start of procedure sk_new()
    118.   	}
    119.   
    120. > _STACK *sk_new(int (*c)(const void *, const void *))
    121.   	{
    122.   	_STACK *ret;

crypto/stack/stack.c:125:6: 
    123.   	int i;
    124.   
    125. > 	if ((ret=OPENSSL_malloc(sizeof(_STACK))) == NULL)
    126.   		goto err;
    127.   	if ((ret->data=OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)

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

crypto/mem.c:296:2: 
      294.   void *CRYPTO_malloc(int num, const char *file, int line)
      295.   	{
      296. > 	void *ret = NULL;
      297.   
      298.   	if (num <= 0) return NULL;

crypto/mem.c:298:6: Taking false branch
      296.   	void *ret = NULL;
      297.   
      298.   	if (num <= 0) return NULL;
                  ^
      299.   
      300.   	allow_customize = 0;

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

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

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

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

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

crypto/mem.c:323:2: 
      321.   #endif
      322.   
      323. > 	return ret;
      324.   	}
      325.   char *CRYPTO_strdup(const char *str, const char *file, int line)

crypto/mem.c:324:2: return from a call to CRYPTO_malloc
      322.   
      323.   	return ret;
      324.   	}
              ^
      325.   char *CRYPTO_strdup(const char *str, const char *file, int line)
      326.   	{

crypto/stack/stack.c:125:6: Taking true branch
    123.   	int i;
    124.   
    125.   	if ((ret=OPENSSL_malloc(sizeof(_STACK))) == NULL)
                ^
    126.   		goto err;
    127.   	if ((ret->data=OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)

crypto/stack/stack.c:136:1: 
    134.   	ret->sorted=0;
    135.   	return(ret);
    136. > err:
    137.   	if(ret)
    138.   		OPENSSL_free(ret);

crypto/stack/stack.c:137:5: Taking false branch
    135.   	return(ret);
    136.   err:
    137.   	if(ret)
               ^
    138.   		OPENSSL_free(ret);
    139.   	return(NULL);

crypto/stack/stack.c:139:2: 
    137.   	if(ret)
    138.   		OPENSSL_free(ret);
    139. > 	return(NULL);
    140.   	}
    141.   

crypto/stack/stack.c:140:2: return from a call to sk_new
    138.   		OPENSSL_free(ret);
    139.   	return(NULL);
    140.   	}
            ^
    141.   
    142.   int sk_insert(_STACK *st, void *data, int loc)

crypto/stack/stack.c:118:2: return from a call to sk_new_null
  116.   	{
  117.   	return sk_new((int (*)(const void *, const void *))0);
  118.   	}
          ^
  119.   
  120.   _STACK *sk_new(int (*c)(const void *, const void *))

apps/crl2p7.c:144:4: Condition is true
142.   			if (--argc < 1) goto bad;
143.   			if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
144.   			sk_OPENSSL_STRING_push(certflst,*(++argv));
          ^
145.   			}
146.   		else

apps/crl2p7.c:144:4: Condition is true
142.   			if (--argc < 1) goto bad;
143.   			if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
144.   			sk_OPENSSL_STRING_push(certflst,*(++argv));
          ^
145.   			}
146.   		else

crypto/stack/stack.c:244:1: start of procedure sk_push()
  242.   	}
  243.   
  244. > int sk_push(_STACK *st, void *data)
  245.   	{
  246.   	return(sk_insert(st,data,st->num));

crypto/stack/stack.c:246:2: Skipping sk_insert(): empty list of specs
  244.   int sk_push(_STACK *st, void *data)
  245.   	{
  246.   	return(sk_insert(st,data,st->num));
          ^
  247.   	}
  248.   

int MAIN(int argc, char **argv)
	{
	int i,badops=0;
	BIO *in=NULL,*out=NULL;
	int informat,outformat;
	char *infile,*outfile,*prog,*certfile;
	PKCS7 *p7 = NULL;
	PKCS7_SIGNED *p7s = NULL;
	X509_CRL *crl=NULL;
	STACK_OF(OPENSSL_STRING) *certflst=NULL;
	STACK_OF(X509_CRL) *crl_stack=NULL;
	STACK_OF(X509) *cert_stack=NULL;
	int ret=1,nocrl=0;
	apps_startup();
	if (bio_err == NULL)
		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
	infile=NULL;
	outfile=NULL;
	informat=FORMAT_PEM;
	outformat=FORMAT_PEM;
	prog=argv[0];
	argc--;
	argv++;
	while (argc >= 1)
		{
		if 	(strcmp(*argv,"-inform") == 0)
			{
			if (--argc < 1) goto bad;
			informat=str2fmt(*(++argv));
			}
		else if (strcmp(*argv,"-outform") == 0)
			{
			if (--argc < 1) goto bad;
			outformat=str2fmt(*(++argv));
			}
		else if (strcmp(*argv,"-in") == 0)
			{
			if (--argc < 1) goto bad;
			infile= *(++argv);
			}
		else if (strcmp(*argv,"-nocrl") == 0)
			{
			nocrl=1;
			}
		else if (strcmp(*argv,"-out") == 0)
			{
			if (--argc < 1) goto bad;
			outfile= *(++argv);
			}
		else if (strcmp(*argv,"-certfile") == 0)
			{
			if (--argc < 1) goto bad;
			if(!certflst) certflst = sk_OPENSSL_STRING_new_null();
			sk_OPENSSL_STRING_push(certflst,*(++argv));
			}
		else
			{
			BIO_printf(bio_err,"unknown option %s\n",*argv);
			badops=1;
			break;
			}
		argc--;
		argv++;
		}
	if (badops)
		{
bad:
		BIO_printf(bio_err,"%s [options] <infile >outfile\n",prog);
		BIO_printf(bio_err,"where options are\n");
		BIO_printf(bio_err," -inform arg    input format - DER or PEM\n");
		BIO_printf(bio_err," -outform arg   output format - DER or PEM\n");
		BIO_printf(bio_err," -in arg        input file\n");
		BIO_printf(bio_err," -out arg       output file\n");
		BIO_printf(bio_err," -certfile arg  certificates file of chain to a trusted CA\n");
		BIO_printf(bio_err,"                (can be used more than once)\n");
		BIO_printf(bio_err," -nocrl         no crl to load, just certs from '-certfile'\n");
		ret = 1;
		goto end;
		}
	ERR_load_crypto_strings();
	in=BIO_new(BIO_s_file());
	out=BIO_new(BIO_s_file());
	if ((in == NULL) || (out == NULL))
		{
		ERR_print_errors(bio_err);
		goto end;
		}
	if (!nocrl)
		{
		if (infile == NULL)
			BIO_set_fp(in,stdin,BIO_NOCLOSE);
		else
			{
			if (BIO_read_filename(in,infile) <= 0)
				{
				perror(infile);
				goto end;
				}
			}
		if 	(informat == FORMAT_ASN1)
			crl=d2i_X509_CRL_bio(in,NULL);
		else if (informat == FORMAT_PEM)
			crl=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
		else	{
			BIO_printf(bio_err,"bad input format specified for input crl\n");
			goto end;
			}
		if (crl == NULL)
			{
			BIO_printf(bio_err,"unable to load CRL\n");
			ERR_print_errors(bio_err);
			goto end;
			}
		}
	if ((p7=PKCS7_new()) == NULL) goto end;
	if ((p7s=PKCS7_SIGNED_new()) == NULL) goto end;
	p7->type=OBJ_nid2obj(NID_pkcs7_signed);
	p7->d.sign=p7s;
	p7s->contents->type=OBJ_nid2obj(NID_pkcs7_data);
	if (!ASN1_INTEGER_set(p7s->version,1)) goto end;
	if ((crl_stack=sk_X509_CRL_new_null()) == NULL) goto end;
	p7s->crl=crl_stack;
	if (crl != NULL)
		{
		sk_X509_CRL_push(crl_stack,crl);
		crl=NULL;
		}
	if ((cert_stack=sk_X509_new_null()) == NULL) goto end;
	p7s->cert=cert_stack;
	if(certflst) for(i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) {
		certfile = sk_OPENSSL_STRING_value(certflst, i);
		if (add_certs_from_file(cert_stack,certfile) < 0)
			{
			BIO_printf(bio_err, "error loading certificates\n");
			ERR_print_errors(bio_err);
			goto end;
			}
	}
	sk_OPENSSL_STRING_free(certflst);
	if (outfile == NULL)
		{
		BIO_set_fp(out,stdout,BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
		{
		BIO *tmpbio = BIO_new(BIO_f_linebuffer());
		out = BIO_push(tmpbio, out);
		}
#endif
		}
	else
		{
		if (BIO_write_filename(out,outfile) <= 0)
			{
			perror(outfile);
			goto end;
			}
		}
	if 	(outformat == FORMAT_ASN1)
		i=i2d_PKCS7_bio(out,p7);
	else if (outformat == FORMAT_PEM)
		i=PEM_write_bio_PKCS7(out,p7);
	else	{
		BIO_printf(bio_err,"bad output format specified for outfile\n");
		goto end;
		}
	if (!i)
		{
		BIO_printf(bio_err,"unable to write pkcs7 object\n");
		ERR_print_errors(bio_err);
		goto end;
		}
	ret=0;
end:
	if (in != NULL) BIO_free(in);
	if (out != NULL) BIO_free_all(out);
	if (p7 != NULL) PKCS7_free(p7);
	if (crl != NULL) X509_CRL_free(crl);
	apps_shutdown();
	OPENSSL_EXIT(ret);
	}
['int MAIN(int argc, char **argv)\n\t{\n\tint i,badops=0;\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat;\n\tchar *infile,*outfile,*prog,*certfile;\n\tPKCS7 *p7 = NULL;\n\tPKCS7_SIGNED *p7s = NULL;\n\tX509_CRL *crl=NULL;\n\tSTACK_OF(OPENSSL_STRING) *certflst=NULL;\n\tSTACK_OF(X509_CRL) *crl_stack=NULL;\n\tSTACK_OF(X509) *cert_stack=NULL;\n\tint ret=1,nocrl=0;\n\tapps_startup();\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\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tprog=argv[0];\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,"-inform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-nocrl") == 0)\n\t\t\t{\n\t\t\tnocrl=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-certfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tif(!certflst) certflst = sk_OPENSSL_STRING_new_null();\n\t\t\tsk_OPENSSL_STRING_push(certflst,*(++argv));\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\nbad:\n\t\tBIO_printf(bio_err,"%s [options] <infile >outfile\\n",prog);\n\t\tBIO_printf(bio_err,"where options are\\n");\n\t\tBIO_printf(bio_err," -inform arg    input format - DER or PEM\\n");\n\t\tBIO_printf(bio_err," -outform arg   output format - DER or PEM\\n");\n\t\tBIO_printf(bio_err," -in arg        input file\\n");\n\t\tBIO_printf(bio_err," -out arg       output file\\n");\n\t\tBIO_printf(bio_err," -certfile arg  certificates file of chain to a trusted CA\\n");\n\t\tBIO_printf(bio_err,"                (can be used more than once)\\n");\n\t\tBIO_printf(bio_err," -nocrl         no crl to load, just certs from \'-certfile\'\\n");\n\t\tret = 1;\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (!nocrl)\n\t\t{\n\t\tif (infile == NULL)\n\t\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(infile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif \t(informat == FORMAT_ASN1)\n\t\t\tcrl=d2i_X509_CRL_bio(in,NULL);\n\t\telse if (informat == FORMAT_PEM)\n\t\t\tcrl=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);\n\t\telse\t{\n\t\t\tBIO_printf(bio_err,"bad input format specified for input crl\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (crl == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load CRL\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif ((p7=PKCS7_new()) == NULL) goto end;\n\tif ((p7s=PKCS7_SIGNED_new()) == NULL) goto end;\n\tp7->type=OBJ_nid2obj(NID_pkcs7_signed);\n\tp7->d.sign=p7s;\n\tp7s->contents->type=OBJ_nid2obj(NID_pkcs7_data);\n\tif (!ASN1_INTEGER_set(p7s->version,1)) goto end;\n\tif ((crl_stack=sk_X509_CRL_new_null()) == NULL) goto end;\n\tp7s->crl=crl_stack;\n\tif (crl != NULL)\n\t\t{\n\t\tsk_X509_CRL_push(crl_stack,crl);\n\t\tcrl=NULL;\n\t\t}\n\tif ((cert_stack=sk_X509_new_null()) == NULL) goto end;\n\tp7s->cert=cert_stack;\n\tif(certflst) for(i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) {\n\t\tcertfile = sk_OPENSSL_STRING_value(certflst, i);\n\t\tif (add_certs_from_file(cert_stack,certfile) < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "error loading certificates\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t}\n\tsk_OPENSSL_STRING_free(certflst);\n\tif (outfile == NULL)\n\t\t{\n\t\tBIO_set_fp(out,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\t}\n\telse\n\t\t{\n\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t{\n\t\t\tperror(outfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif \t(outformat == FORMAT_ASN1)\n\t\ti=i2d_PKCS7_bio(out,p7);\n\telse if (outformat == FORMAT_PEM)\n\t\ti=PEM_write_bio_PKCS7(out,p7);\n\telse\t{\n\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\tgoto end;\n\t\t}\n\tif (!i)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to write pkcs7 object\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tret=0;\nend:\n\tif (in != NULL) BIO_free(in);\n\tif (out != NULL) BIO_free_all(out);\n\tif (p7 != NULL) PKCS7_free(p7);\n\tif (crl != NULL) X509_CRL_free(crl);\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}', '_STACK *sk_new_null(void)\n\t{\n\treturn sk_new((int (*)(const void *, const void *))0);\n\t}', '_STACK *sk_new(int (*c)(const void *, const void *))\n\t{\n\t_STACK *ret;\n\tint i;\n\tif ((ret=OPENSSL_malloc(sizeof(_STACK))) == NULL)\n\t\tgoto err;\n\tif ((ret->data=OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)\n\t\tgoto err;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->data[i]=NULL;\n\tret->comp=c;\n\tret->num_alloc=MIN_NODES;\n\tret->num=0;\n\tret->sorted=0;\n\treturn(ret);\nerr:\n\tif(ret)\n\t\tOPENSSL_free(ret);\n\treturn(NULL);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\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#ifndef OPENSSL_CPUID_OBJ\n        if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'int sk_push(_STACK *st, void *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}']