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


crypto/x509/x509_vfy.c:329:1: start of procedure check_chain_purpose()
327.    */
328.   
329. > static int check_chain_purpose(X509_STORE_CTX *ctx)
330.   {
331.   #ifdef NO_CHAIN_VERIFY

crypto/x509/x509_vfy.c:334:2: 
332.   	return 1;
333.   #else
334. > 	int i, ok=0;
335.   	X509 *x;
336.   	int (*cb)();

crypto/x509/x509_vfy.c:337:2: 
335.   	X509 *x;
336.   	int (*cb)();
337. > 	cb=ctx->ctx->verify_cb;
338.   	if (cb == NULL) cb=null_callback;
339.   	/* Check all untrusted certificates */

crypto/x509/x509_vfy.c:338:6: Taking false branch
336.   	int (*cb)();
337.   	cb=ctx->ctx->verify_cb;
338.   	if (cb == NULL) cb=null_callback;
            ^
339.   	/* Check all untrusted certificates */
340.   	for(i = 0; i < ctx->last_untrusted; i++) {

crypto/x509/x509_vfy.c:340:6: 
338.   	if (cb == NULL) cb=null_callback;
339.   	/* Check all untrusted certificates */
340. > 	for(i = 0; i < ctx->last_untrusted; i++) {
341.   		x = sk_X509_value(ctx->chain, i);
342.   		if(!X509_check_purpose(x, ctx->purpose, i)) {

crypto/x509/x509_vfy.c:340:13: Loop condition is true. Entering loop body
338.   	if (cb == NULL) cb=null_callback;
339.   	/* Check all untrusted certificates */
340.   	for(i = 0; i < ctx->last_untrusted; i++) {
                   ^
341.   		x = sk_X509_value(ctx->chain, i);
342.   		if(!X509_check_purpose(x, ctx->purpose, i)) {

crypto/x509/x509_vfy.c:341:3: 
339.   	/* Check all untrusted certificates */
340.   	for(i = 0; i < ctx->last_untrusted; i++) {
341. > 		x = sk_X509_value(ctx->chain, i);
342.   		if(!X509_check_purpose(x, ctx->purpose, i)) {
343.   			if(i) ctx->error = X509_V_ERR_INVALID_CA;

crypto/x509/x509_vfy.c:786:1: start of procedure sk_X509_value()
  784.   
  785.   
  786. > IMPLEMENT_STACK_OF(X509)
  787.   IMPLEMENT_ASN1_SET_OF(X509)
  788.   

crypto/stack/stack.c:289:1: start of procedure sk_value()
    287.   }
    288.   
    289. > char *sk_value(STACK *st, int i)
    290.   {
    291.   	if(st == NULL) return NULL;

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

crypto/stack/stack.c:291:17: 
    289.   char *sk_value(STACK *st, int i)
    290.   {
    291. > 	if(st == NULL) return NULL;
    292.   	return st->data[i];
    293.   }

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

crypto/x509/x509_vfy.c:786:1: return from a call to sk_X509_value
  784.   
  785.   
  786. > IMPLEMENT_STACK_OF(X509)
  787.   IMPLEMENT_ASN1_SET_OF(X509)
  788.   

crypto/x509/x509_vfy.c:342:7: 
340.   	for(i = 0; i < ctx->last_untrusted; i++) {
341.   		x = sk_X509_value(ctx->chain, i);
342. > 		if(!X509_check_purpose(x, ctx->purpose, i)) {
343.   			if(i) ctx->error = X509_V_ERR_INVALID_CA;
344.   			else ctx->error = X509_V_ERR_INVALID_PURPOSE;

crypto/x509v3/v3_purp.c:98:1: start of procedure X509_check_purpose()
  96.   }
  97.   
  98. > int X509_check_purpose(X509 *x, int id, int ca)
  99.   {
  100.   	int idx;

crypto/x509v3/v3_purp.c:102:7: 
  100.   	int idx;
  101.   	X509_PURPOSE *pt;
  102. > 	if(!(x->ex_flags & EXFLAG_SET)) {
  103.   		CRYPTO_w_lock(CRYPTO_LOCK_X509);
  104.   		x509v3_cache_extensions(x);

static int check_chain_purpose(X509_STORE_CTX *ctx)
{
#ifdef NO_CHAIN_VERIFY
	return 1;
#else
	int i, ok=0;
	X509 *x;
	int (*cb)();
	cb=ctx->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 NO_CHAIN_VERIFY\n\treturn 1;\n#else\n\tint i, ok=0;\n\tX509 *x;\n\tint (*cb)();\n\tcb=ctx->ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tfor(i = 0; i < ctx->last_untrusted; i++) {\n\t\tx = sk_X509_value(ctx->chain, i);\n\t\tif(!X509_check_purpose(x, ctx->purpose, i)) {\n\t\t\tif(i) ctx->error = X509_V_ERR_INVALID_CA;\n\t\t\telse ctx->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}\n\t\tif((i > 1) && (x->ex_pathlen != -1)\n\t\t\t\t\t&& (i > (x->ex_pathlen + 1))) {\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}\n\t}\n\tok = 1;\n\tend:\n\treturn(ok);\n#endif\n}', 'IMPLEMENT_STACK_OF(X509)', 'char *sk_value(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\tX509_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_iget(idx);\n\treturn pt->check_purpose(pt, x, ca);\n}']