crypto/x509/x509_vfy.c:384: error: NULL_DEREFERENCE
  pointer `x` last assigned on line 383 could be null and is dereferenced by call to `X509_check_purpose()` at line 384, column 8.
Showing all 14 steps of the trace


crypto/x509/x509_vfy.c:370:1: start of procedure check_chain_purpose()
368.    */
369.   
370. > static int check_chain_purpose(X509_STORE_CTX *ctx)
371.   {
372.   #ifdef OPENSSL_NO_CHAIN_VERIFY

crypto/x509/x509_vfy.c:375:2: 
373.   	return 1;
374.   #else
375. > 	int i, ok=0;
376.   	X509 *x;
377.   	int (*cb)();

crypto/x509/x509_vfy.c:378:2: 
376.   	X509 *x;
377.   	int (*cb)();
378. > 	cb=ctx->verify_cb;
379.   	if (cb == NULL) cb=null_callback;
380.   	/* Check all untrusted certificates */

crypto/x509/x509_vfy.c:379:6: Taking false branch
377.   	int (*cb)();
378.   	cb=ctx->verify_cb;
379.   	if (cb == NULL) cb=null_callback;
            ^
380.   	/* Check all untrusted certificates */
381.   	for (i = 0; i < ctx->last_untrusted; i++)

crypto/x509/x509_vfy.c:381:7: 
379.   	if (cb == NULL) cb=null_callback;
380.   	/* Check all untrusted certificates */
381. > 	for (i = 0; i < ctx->last_untrusted; i++)
382.   		{
383.   		x = sk_X509_value(ctx->chain, i);

crypto/x509/x509_vfy.c:381:14: Loop condition is true. Entering loop body
379.   	if (cb == NULL) cb=null_callback;
380.   	/* Check all untrusted certificates */
381.   	for (i = 0; i < ctx->last_untrusted; i++)
                    ^
382.   		{
383.   		x = sk_X509_value(ctx->chain, i);

crypto/x509/x509_vfy.c:383:3: 
381.   	for (i = 0; i < ctx->last_untrusted; i++)
382.   		{
383. > 		x = sk_X509_value(ctx->chain, i);
384.   		if (!X509_check_purpose(x, ctx->purpose, i))
385.   			{

crypto/stack/stack.c:305:1: start of procedure sk_value()
  303.   }
  304.   
  305. > char *sk_value(const STACK *st, int i)
  306.   {
  307.   	if(st == NULL) return NULL;

crypto/stack/stack.c:307:5: Taking true branch
  305.   char *sk_value(const STACK *st, int i)
  306.   {
  307.   	if(st == NULL) return NULL;
             ^
  308.   	return st->data[i];
  309.   }

crypto/stack/stack.c:307:17: 
  305.   char *sk_value(const STACK *st, int i)
  306.   {
  307. > 	if(st == NULL) return NULL;
  308.   	return st->data[i];
  309.   }

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

crypto/x509/x509_vfy.c:384:8: 
382.   		{
383.   		x = sk_X509_value(ctx->chain, i);
384. > 		if (!X509_check_purpose(x, ctx->purpose, i))
385.   			{
386.   			if (i)

crypto/x509v3/v3_purp.c:108:1: start of procedure X509_check_purpose()
  106.    * I really can't because it does recalculate hashes and do other non-const
  107.    * things. */
  108. > int X509_check_purpose(X509 *x, int id, int ca)
  109.   {
  110.   	int idx;

crypto/x509v3/v3_purp.c:112:7: 
  110.   	int idx;
  111.   	const X509_PURPOSE *pt;
  112. > 	if(!(x->ex_flags & EXFLAG_SET)) {
  113.   		CRYPTO_w_lock(CRYPTO_LOCK_X509);
  114.   		x509v3_cache_extensions(x);

static int check_chain_purpose(X509_STORE_CTX *ctx)
{
#ifdef OPENSSL_NO_CHAIN_VERIFY
	return 1;
#else
	int i, ok=0;
	X509 *x;
	int (*cb)();
	cb=ctx->verify_cb;
	if (cb == NULL) cb=null_callback;
	for (i = 0; i < ctx->last_untrusted; i++)
		{
		x = sk_X509_value(ctx->chain, i);
		if (!X509_check_purpose(x, ctx->purpose, i))
			{
			if (i)
				ctx->error = X509_V_ERR_INVALID_CA;
			else
				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;
			}
		}
	ok = 1;
 end:
	return ok;
#endif
}
['static int check_chain_purpose(X509_STORE_CTX *ctx)\n{\n#ifdef OPENSSL_NO_CHAIN_VERIFY\n\treturn 1;\n#else\n\tint i, ok=0;\n\tX509 *x;\n\tint (*cb)();\n\tcb=ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tfor (i = 0; i < ctx->last_untrusted; i++)\n\t\t{\n\t\tx = sk_X509_value(ctx->chain, i);\n\t\tif (!X509_check_purpose(x, ctx->purpose, i))\n\t\t\t{\n\t\t\tif (i)\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\telse\n\t\t\t\tctx->error = X509_V_ERR_INVALID_PURPOSE;\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 ((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\t}\n\tok = 1;\n end:\n\treturn ok;\n#endif\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}', 'int X509_check_purpose(X509 *x, int id, int ca)\n{\n\tint idx;\n\tconst X509_PURPOSE *pt;\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\tif(id == -1) return 1;\n\tidx = X509_PURPOSE_get_by_id(id);\n\tif(idx == -1) return -1;\n\tpt = X509_PURPOSE_get0(idx);\n\treturn pt->check_purpose(pt, x, ca);\n}']