crypto/x509/x509_vfy.c:417: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 407 could be null and is dereferenced by call to `X509_check_ca()` at line 417, column 9.
Showing all 17 steps of the trace


crypto/x509/x509_vfy.c:384:1: start of procedure check_chain_extensions()
382.    */
383.   
384. > static int check_chain_extensions(X509_STORE_CTX *ctx)
385.   {
386.   #ifdef OPENSSL_NO_CHAIN_VERIFY

crypto/x509/x509_vfy.c:389:2: 
387.   	return 1;
388.   #else
389. > 	int i, ok=0, must_be_ca;
390.   	X509 *x;
391.   	int (*cb)();

crypto/x509/x509_vfy.c:392:2: 
390.   	X509 *x;
391.   	int (*cb)();
392. > 	cb=ctx->verify_cb;
393.   
394.   	/* must_be_ca can have 1 of 3 values:

crypto/x509/x509_vfy.c:402:2: 
400.   	       all certificates in the chain except the leaf certificate.
401.   	*/
402. > 	must_be_ca = -1;
403.   	/* Check all untrusted certificates */
404.   	for (i = 0; i < ctx->last_untrusted; i++)

crypto/x509/x509_vfy.c:404:7: 
402.   	must_be_ca = -1;
403.   	/* Check all untrusted certificates */
404. > 	for (i = 0; i < ctx->last_untrusted; i++)
405.   		{
406.   		int ret;

crypto/x509/x509_vfy.c:404:14: Loop condition is true. Entering loop body
402.   	must_be_ca = -1;
403.   	/* Check all untrusted certificates */
404.   	for (i = 0; i < ctx->last_untrusted; i++)
                    ^
405.   		{
406.   		int ret;

crypto/x509/x509_vfy.c:407:3: 
405.   		{
406.   		int ret;
407. > 		x = sk_X509_value(ctx->chain, i);
408.   		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
409.   			&& (x->ex_flags & EXFLAG_CRITICAL))

crypto/stack/stack.c:307:1: start of procedure sk_value()
  305.   }
  306.   
  307. > char *sk_value(const STACK *st, int i)
  308.   {
  309.   	if(!st || (i < 0) || (i >= st->num)) return NULL;

crypto/stack/stack.c:309:6: Taking false branch
  307.   char *sk_value(const STACK *st, int i)
  308.   {
  309.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
              ^
  310.   	return st->data[i];
  311.   }

crypto/stack/stack.c:309:13: Taking false branch
  307.   char *sk_value(const STACK *st, int i)
  308.   {
  309.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                     ^
  310.   	return st->data[i];
  311.   }

crypto/stack/stack.c:309:24: Taking true branch
  307.   char *sk_value(const STACK *st, int i)
  308.   {
  309.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                                ^
  310.   	return st->data[i];
  311.   }

crypto/stack/stack.c:309:39: 
  307.   char *sk_value(const STACK *st, int i)
  308.   {
  309. > 	if(!st || (i < 0) || (i >= st->num)) return NULL;
  310.   	return st->data[i];
  311.   }

crypto/stack/stack.c:311:1: return from a call to sk_value
  309.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  310.   	return st->data[i];
  311. > }
  312.   
  313.   char *sk_set(STACK *st, int i, char *value)

crypto/x509/x509_vfy.c:408:9: Taking false branch
406.   		int ret;
407.   		x = sk_X509_value(ctx->chain, i);
408.   		if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
               ^
409.   			&& (x->ex_flags & EXFLAG_CRITICAL))
410.   			{

crypto/x509/x509_vfy.c:417:3: 
415.   			if (!ok) goto end;
416.   			}
417. > 		ret = X509_check_ca(x);
418.   		switch(must_be_ca)
419.   			{

crypto/x509v3/v3_purp.c:451:1: start of procedure X509_check_ca()
  449.   }
  450.   
  451. > int X509_check_ca(X509 *x)
  452.   {
  453.   	if(!(x->ex_flags & EXFLAG_SET)) {

crypto/x509v3/v3_purp.c:453:7: 
  451.   int X509_check_ca(X509 *x)
  452.   {
  453. > 	if(!(x->ex_flags & EXFLAG_SET)) {
  454.   		CRYPTO_w_lock(CRYPTO_LOCK_X509);
  455.   		x509v3_cache_extensions(x);

static int check_chain_extensions(X509_STORE_CTX *ctx)
{
#ifdef OPENSSL_NO_CHAIN_VERIFY
	return 1;
#else
	int i, ok=0, must_be_ca;
	X509 *x;
	int (*cb)();
	cb=ctx->verify_cb;
	must_be_ca = -1;
	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;
			}
		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, ctx->param->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_pathlen != -1)
			   && (i > (x->ex_pathlen + 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;
			}
		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;\n\tX509 *x;\n\tint (*cb)();\n\tcb=ctx->verify_cb;\n\tmust_be_ca = -1;\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\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, ctx->param->purpose,\n\t\t\t\tmust_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_pathlen != -1)\n\t\t\t   && (i > (x->ex_pathlen + 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\tmust_be_ca = 1;\n\t\t}\n\tok = 1;\n end:\n\treturn ok;\n#endif\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}', 'int X509_check_ca(X509 *x)\n{\n\tif(!(x->ex_flags & EXFLAG_SET)) {\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_X509);\n\t\tx509v3_cache_extensions(x);\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_X509);\n\t}\n\treturn check_ca(x);\n}']