crypto/x509/x509_vfy.c:586: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 584 could be null and is dereferenced at line 586, column 8.
Showing all 23 steps of the trace


crypto/x509/x509_vfy.c:540:1: start of procedure check_chain_extensions()
538.    */
539.   
540. > static int check_chain_extensions(X509_STORE_CTX *ctx)
541.   {
542.   #ifdef OPENSSL_NO_CHAIN_VERIFY

crypto/x509/x509_vfy.c:545:2: 
543.   	return 1;
544.   #else
545. > 	int i, ok=0, must_be_ca, plen = 0;
546.   	X509 *x;
547.   	int (*cb)(int xok,X509_STORE_CTX *xctx);

crypto/x509/x509_vfy.c:548:2: 
546.   	X509 *x;
547.   	int (*cb)(int xok,X509_STORE_CTX *xctx);
548. > 	int proxy_path_length = 0;
549.   	int purpose;
550.   	int allow_proxy_certs;

crypto/x509/x509_vfy.c:551:2: 
549.   	int purpose;
550.   	int allow_proxy_certs;
551. > 	cb=ctx->verify_cb;
552.   
553.   	/* must_be_ca can have 1 of 3 values:

crypto/x509/x509_vfy.c:561:2: 
559.   	       all certificates in the chain except the leaf certificate.
560.   	*/
561. > 	must_be_ca = -1;
562.   
563.   	/* CRL path validation */

crypto/x509/x509_vfy.c:564:6: Taking false branch
562.   
563.   	/* CRL path validation */
564.   	if (ctx->parent)
            ^
565.   		{
566.   		allow_proxy_certs = 0;

crypto/x509/x509_vfy.c:572:7: Condition is true
570.   		{
571.   		allow_proxy_certs =
572.   			!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
             ^
573.   		/* A hack to keep people who don't want to modify their
574.   		   software happy */

crypto/x509/x509_vfy.c:572:4: 
570.   		{
571.   		allow_proxy_certs =
572. > 			!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
573.   		/* A hack to keep people who don't want to modify their
574.   		   software happy */

crypto/x509/x509_vfy.c:571:3: 
569.   	else
570.   		{
571. > 		allow_proxy_certs =
572.   			!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
573.   		/* A hack to keep people who don't want to modify their

crypto/x509/x509_vfy.c:575:7: Taking false branch
573.   		/* A hack to keep people who don't want to modify their
574.   		   software happy */
575.   		if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
             ^
576.   			allow_proxy_certs = 1;
577.   		purpose = ctx->param->purpose;

crypto/x509/x509_vfy.c:577:3: 
575.   		if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
576.   			allow_proxy_certs = 1;
577. > 		purpose = ctx->param->purpose;
578.   		}
579.   

crypto/x509/x509_vfy.c:581:7: 
579.   
580.   	/* Check all untrusted certificates */
581. > 	for (i = 0; i < ctx->last_untrusted; i++)
582.   		{
583.   		int ret;

crypto/x509/x509_vfy.c:581:14: Loop condition is true. Entering loop body
579.   
580.   	/* Check all untrusted certificates */
581.   	for (i = 0; i < ctx->last_untrusted; i++)
                    ^
582.   		{
583.   		int ret;

crypto/x509/x509_vfy.c:584:7: Condition is true
582.   		{
583.   		int ret;
584.   		x = sk_X509_value(ctx->chain, i);
             ^
585.   		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
586.   			&& (x->ex_flags & EXFLAG_CRITICAL))

crypto/x509/x509_vfy.c:584:3: 
582.   		{
583.   		int ret;
584. > 		x = sk_X509_value(ctx->chain, i);
585.   		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
586.   			&& (x->ex_flags & EXFLAG_CRITICAL))

crypto/stack/stack.c:300:1: start of procedure sk_value()
  298.   }
  299.   
  300. > void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;

crypto/stack/stack.c:302:6: Taking false branch
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
              ^
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:302:13: Taking false branch
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                     ^
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:302:24: Taking true branch
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                                ^
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:302:39: 
  300.   void *sk_value(const _STACK *st, int i)
  301.   {
  302. > 	if(!st || (i < 0) || (i >= st->num)) return NULL;
  303.   	return st->data[i];
  304.   }

crypto/stack/stack.c:304:1: return from a call to sk_value
  302.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  303.   	return st->data[i];
  304. > }
  305.   
  306.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_vfy.c:585:9: Taking true branch
583.   		int ret;
584.   		x = sk_X509_value(ctx->chain, i);
585.   		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
               ^
586.   			&& (x->ex_flags & EXFLAG_CRITICAL))
587.   			{

crypto/x509/x509_vfy.c:586:8: 
584.   		x = sk_X509_value(ctx->chain, i);
585.   		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
586. > 			&& (x->ex_flags & EXFLAG_CRITICAL))
587.   			{
588.   			ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;

static int check_chain_extensions(X509_STORE_CTX *ctx)
{
#ifdef OPENSSL_NO_CHAIN_VERIFY
	return 1;
#else
	int i, ok=0, must_be_ca, plen = 0;
	X509 *x;
	int (*cb)(int xok,X509_STORE_CTX *xctx);
	int proxy_path_length = 0;
	int purpose;
	int allow_proxy_certs;
	cb=ctx->verify_cb;
	must_be_ca = -1;
	if (ctx->parent)
		{
		allow_proxy_certs = 0;
		purpose = X509_PURPOSE_CRL_SIGN;
		}
	else
		{
		allow_proxy_certs =
			!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
		if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
			allow_proxy_certs = 1;
		purpose = ctx->param->purpose;
		}
	for (i = 0; i < ctx->last_untrusted; i++)
		{
		int ret;
		x = sk_X509_value(ctx->chain, i);
		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
			&& (x->ex_flags & EXFLAG_CRITICAL))
			{
			ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
			ctx->error_depth = i;
			ctx->current_cert = x;
			ok=cb(0,ctx);
			if (!ok) goto end;
			}
		if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))
			{
			ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
			ctx->error_depth = i;
			ctx->current_cert = x;
			ok=cb(0,ctx);
			if (!ok) goto end;
			}
		ret = X509_check_ca(x);
		switch(must_be_ca)
			{
		case -1:
			if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
				&& (ret != 1) && (ret != 0))
				{
				ret = 0;
				ctx->error = X509_V_ERR_INVALID_CA;
				}
			else
				ret = 1;
			break;
		case 0:
			if (ret != 0)
				{
				ret = 0;
				ctx->error = X509_V_ERR_INVALID_NON_CA;
				}
			else
				ret = 1;
			break;
		default:
			if ((ret == 0)
				|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
					&& (ret != 1)))
				{
				ret = 0;
				ctx->error = X509_V_ERR_INVALID_CA;
				}
			else
				ret = 1;
			break;
			}
		if (ret == 0)
			{
			ctx->error_depth = i;
			ctx->current_cert = x;
			ok=cb(0,ctx);
			if (!ok) goto end;
			}
		if (ctx->param->purpose > 0)
			{
			ret = X509_check_purpose(x, purpose, must_be_ca > 0);
			if ((ret == 0)
				|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
					&& (ret != 1)))
				{
				ctx->error = X509_V_ERR_INVALID_PURPOSE;
				ctx->error_depth = i;
				ctx->current_cert = x;
				ok=cb(0,ctx);
				if (!ok) goto end;
				}
			}
		if ((i > 1) && !(x->ex_flags & EXFLAG_SI)
			   && (x->ex_pathlen != -1)
			   && (plen > (x->ex_pathlen + proxy_path_length + 1)))
			{
			ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
			ctx->error_depth = i;
			ctx->current_cert = x;
			ok=cb(0,ctx);
			if (!ok) goto end;
			}
		if (!(x->ex_flags & EXFLAG_SI))
			plen++;
		if (x->ex_flags & EXFLAG_PROXY)
			{
			if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen)
				{
				ctx->error =
					X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
				ctx->error_depth = i;
				ctx->current_cert = x;
				ok=cb(0,ctx);
				if (!ok) goto end;
				}
			proxy_path_length++;
			must_be_ca = 0;
			}
		else
			must_be_ca = 1;
		}
	ok = 1;
 end:
	return ok;
#endif
}
['static int check_chain_extensions(X509_STORE_CTX *ctx)\n{\n#ifdef OPENSSL_NO_CHAIN_VERIFY\n\treturn 1;\n#else\n\tint i, ok=0, must_be_ca, plen = 0;\n\tX509 *x;\n\tint (*cb)(int xok,X509_STORE_CTX *xctx);\n\tint proxy_path_length = 0;\n\tint purpose;\n\tint allow_proxy_certs;\n\tcb=ctx->verify_cb;\n\tmust_be_ca = -1;\n\tif (ctx->parent)\n\t\t{\n\t\tallow_proxy_certs = 0;\n\t\tpurpose = X509_PURPOSE_CRL_SIGN;\n\t\t}\n\telse\n\t\t{\n\t\tallow_proxy_certs =\n\t\t\t!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);\n\t\tif (getenv("OPENSSL_ALLOW_PROXY_CERTS"))\n\t\t\tallow_proxy_certs = 1;\n\t\tpurpose = ctx->param->purpose;\n\t\t}\n\tfor (i = 0; i < ctx->last_untrusted; i++)\n\t\t{\n\t\tint ret;\n\t\tx = sk_X509_value(ctx->chain, i);\n\t\tif (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)\n\t\t\t&& (x->ex_flags & EXFLAG_CRITICAL))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tret = X509_check_ca(x);\n\t\tswitch(must_be_ca)\n\t\t\t{\n\t\tcase -1:\n\t\t\tif ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t&& (ret != 1) && (ret != 0))\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\tcase 0:\n\t\t\tif (ret != 0)\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_NON_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tif ((ret == 0)\n\t\t\t\t|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t\t&& (ret != 1)))\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\t\t}\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (ctx->param->purpose > 0)\n\t\t\t{\n\t\t\tret = X509_check_purpose(x, purpose, must_be_ca > 0);\n\t\t\tif ((ret == 0)\n\t\t\t\t|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t\t&& (ret != 1)))\n\t\t\t\t{\n\t\t\t\tctx->error = X509_V_ERR_INVALID_PURPOSE;\n\t\t\t\tctx->error_depth = i;\n\t\t\t\tctx->current_cert = x;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif ((i > 1) && !(x->ex_flags & EXFLAG_SI)\n\t\t\t   && (x->ex_pathlen != -1)\n\t\t\t   && (plen > (x->ex_pathlen + proxy_path_length + 1)))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (!(x->ex_flags & EXFLAG_SI))\n\t\t\tplen++;\n\t\tif (x->ex_flags & EXFLAG_PROXY)\n\t\t\t{\n\t\t\tif (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen)\n\t\t\t\t{\n\t\t\t\tctx->error =\n\t\t\t\t\tX509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;\n\t\t\t\tctx->error_depth = i;\n\t\t\t\tctx->current_cert = x;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tproxy_path_length++;\n\t\t\tmust_be_ca = 0;\n\t\t\t}\n\t\telse\n\t\t\tmust_be_ca = 1;\n\t\t}\n\tok = 1;\n end:\n\treturn ok;\n#endif\n}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}']