apps/verify.c:128: error: NULL_DEREFERENCE
  pointer `xptmp` last assigned on line 127 could be null and is dereferenced by call to `X509_PURPOSE_get_id()` at line 128, column 15.
Showing all 39 steps of the trace


apps/verify.c:79:1: start of procedure verify_main()
77.   int MAIN(int, char **);
78.   
79. > int MAIN(int argc, char **argv)
80.   	{
81.   	int i,ret=1;

apps/verify.c:81:2: 
79.   int MAIN(int argc, char **argv)
80.   	{
81. > 	int i,ret=1;
82.   	int purpose = -1;
83.   	char *CApath=NULL,*CAfile=NULL;

apps/verify.c:82:2: 
80.   	{
81.   	int i,ret=1;
82. > 	int purpose = -1;
83.   	char *CApath=NULL,*CAfile=NULL;
84.   	char *untfile = NULL;

apps/verify.c:83:2: 
81.   	int i,ret=1;
82.   	int purpose = -1;
83. > 	char *CApath=NULL,*CAfile=NULL;
84.   	char *untfile = NULL;
85.   	STACK_OF(X509) *untrusted = NULL;

apps/verify.c:84:2: 
82.   	int purpose = -1;
83.   	char *CApath=NULL,*CAfile=NULL;
84. > 	char *untfile = NULL;
85.   	STACK_OF(X509) *untrusted = NULL;
86.   	X509_STORE *cert_ctx=NULL;

apps/verify.c:85:2: 
83.   	char *CApath=NULL,*CAfile=NULL;
84.   	char *untfile = NULL;
85. > 	STACK_OF(X509) *untrusted = NULL;
86.   	X509_STORE *cert_ctx=NULL;
87.   	X509_LOOKUP *lookup=NULL;

apps/verify.c:86:2: 
84.   	char *untfile = NULL;
85.   	STACK_OF(X509) *untrusted = NULL;
86. > 	X509_STORE *cert_ctx=NULL;
87.   	X509_LOOKUP *lookup=NULL;
88.   

apps/verify.c:87:2: 
85.   	STACK_OF(X509) *untrusted = NULL;
86.   	X509_STORE *cert_ctx=NULL;
87. > 	X509_LOOKUP *lookup=NULL;
88.   
89.   	cert_ctx=X509_STORE_new();

apps/verify.c:89:2: Skipping X509_STORE_new(): empty list of specs
87.   	X509_LOOKUP *lookup=NULL;
88.   
89.   	cert_ctx=X509_STORE_new();
       ^
90.   	if (cert_ctx == NULL) goto end;
91.   	X509_STORE_set_verify_cb_func(cert_ctx,cb);

apps/verify.c:90:6: Taking false branch
88.   
89.   	cert_ctx=X509_STORE_new();
90.   	if (cert_ctx == NULL) goto end;
           ^
91.   	X509_STORE_set_verify_cb_func(cert_ctx,cb);
92.   

apps/verify.c:91:2: 
89.   	cert_ctx=X509_STORE_new();
90.   	if (cert_ctx == NULL) goto end;
91. > 	X509_STORE_set_verify_cb_func(cert_ctx,cb);
92.   
93.   	ERR_load_crypto_strings();

apps/verify.c:93:2: Skipping ERR_load_crypto_strings(): empty list of specs
91.   	X509_STORE_set_verify_cb_func(cert_ctx,cb);
92.   
93.   	ERR_load_crypto_strings();
       ^
94.   
95.   	apps_startup();

apps/verify.c:95:2: 
93.   	ERR_load_crypto_strings();
94.   
95. > 	apps_startup();
96.   
97.   	if (bio_err == NULL)

apps/verify.c:97:6: Taking false branch
95.   	apps_startup();
96.   
97.   	if (bio_err == NULL)
            ^
98.   		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
99.   			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);

apps/verify.c:101:2: 
99.   			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
100.   
101. > 	argc--;
102.   	argv++;
103.   	for (;;)

apps/verify.c:102:2: 
100.   
101.   	argc--;
102. > 	argv++;
103.   	for (;;)
104.   		{

apps/verify.c:148:3: Loop condition is true. Entering loop body
146.   		else
147.   			break;
148.   		}
         ^
149.   
150.   	lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());

apps/verify.c:105:7: Taking true branch
103.   	for (;;)
104.   		{
105.   		if (argc >= 1)
             ^
106.   			{
107.   			if (strcmp(*argv,"-CApath") == 0)

apps/verify.c:107:8: Taking false branch
105.   		if (argc >= 1)
106.   			{
107.   			if (strcmp(*argv,"-CApath") == 0)
              ^
108.   				{
109.   				if (argc-- < 1) goto end;

apps/verify.c:112:13: Taking false branch
110.   				CApath= *(++argv);
111.   				}
112.   			else if (strcmp(*argv,"-CAfile") == 0)
                   ^
113.   				{
114.   				if (argc-- < 1) goto end;

apps/verify.c:117:13: Taking true branch
115.   				CAfile= *(++argv);
116.   				}
117.   			else if (strcmp(*argv,"-purpose") == 0)
                   ^
118.   				{
119.   				X509_PURPOSE *xptmp;

apps/verify.c:120:9: Taking false branch
118.   				{
119.   				X509_PURPOSE *xptmp;
120.   				if (argc-- < 1) goto end;
               ^
121.   				i = X509_PURPOSE_get_by_sname(*(++argv));
122.   				if(i < 0)

apps/verify.c:121:5: Skipping X509_PURPOSE_get_by_sname(): empty list of specs
119.   				X509_PURPOSE *xptmp;
120.   				if (argc-- < 1) goto end;
121.   				i = X509_PURPOSE_get_by_sname(*(++argv));
           ^
122.   				if(i < 0)
123.   					{

apps/verify.c:122:8: Taking false branch
120.   				if (argc-- < 1) goto end;
121.   				i = X509_PURPOSE_get_by_sname(*(++argv));
122.   				if(i < 0)
              ^
123.   					{
124.   					BIO_printf(bio_err, "unrecognized purpose\n");

apps/verify.c:127:5: 
125.   					goto end;
126.   					}
127. > 				xptmp = X509_PURPOSE_get0(i);
128.   				purpose = X509_PURPOSE_get_id(xptmp);
129.   				}

crypto/x509v3/v3_purp.c:122:1: start of procedure X509_PURPOSE_get0()
  120.   }
  121.   
  122. > X509_PURPOSE * X509_PURPOSE_get0(int idx)
  123.   {
  124.   	if(idx < 0) return NULL;

crypto/x509v3/v3_purp.c:124:5: Taking false branch
  122.   X509_PURPOSE * X509_PURPOSE_get0(int idx)
  123.   {
  124.   	if(idx < 0) return NULL;
             ^
  125.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
  126.   	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);

crypto/x509v3/v3_purp.c:125:5: Taking false branch
  123.   {
  124.   	if(idx < 0) return NULL;
  125.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
             ^
  126.   	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
  127.   }

crypto/x509v3/v3_purp.c:126:2: 
  124.   	if(idx < 0) return NULL;
  125.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
  126. > 	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
  127.   }
  128.   

crypto/x509v3/v3_purp.c:91:1: start of procedure sk_X509_PURPOSE_value()
    89.   #define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
    90.   
    91. > IMPLEMENT_STACK_OF(X509_PURPOSE)
    92.   
    93.   static STACK_OF(X509_PURPOSE) *xptable = NULL;

crypto/stack/stack.c:289:1: start of procedure sk_value()
      287.   }
      288.   
      289. > char *sk_value(STACK *st, int i)
      290.   {
      291.   	if(st == NULL) return NULL;

crypto/stack/stack.c:291:5: Taking true branch
      289.   char *sk_value(STACK *st, int i)
      290.   {
      291.   	if(st == NULL) return NULL;
                 ^
      292.   	return st->data[i];
      293.   }

crypto/stack/stack.c:291:17: 
      289.   char *sk_value(STACK *st, int i)
      290.   {
      291. > 	if(st == NULL) return NULL;
      292.   	return st->data[i];
      293.   }

crypto/stack/stack.c:293:1: return from a call to sk_value
      291.   	if(st == NULL) return NULL;
      292.   	return st->data[i];
      293. > }
      294.   
      295.   char *sk_set(STACK *st, int i, char *value)

crypto/x509v3/v3_purp.c:91:1: return from a call to sk_X509_PURPOSE_value
    89.   #define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
    90.   
    91. > IMPLEMENT_STACK_OF(X509_PURPOSE)
    92.   
    93.   static STACK_OF(X509_PURPOSE) *xptable = NULL;

crypto/x509v3/v3_purp.c:127:1: return from a call to X509_PURPOSE_get0
  125.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
  126.   	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
  127. > }
  128.   
  129.   int X509_PURPOSE_get_by_sname(char *sname)

apps/verify.c:128:5: 
126.   					}
127.   				xptmp = X509_PURPOSE_get0(i);
128. > 				purpose = X509_PURPOSE_get_id(xptmp);
129.   				}
130.   			else if (strcmp(*argv,"-untrusted") == 0)

crypto/x509v3/v3_purp.c:232:1: start of procedure X509_PURPOSE_get_id()
  230.   }
  231.   
  232. > int X509_PURPOSE_get_id(X509_PURPOSE *xp)
  233.   {
  234.   	return xp->purpose;

crypto/x509v3/v3_purp.c:234:2: 
  232.   int X509_PURPOSE_get_id(X509_PURPOSE *xp)
  233.   {
  234. > 	return xp->purpose;
  235.   }
  236.   

int MAIN(int argc, char **argv)
	{
	int i,ret=1;
	int purpose = -1;
	char *CApath=NULL,*CAfile=NULL;
	char *untfile = NULL;
	STACK_OF(X509) *untrusted = NULL;
	X509_STORE *cert_ctx=NULL;
	X509_LOOKUP *lookup=NULL;
	cert_ctx=X509_STORE_new();
	if (cert_ctx == NULL) goto end;
	X509_STORE_set_verify_cb_func(cert_ctx,cb);
	ERR_load_crypto_strings();
	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);
	argc--;
	argv++;
	for (;;)
		{
		if (argc >= 1)
			{
			if (strcmp(*argv,"-CApath") == 0)
				{
				if (argc-- < 1) goto end;
				CApath= *(++argv);
				}
			else if (strcmp(*argv,"-CAfile") == 0)
				{
				if (argc-- < 1) goto end;
				CAfile= *(++argv);
				}
			else if (strcmp(*argv,"-purpose") == 0)
				{
				X509_PURPOSE *xptmp;
				if (argc-- < 1) goto end;
				i = X509_PURPOSE_get_by_sname(*(++argv));
				if(i < 0)
					{
					BIO_printf(bio_err, "unrecognized purpose\n");
					goto end;
					}
				xptmp = X509_PURPOSE_get0(i);
				purpose = X509_PURPOSE_get_id(xptmp);
				}
			else if (strcmp(*argv,"-untrusted") == 0)
				{
				if (argc-- < 1) goto end;
				untfile= *(++argv);
				}
			else if (strcmp(*argv,"-help") == 0)
				goto end;
			else if (strcmp(*argv,"-verbose") == 0)
				v_verbose=1;
			else if (argv[0][0] == '-')
				goto end;
			else
				break;
			argc--;
			argv++;
			}
		else
			break;
		}
	lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());
	if (lookup == NULL) abort();
	if (CAfile) {
		i=X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM);
		if(!i) {
			BIO_printf(bio_err, "Error loading file %s\n", CAfile);
			ERR_print_errors(bio_err);
			goto end;
		}
	} else X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
	lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_hash_dir());
	if (lookup == NULL) abort();
	if (CApath) {
		i=X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM);
		if(!i) {
			BIO_printf(bio_err, "Error loading directory %s\n", CApath);
			ERR_print_errors(bio_err);
			goto end;
		}
	} else X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
	ERR_clear_error();
	if(untfile) {
		if(!(untrusted = load_untrusted(untfile))) {
			BIO_printf(bio_err, "Error loading untrusted file %s\n", untfile);
			ERR_print_errors(bio_err);
			goto end;
		}
	}
	if (argc < 1) check(cert_ctx, NULL, untrusted, purpose);
	else
		for (i=0; i<argc; i++)
			check(cert_ctx,argv[i], untrusted, purpose);
	ret=0;
end:
	if (ret == 1) {
		BIO_printf(bio_err,"usage: verify [-verbose] [-CApath path] [-CAfile file] cert1 cert2 ...\n");
		BIO_printf(bio_err,"recognized usages:\n");
		for(i = 0; i < X509_PURPOSE_get_count(); i++) {
			X509_PURPOSE *ptmp;
			ptmp = X509_PURPOSE_get0(i);
			BIO_printf(bio_err, "\t%-10s\t%s\n", X509_PURPOSE_get0_sname(ptmp),
								X509_PURPOSE_get0_name(ptmp));
		}
	}
	if (cert_ctx != NULL) X509_STORE_free(cert_ctx);
	sk_X509_pop_free(untrusted, X509_free);
	EXIT(ret);
	}
['int MAIN(int argc, char **argv)\n\t{\n\tint i,ret=1;\n\tint purpose = -1;\n\tchar *CApath=NULL,*CAfile=NULL;\n\tchar *untfile = NULL;\n\tSTACK_OF(X509) *untrusted = NULL;\n\tX509_STORE *cert_ctx=NULL;\n\tX509_LOOKUP *lookup=NULL;\n\tcert_ctx=X509_STORE_new();\n\tif (cert_ctx == NULL) goto end;\n\tX509_STORE_set_verify_cb_func(cert_ctx,cb);\n\tERR_load_crypto_strings();\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\targc--;\n\targv++;\n\tfor (;;)\n\t\t{\n\t\tif (argc >= 1)\n\t\t\t{\n\t\t\tif (strcmp(*argv,"-CApath") == 0)\n\t\t\t\t{\n\t\t\t\tif (argc-- < 1) goto end;\n\t\t\t\tCApath= *(++argv);\n\t\t\t\t}\n\t\t\telse if (strcmp(*argv,"-CAfile") == 0)\n\t\t\t\t{\n\t\t\t\tif (argc-- < 1) goto end;\n\t\t\t\tCAfile= *(++argv);\n\t\t\t\t}\n\t\t\telse if (strcmp(*argv,"-purpose") == 0)\n\t\t\t\t{\n\t\t\t\tX509_PURPOSE *xptmp;\n\t\t\t\tif (argc-- < 1) goto end;\n\t\t\t\ti = X509_PURPOSE_get_by_sname(*(++argv));\n\t\t\t\tif(i < 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err, "unrecognized purpose\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\txptmp = X509_PURPOSE_get0(i);\n\t\t\t\tpurpose = X509_PURPOSE_get_id(xptmp);\n\t\t\t\t}\n\t\t\telse if (strcmp(*argv,"-untrusted") == 0)\n\t\t\t\t{\n\t\t\t\tif (argc-- < 1) goto end;\n\t\t\t\tuntfile= *(++argv);\n\t\t\t\t}\n\t\t\telse if (strcmp(*argv,"-help") == 0)\n\t\t\t\tgoto end;\n\t\t\telse if (strcmp(*argv,"-verbose") == 0)\n\t\t\t\tv_verbose=1;\n\t\t\telse if (argv[0][0] == \'-\')\n\t\t\t\tgoto end;\n\t\t\telse\n\t\t\t\tbreak;\n\t\t\targc--;\n\t\t\targv++;\n\t\t\t}\n\t\telse\n\t\t\tbreak;\n\t\t}\n\tlookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file());\n\tif (lookup == NULL) abort();\n\tif (CAfile) {\n\t\ti=X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM);\n\t\tif(!i) {\n\t\t\tBIO_printf(bio_err, "Error loading file %s\\n", CAfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t} else X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);\n\tlookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_hash_dir());\n\tif (lookup == NULL) abort();\n\tif (CApath) {\n\t\ti=X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM);\n\t\tif(!i) {\n\t\t\tBIO_printf(bio_err, "Error loading directory %s\\n", CApath);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t} else X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);\n\tERR_clear_error();\n\tif(untfile) {\n\t\tif(!(untrusted = load_untrusted(untfile))) {\n\t\t\tBIO_printf(bio_err, "Error loading untrusted file %s\\n", untfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t}\n\tif (argc < 1) check(cert_ctx, NULL, untrusted, purpose);\n\telse\n\t\tfor (i=0; i<argc; i++)\n\t\t\tcheck(cert_ctx,argv[i], untrusted, purpose);\n\tret=0;\nend:\n\tif (ret == 1) {\n\t\tBIO_printf(bio_err,"usage: verify [-verbose] [-CApath path] [-CAfile file] cert1 cert2 ...\\n");\n\t\tBIO_printf(bio_err,"recognized usages:\\n");\n\t\tfor(i = 0; i < X509_PURPOSE_get_count(); i++) {\n\t\t\tX509_PURPOSE *ptmp;\n\t\t\tptmp = X509_PURPOSE_get0(i);\n\t\t\tBIO_printf(bio_err, "\\t%-10s\\t%s\\n", X509_PURPOSE_get0_sname(ptmp),\n\t\t\t\t\t\t\t\tX509_PURPOSE_get0_name(ptmp));\n\t\t}\n\t}\n\tif (cert_ctx != NULL) X509_STORE_free(cert_ctx);\n\tsk_X509_pop_free(untrusted, X509_free);\n\tEXIT(ret);\n\t}', 'X509_PURPOSE * X509_PURPOSE_get0(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_PURPOSE_COUNT) return xstandard + idx;\n\treturn sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}', 'IMPLEMENT_STACK_OF(X509_PURPOSE)', 'char *sk_value(STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}', 'int X509_PURPOSE_get_id(X509_PURPOSE *xp)\n{\n\treturn xp->purpose;\n}']