crypto/x509/x509_vfy.c:307: error: NULL_DEREFERENCE
  pointer `xi` last assigned on line 306 could be null and is dereferenced by call to `X509_get_subject_name()` at line 307, column 20.
Showing all 20 steps of the trace


crypto/x509/x509_vfy.c:293:1: start of procedure internal_verify()
291.   	}
292.   
293. > static int internal_verify(X509_STORE_CTX *ctx)
294.   	{
295.   	int i,ok=0,n;

crypto/x509/x509_vfy.c:295:2: 
293.   static int internal_verify(X509_STORE_CTX *ctx)
294.   	{
295. > 	int i,ok=0,n;
296.   	X509 *xs,*xi;
297.   	EVP_PKEY *pkey=NULL;

crypto/x509/x509_vfy.c:297:2: 
295.   	int i,ok=0,n;
296.   	X509 *xs,*xi;
297. > 	EVP_PKEY *pkey=NULL;
298.   	int (*cb)();
299.   

crypto/x509/x509_vfy.c:300:2: 
298.   	int (*cb)();
299.   
300. > 	cb=ctx->ctx->verify_cb;
301.   	if (cb == NULL) cb=null_callback;
302.   

crypto/x509/x509_vfy.c:301:6: Taking false branch
299.   
300.   	cb=ctx->ctx->verify_cb;
301.   	if (cb == NULL) cb=null_callback;
            ^
302.   
303.   	n=sk_num(ctx->chain);

crypto/x509/x509_vfy.c:303:2: 
301.   	if (cb == NULL) cb=null_callback;
302.   
303. > 	n=sk_num(ctx->chain);
304.   	ctx->error_depth=n-1;
305.   	n--;

crypto/stack/stack.c:287:1: start of procedure sk_num()
  285.   	}
  286.   
  287. > int sk_num(STACK *st)
  288.   {
  289.   	if(st == NULL) return -1;

crypto/stack/stack.c:289:5: Taking true branch
  287.   int sk_num(STACK *st)
  288.   {
  289.   	if(st == NULL) return -1;
             ^
  290.   	return st->num;
  291.   }

crypto/stack/stack.c:289:17: 
  287.   int sk_num(STACK *st)
  288.   {
  289. > 	if(st == NULL) return -1;
  290.   	return st->num;
  291.   }

crypto/stack/stack.c:291:1: return from a call to sk_num
  289.   	if(st == NULL) return -1;
  290.   	return st->num;
  291. > }
  292.   
  293.   char *sk_value(STACK *st, int i)

crypto/x509/x509_vfy.c:304:2: 
302.   
303.   	n=sk_num(ctx->chain);
304. > 	ctx->error_depth=n-1;
305.   	n--;
306.   	xi=(X509 *)sk_value(ctx->chain,n);

crypto/x509/x509_vfy.c:305:2: 
303.   	n=sk_num(ctx->chain);
304.   	ctx->error_depth=n-1;
305. > 	n--;
306.   	xi=(X509 *)sk_value(ctx->chain,n);
307.   	if (X509_NAME_cmp(X509_get_subject_name(xi),

crypto/x509/x509_vfy.c:306:2: 
304.   	ctx->error_depth=n-1;
305.   	n--;
306. > 	xi=(X509 *)sk_value(ctx->chain,n);
307.   	if (X509_NAME_cmp(X509_get_subject_name(xi),
308.   		X509_get_issuer_name(xi)) == 0)

crypto/stack/stack.c:293:1: start of procedure sk_value()
  291.   }
  292.   
  293. > char *sk_value(STACK *st, int i)
  294.   {
  295.   	if(st == NULL) return NULL;

crypto/stack/stack.c:295:5: Taking true branch
  293.   char *sk_value(STACK *st, int i)
  294.   {
  295.   	if(st == NULL) return NULL;
             ^
  296.   	return st->data[i];
  297.   }

crypto/stack/stack.c:295:17: 
  293.   char *sk_value(STACK *st, int i)
  294.   {
  295. > 	if(st == NULL) return NULL;
  296.   	return st->data[i];
  297.   }

crypto/stack/stack.c:297:1: return from a call to sk_value
  295.   	if(st == NULL) return NULL;
  296.   	return st->data[i];
  297. > }
  298.   
  299.   char *sk_set(STACK *st, int i, char *value)

crypto/x509/x509_vfy.c:307:6: 
305.   	n--;
306.   	xi=(X509 *)sk_value(ctx->chain,n);
307. > 	if (X509_NAME_cmp(X509_get_subject_name(xi),
308.   		X509_get_issuer_name(xi)) == 0)
309.   		xs=xi;

crypto/x509/x509_cmp.c:126:1: start of procedure X509_get_subject_name()
  124.   	}
  125.   
  126. > X509_NAME *X509_get_subject_name(X509 *a)
  127.   	{
  128.   	return(a->cert_info->subject);

crypto/x509/x509_cmp.c:128:2: 
  126.   X509_NAME *X509_get_subject_name(X509 *a)
  127.   	{
  128. > 	return(a->cert_info->subject);
  129.   	}
  130.   

static int internal_verify(X509_STORE_CTX *ctx)
	{
	int i,ok=0,n;
	X509 *xs,*xi;
	EVP_PKEY *pkey=NULL;
	int (*cb)();
	cb=ctx->ctx->verify_cb;
	if (cb == NULL) cb=null_callback;
	n=sk_num(ctx->chain);
	ctx->error_depth=n-1;
	n--;
	xi=(X509 *)sk_value(ctx->chain,n);
	if (X509_NAME_cmp(X509_get_subject_name(xi),
		X509_get_issuer_name(xi)) == 0)
		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=(X509 *)sk_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)
				{
				EVP_PKEY_free(pkey);
				ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
				ctx->current_cert=xs;
				ok=(*cb)(0,ctx);
				if (!ok) goto end;
				}
			EVP_PKEY_free(pkey);
			pkey=NULL;
			i=X509_cmp_current_time(X509_get_notBefore(xs));
			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_current_time(X509_get_notAfter(xs));
		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=(X509 *)sk_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\tint (*cb)();\n\tcb=ctx->ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tn=sk_num(ctx->chain);\n\tctx->error_depth=n-1;\n\tn--;\n\txi=(X509 *)sk_value(ctx->chain,n);\n\tif (X509_NAME_cmp(X509_get_subject_name(xi),\n\t\tX509_get_issuer_name(xi)) == 0)\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=(X509 *)sk_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\tEVP_PKEY_free(pkey);\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) goto end;\n\t\t\t\t}\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\tpkey=NULL;\n\t\t\ti=X509_cmp_current_time(X509_get_notBefore(xs));\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_current_time(X509_get_notAfter(xs));\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=(X509 *)sk_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\tok=1;\nend:\n\treturn(ok);\n\t}', 'int sk_num(STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'char *sk_value(STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}', 'X509_NAME *X509_get_subject_name(X509 *a)\n\t{\n\treturn(a->cert_info->subject);\n\t}']