crypto/x509/x509_vfy.c:668: error: NULL_DEREFERENCE
  pointer `xs` last assigned on line 660 could be null and is dereferenced at line 668, column 8.
Showing all 30 steps of the trace


crypto/x509/x509_vfy.c:627:1: start of procedure internal_verify()
625.   	}
626.   
627. > static int internal_verify(X509_STORE_CTX *ctx)
628.   	{
629.   	int i,ok=0,n;

crypto/x509/x509_vfy.c:629:2: 
627.   static int internal_verify(X509_STORE_CTX *ctx)
628.   	{
629. > 	int i,ok=0,n;
630.   	X509 *xs,*xi;
631.   	EVP_PKEY *pkey=NULL;

crypto/x509/x509_vfy.c:631:2: 
629.   	int i,ok=0,n;
630.   	X509 *xs,*xi;
631. > 	EVP_PKEY *pkey=NULL;
632.   	time_t *ptime;
633.   	int (*cb)();

crypto/x509/x509_vfy.c:635:2: 
633.   	int (*cb)();
634.   
635. > 	cb=ctx->verify_cb;
636.   
637.   	n=sk_X509_num(ctx->chain);

crypto/x509/x509_vfy.c:637:2: 
635.   	cb=ctx->verify_cb;
636.   
637. > 	n=sk_X509_num(ctx->chain);
638.   	ctx->error_depth=n-1;
639.   	n--;

crypto/stack/stack.c:301:1: start of procedure sk_num()
  299.   	}
  300.   
  301. > int sk_num(const STACK *st)
  302.   {
  303.   	if(st == NULL) return -1;

crypto/stack/stack.c:303:5: Taking false branch
  301.   int sk_num(const STACK *st)
  302.   {
  303.   	if(st == NULL) return -1;
             ^
  304.   	return st->num;
  305.   }

crypto/stack/stack.c:304:2: 
  302.   {
  303.   	if(st == NULL) return -1;
  304. > 	return st->num;
  305.   }
  306.   

crypto/stack/stack.c:305:1: return from a call to sk_num
  303.   	if(st == NULL) return -1;
  304.   	return st->num;
  305. > }
  306.   
  307.   char *sk_value(const STACK *st, int i)

crypto/x509/x509_vfy.c:638:2: 
636.   
637.   	n=sk_X509_num(ctx->chain);
638. > 	ctx->error_depth=n-1;
639.   	n--;
640.   	xi=sk_X509_value(ctx->chain,n);

crypto/x509/x509_vfy.c:639:2: 
637.   	n=sk_X509_num(ctx->chain);
638.   	ctx->error_depth=n-1;
639. > 	n--;
640.   	xi=sk_X509_value(ctx->chain,n);
641.   	if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)

crypto/x509/x509_vfy.c:640:2: 
638.   	ctx->error_depth=n-1;
639.   	n--;
640. > 	xi=sk_X509_value(ctx->chain,n);
641.   	if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
642.   		ptime = &ctx->check_time;

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 == NULL) return NULL;

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

crypto/stack/stack.c:310:2: 
  308.   {
  309.   	if(st == NULL) return NULL;
  310. > 	return st->data[i];
  311.   }
  312.   

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

crypto/x509/x509_vfy.c:641:6: Taking false branch
639.   	n--;
640.   	xi=sk_X509_value(ctx->chain,n);
641.   	if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
            ^
642.   		ptime = &ctx->check_time;
643.   	else

crypto/x509/x509_vfy.c:644:3: 
642.   		ptime = &ctx->check_time;
643.   	else
644. > 		ptime = NULL;
645.   	if (ctx->check_issued(ctx, xi, xi))
646.   		xs=xi;

crypto/x509/x509_vfy.c:645:6: Taking false branch
643.   	else
644.   		ptime = NULL;
645.   	if (ctx->check_issued(ctx, xi, xi))
            ^
646.   		xs=xi;
647.   	else

crypto/x509/x509_vfy.c:649:7: Taking false branch
647.   	else
648.   		{
649.   		if (n <= 0)
             ^
650.   			{
651.   			ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;

crypto/x509/x509_vfy.c:658:4: 
656.   		else
657.   			{
658. > 			n--;
659.   			ctx->error_depth=n;
660.   			xs=sk_X509_value(ctx->chain,n);

crypto/x509/x509_vfy.c:659:4: 
657.   			{
658.   			n--;
659. > 			ctx->error_depth=n;
660.   			xs=sk_X509_value(ctx->chain,n);
661.   			}

crypto/x509/x509_vfy.c:660:4: 
658.   			n--;
659.   			ctx->error_depth=n;
660. > 			xs=sk_X509_value(ctx->chain,n);
661.   			}
662.   		}

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 == NULL) return NULL;

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

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

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

crypto/x509/x509_vfy.c:665:9: Loop condition is true. Entering loop body
663.   
664.   /*	ctx->error=0;  not needed */
665.   	while (n >= 0)
               ^
666.   		{
667.   		ctx->error_depth=n;

crypto/x509/x509_vfy.c:667:3: 
665.   	while (n >= 0)
666.   		{
667. > 		ctx->error_depth=n;
668.   		if (!xs->valid)
669.   			{

crypto/x509/x509_vfy.c:668:8: Taking false branch
666.   		{
667.   		ctx->error_depth=n;
668.   		if (!xs->valid)
              ^
669.   			{
670.   			if ((pkey=X509_get_pubkey(xi)) == NULL)

static int internal_verify(X509_STORE_CTX *ctx)
	{
	int i,ok=0,n;
	X509 *xs,*xi;
	EVP_PKEY *pkey=NULL;
	time_t *ptime;
	int (*cb)();
	cb=ctx->verify_cb;
	n=sk_X509_num(ctx->chain);
	ctx->error_depth=n-1;
	n--;
	xi=sk_X509_value(ctx->chain,n);
	if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
		ptime = &ctx->check_time;
	else
		ptime = NULL;
	if (ctx->check_issued(ctx, xi, xi))
		xs=xi;
	else
		{
		if (n <= 0)
			{
			ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
			ctx->current_cert=xi;
			ok=cb(0,ctx);
			goto end;
			}
		else
			{
			n--;
			ctx->error_depth=n;
			xs=sk_X509_value(ctx->chain,n);
			}
		}
	while (n >= 0)
		{
		ctx->error_depth=n;
		if (!xs->valid)
			{
			if ((pkey=X509_get_pubkey(xi)) == NULL)
				{
				ctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
				ctx->current_cert=xi;
				ok=(*cb)(0,ctx);
				if (!ok) goto end;
				}
			if (X509_verify(xs,pkey) <= 0)
				{
				ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
				ctx->current_cert=xs;
				ok=(*cb)(0,ctx);
				if (!ok)
					{
					EVP_PKEY_free(pkey);
					goto end;
					}
				}
			EVP_PKEY_free(pkey);
			pkey=NULL;
			i=X509_cmp_time(X509_get_notBefore(xs), ptime);
			if (i == 0)
				{
				ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
				ctx->current_cert=xs;
				ok=(*cb)(0,ctx);
				if (!ok) goto end;
				}
			if (i > 0)
				{
				ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
				ctx->current_cert=xs;
				ok=(*cb)(0,ctx);
				if (!ok) goto end;
				}
			xs->valid=1;
			}
		i=X509_cmp_time(X509_get_notAfter(xs), ptime);
		if (i == 0)
			{
			ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
			ctx->current_cert=xs;
			ok=(*cb)(0,ctx);
			if (!ok) goto end;
			}
		if (i < 0)
			{
			ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
			ctx->current_cert=xs;
			ok=(*cb)(0,ctx);
			if (!ok) goto end;
			}
		ctx->current_cert=xs;
		ok=(*cb)(1,ctx);
		if (!ok) goto end;
		n--;
		if (n >= 0)
			{
			xi=xs;
			xs=sk_X509_value(ctx->chain,n);
			}
		}
	ok=1;
end:
	return ok;
	}
['static int internal_verify(X509_STORE_CTX *ctx)\n\t{\n\tint i,ok=0,n;\n\tX509 *xs,*xi;\n\tEVP_PKEY *pkey=NULL;\n\ttime_t *ptime;\n\tint (*cb)();\n\tcb=ctx->verify_cb;\n\tn=sk_X509_num(ctx->chain);\n\tctx->error_depth=n-1;\n\tn--;\n\txi=sk_X509_value(ctx->chain,n);\n\tif (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)\n\t\tptime = &ctx->check_time;\n\telse\n\t\tptime = NULL;\n\tif (ctx->check_issued(ctx, xi, xi))\n\t\txs=xi;\n\telse\n\t\t{\n\t\tif (n <= 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;\n\t\t\tctx->current_cert=xi;\n\t\t\tok=cb(0,ctx);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tn--;\n\t\t\tctx->error_depth=n;\n\t\t\txs=sk_X509_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\twhile (n >= 0)\n\t\t{\n\t\tctx->error_depth=n;\n\t\tif (!xs->valid)\n\t\t\t{\n\t\t\tif ((pkey=X509_get_pubkey(xi)) == NULL)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;\n\t\t\t\tctx->current_cert=xi;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tif (X509_verify(xs,pkey) <= 0)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok)\n\t\t\t\t\t{\n\t\t\t\t\tEVP_PKEY_free(pkey);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\tpkey=NULL;\n\t\t\ti=X509_cmp_time(X509_get_notBefore(xs), ptime);\n\t\t\tif (i == 0)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tif (i > 0)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_CERT_NOT_YET_VALID;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\txs->valid=1;\n\t\t\t}\n\t\ti=X509_cmp_time(X509_get_notAfter(xs), ptime);\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;\n\t\t\tctx->current_cert=xs;\n\t\t\tok=(*cb)(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_CERT_HAS_EXPIRED;\n\t\t\tctx->current_cert=xs;\n\t\t\tok=(*cb)(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tctx->current_cert=xs;\n\t\tok=(*cb)(1,ctx);\n\t\tif (!ok) goto end;\n\t\tn--;\n\t\tif (n >= 0)\n\t\t\t{\n\t\t\txi=xs;\n\t\t\txs=sk_X509_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\tok=1;\nend:\n\treturn ok;\n\t}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}']