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


crypto/x509/x509_vfy.c:1770:1: start of procedure internal_verify()
1768.   	}
1769.   
1770. > static int internal_verify(X509_STORE_CTX *ctx)
1771.   	{
1772.   	int ok=0,n;

crypto/x509/x509_vfy.c:1772:2: 
1770.   static int internal_verify(X509_STORE_CTX *ctx)
1771.   	{
1772. > 	int ok=0,n;
1773.   	X509 *xs,*xi;
1774.   	EVP_PKEY *pkey=NULL;

crypto/x509/x509_vfy.c:1774:2: 
1772.   	int ok=0,n;
1773.   	X509 *xs,*xi;
1774. > 	EVP_PKEY *pkey=NULL;
1775.   	int (*cb)(int xok,X509_STORE_CTX *xctx);
1776.   

crypto/x509/x509_vfy.c:1777:2: 
1775.   	int (*cb)(int xok,X509_STORE_CTX *xctx);
1776.   
1777. > 	cb=ctx->verify_cb;
1778.   
1779.   	n=sk_X509_num(ctx->chain);

crypto/x509/x509_vfy.c:1779:4: Condition is true
1777.   	cb=ctx->verify_cb;
1778.   
1779.   	n=sk_X509_num(ctx->chain);
           ^
1780.   	ctx->error_depth=n-1;
1781.   	n--;

crypto/x509/x509_vfy.c:1779:2: 
1777.   	cb=ctx->verify_cb;
1778.   
1779. > 	n=sk_X509_num(ctx->chain);
1780.   	ctx->error_depth=n-1;
1781.   	n--;

crypto/stack/stack.c:331:1: start of procedure sk_num()
  329.   	}
  330.   
  331. > int sk_num(const _STACK *st)
  332.   {
  333.   	if(st == NULL) return -1;

crypto/stack/stack.c:333:5: Taking false branch
  331.   int sk_num(const _STACK *st)
  332.   {
  333.   	if(st == NULL) return -1;
             ^
  334.   	return st->num;
  335.   }

crypto/stack/stack.c:334:2: 
  332.   {
  333.   	if(st == NULL) return -1;
  334. > 	return st->num;
  335.   }
  336.   

crypto/stack/stack.c:335:1: return from a call to sk_num
  333.   	if(st == NULL) return -1;
  334.   	return st->num;
  335. > }
  336.   
  337.   void *sk_value(const _STACK *st, int i)

crypto/x509/x509_vfy.c:1780:2: 
1778.   
1779.   	n=sk_X509_num(ctx->chain);
1780. > 	ctx->error_depth=n-1;
1781.   	n--;
1782.   	xi=sk_X509_value(ctx->chain,n);

crypto/x509/x509_vfy.c:1781:2: 
1779.   	n=sk_X509_num(ctx->chain);
1780.   	ctx->error_depth=n-1;
1781. > 	n--;
1782.   	xi=sk_X509_value(ctx->chain,n);
1783.   

crypto/x509/x509_vfy.c:1782:5: Condition is true
1780.   	ctx->error_depth=n-1;
1781.   	n--;
1782.   	xi=sk_X509_value(ctx->chain,n);
            ^
1783.   
1784.   	if (ctx->check_issued(ctx, xi, xi))

crypto/x509/x509_vfy.c:1782:2: 
1780.   	ctx->error_depth=n-1;
1781.   	n--;
1782. > 	xi=sk_X509_value(ctx->chain,n);
1783.   
1784.   	if (ctx->check_issued(ctx, xi, xi))

crypto/stack/stack.c:337:1: start of procedure sk_value()
  335.   }
  336.   
  337. > void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;

crypto/stack/stack.c:339:6: Taking false branch
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
              ^
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:339:13: Taking false branch
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                     ^
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:339:24: Taking false branch
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                                ^
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:340:2: 
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  340. > 	return st->data[i];
  341.   }
  342.   

crypto/stack/stack.c:341:1: return from a call to sk_value
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  340.   	return st->data[i];
  341. > }
  342.   
  343.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_vfy.c:1784:6: Taking false branch
1782.   	xi=sk_X509_value(ctx->chain,n);
1783.   
1784.   	if (ctx->check_issued(ctx, xi, xi))
             ^
1785.   		xs=xi;
1786.   	else

crypto/x509/x509_vfy.c:1788:7: Taking false branch
1786.   	else
1787.   		{
1788.   		if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)
              ^
1789.   			{
1790.   			xs = xi;

crypto/x509/x509_vfy.c:1793:7: Taking false branch
1791.   			goto check_cert;
1792.   			}
1793.   		if (n <= 0)
              ^
1794.   			{
1795.   			ctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;

crypto/x509/x509_vfy.c:1802:4: 
1800.   		else
1801.   			{
1802. > 			n--;
1803.   			ctx->error_depth=n;
1804.   			xs=sk_X509_value(ctx->chain,n);

crypto/x509/x509_vfy.c:1803:4: 
1801.   			{
1802.   			n--;
1803. > 			ctx->error_depth=n;
1804.   			xs=sk_X509_value(ctx->chain,n);
1805.   			}

crypto/x509/x509_vfy.c:1804:7: Condition is true
1802.   			n--;
1803.   			ctx->error_depth=n;
1804.   			xs=sk_X509_value(ctx->chain,n);
              ^
1805.   			}
1806.   		}

crypto/x509/x509_vfy.c:1804:4: 
1802.   			n--;
1803.   			ctx->error_depth=n;
1804. > 			xs=sk_X509_value(ctx->chain,n);
1805.   			}
1806.   		}

crypto/stack/stack.c:337:1: start of procedure sk_value()
  335.   }
  336.   
  337. > void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;

crypto/stack/stack.c:339:6: Taking false branch
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
              ^
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:339:13: Taking false branch
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                     ^
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:339:24: Taking true branch
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
                                ^
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:339:39: 
  337.   void *sk_value(const _STACK *st, int i)
  338.   {
  339. > 	if(!st || (i < 0) || (i >= st->num)) return NULL;
  340.   	return st->data[i];
  341.   }

crypto/stack/stack.c:341:1: return from a call to sk_value
  339.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  340.   	return st->data[i];
  341. > }
  342.   
  343.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509/x509_vfy.c:1809:9: Loop condition is true. Entering loop body
1807.   
1808.   /*	ctx->error=0;  not needed */
1809.   	while (n >= 0)
                ^
1810.   		{
1811.   		ctx->error_depth=n;

crypto/x509/x509_vfy.c:1811:3: 
1809.   	while (n >= 0)
1810.   		{
1811. > 		ctx->error_depth=n;
1812.   
1813.   		/* Skip signature check for self signed certificates unless

crypto/x509/x509_vfy.c:1817:8: Taking false branch
1815.   		 * just wastes time.
1816.   		 */
1817.   		if (!xs->valid && (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)))
               ^
1818.   			{
1819.   			if ((pkey=X509_get_pubkey(xi)) == NULL)

static int internal_verify(X509_STORE_CTX *ctx)
	{
	int ok=0,n;
	X509 *xs,*xi;
	EVP_PKEY *pkey=NULL;
	int (*cb)(int xok,X509_STORE_CTX *xctx);
	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->check_issued(ctx, xi, xi))
		xs=xi;
	else
		{
		if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)
			{
			xs = xi;
			goto check_cert;
			}
		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 && (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)))
			{
			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;
				}
			else 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;
			}
		xs->valid = 1;
		check_cert:
		ok = x509_check_cert_time(ctx, xs, 0);
		if (!ok)
			goto end;
		ctx->current_issuer=xi;
		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 ok=0,n;\n\tX509 *xs,*xi;\n\tEVP_PKEY *pkey=NULL;\n\tint (*cb)(int xok,X509_STORE_CTX *xctx);\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->check_issued(ctx, xi, xi))\n\t\txs=xi;\n\telse\n\t\t{\n\t\tif (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN)\n\t\t\t{\n\t\t\txs = xi;\n\t\t\tgoto check_cert;\n\t\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 && (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)))\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\telse if (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\t}\n\t\txs->valid = 1;\n\t\tcheck_cert:\n\t\tok = x509_check_cert_time(ctx, xs, 0);\n\t\tif (!ok)\n\t\t\tgoto end;\n\t\tctx->current_issuer=xi;\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}', '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}']