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


crypto/x509/x509_vfy.c:99:1: start of procedure X509_verify_cert()
97.   #endif
98.   
99. > int X509_verify_cert(X509_STORE_CTX *ctx)
100.   	{
101.   	X509 *x,*xtmp,*chain_ss=NULL;

crypto/x509/x509_vfy.c:101:2: 
99.   int X509_verify_cert(X509_STORE_CTX *ctx)
100.   	{
101. > 	X509 *x,*xtmp,*chain_ss=NULL;
102.   	X509_NAME *xn;
103.   	int depth,i,ok=0;

crypto/x509/x509_vfy.c:103:2: 
101.   	X509 *x,*xtmp,*chain_ss=NULL;
102.   	X509_NAME *xn;
103. > 	int depth,i,ok=0;
104.   	int num;
105.   	int (*cb)();

crypto/x509/x509_vfy.c:106:2: 
104.   	int num;
105.   	int (*cb)();
106. > 	STACK_OF(X509) *sktmp=NULL;
107.   
108.   	if (ctx->cert == NULL)

crypto/x509/x509_vfy.c:108:6: Taking false branch
106.   	STACK_OF(X509) *sktmp=NULL;
107.   
108.   	if (ctx->cert == NULL)
            ^
109.   		{
110.   		X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);

crypto/x509/x509_vfy.c:114:2: 
112.   		}
113.   
114. > 	cb=ctx->verify_cb;
115.   
116.   	/* first we make sure the chain we are going to build is

crypto/x509/x509_vfy.c:118:6: Taking false branch
116.   	/* first we make sure the chain we are going to build is
117.   	 * present and that the first entry is in place */
118.   	if (ctx->chain == NULL)
            ^
119.   		{
120.   		if (	((ctx->chain=sk_X509_new_null()) == NULL) ||

crypto/x509/x509_vfy.c:131:6: Taking true branch
129.   
130.   	/* We use a temporary STACK so we can chop and hack at it */
131.   	if (ctx->untrusted != NULL
            ^
132.   	    && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
133.   		{

crypto/x509/x509_vfy.c:132:9: 
130.   	/* We use a temporary STACK so we can chop and hack at it */
131.   	if (ctx->untrusted != NULL
132. > 	    && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
133.   		{
134.   		X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);

crypto/stack/stack.c:91:1: start of procedure sk_dup()
  89.   	}
  90.   
  91. > STACK *sk_dup(STACK *sk)
  92.   	{
  93.   	STACK *ret;

crypto/stack/stack.c:96:6: Taking false branch
  94.   	char **s;
  95.   
  96.   	if ((ret=sk_new(sk->comp)) == NULL) goto err;
             ^
  97.   	s=(char **)OPENSSL_realloc((char *)ret->data,
  98.   		(unsigned int)sizeof(char *)*sk->num_alloc);

crypto/stack/stack.c:97:2: 
  95.   
  96.   	if ((ret=sk_new(sk->comp)) == NULL) goto err;
  97. > 	s=(char **)OPENSSL_realloc((char *)ret->data,
  98.   		(unsigned int)sizeof(char *)*sk->num_alloc);
  99.   	if (s == NULL) goto err;

crypto/mem.c:302:1: start of procedure CRYPTO_realloc()
    300.   	}
    301.   
    302. > void *CRYPTO_realloc(void *str, int num, const char *file, int line)
    303.   	{
    304.   	void *ret = NULL;

crypto/mem.c:304:2: 
    302.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)
    303.   	{
    304. > 	void *ret = NULL;
    305.   
    306.   	if (realloc_debug_func != NULL)

crypto/mem.c:306:6: Taking true branch
    304.   	void *ret = NULL;
    305.   
    306.   	if (realloc_debug_func != NULL)
                ^
    307.   		realloc_debug_func(str, NULL, num, file, line, 0);
    308.   	ret = realloc_ex_func(str,num,file,line);

crypto/mem.c:307:3: Skipping __function_pointer__(): unresolved function pointer
    305.   
    306.   	if (realloc_debug_func != NULL)
    307.   		realloc_debug_func(str, NULL, num, file, line, 0);
             ^
    308.   	ret = realloc_ex_func(str,num,file,line);
    309.   #ifdef LEVITTE_DEBUG_MEM

crypto/mem.c:308:2: Skipping __function_pointer__(): unresolved function pointer
    306.   	if (realloc_debug_func != NULL)
    307.   		realloc_debug_func(str, NULL, num, file, line, 0);
    308.   	ret = realloc_ex_func(str,num,file,line);
            ^
    309.   #ifdef LEVITTE_DEBUG_MEM
    310.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         | 0x%p -> 0x%p (%d)\n", str, ret, num);

crypto/mem.c:312:6: Taking true branch
    310.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         | 0x%p -> 0x%p (%d)\n", str, ret, num);
    311.   #endif
    312.   	if (realloc_debug_func != NULL)
                ^
    313.   		realloc_debug_func(str, ret, num, file, line, 1);
    314.   

crypto/mem.c:313:3: Skipping __function_pointer__(): unresolved function pointer
    311.   #endif
    312.   	if (realloc_debug_func != NULL)
    313.   		realloc_debug_func(str, ret, num, file, line, 1);
             ^
    314.   
    315.   	return ret;

crypto/mem.c:315:2: 
    313.   		realloc_debug_func(str, ret, num, file, line, 1);
    314.   
    315. > 	return ret;
    316.   	}
    317.   

crypto/mem.c:316:2: return from a call to CRYPTO_realloc
    314.   
    315.   	return ret;
    316.   	}
            ^
    317.   
    318.   void CRYPTO_free(void *str)

crypto/stack/stack.c:99:6: Taking false branch
  97.   	s=(char **)OPENSSL_realloc((char *)ret->data,
  98.   		(unsigned int)sizeof(char *)*sk->num_alloc);
  99.   	if (s == NULL) goto err;
              ^
  100.   	ret->data=s;
  101.   

crypto/stack/stack.c:100:2: 
  98.   		(unsigned int)sizeof(char *)*sk->num_alloc);
  99.   	if (s == NULL) goto err;
  100. > 	ret->data=s;
  101.   
  102.   	ret->num=sk->num;

crypto/stack/stack.c:102:2: 
  100.   	ret->data=s;
  101.   
  102. > 	ret->num=sk->num;
  103.   	memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
  104.   	ret->sorted=sk->sorted;

crypto/stack/stack.c:103:2: 
  101.   
  102.   	ret->num=sk->num;
  103. > 	memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
  104.   	ret->sorted=sk->sorted;
  105.   	ret->num_alloc=sk->num_alloc;

crypto/stack/stack.c:104:2: 
  102.   	ret->num=sk->num;
  103.   	memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
  104. > 	ret->sorted=sk->sorted;
  105.   	ret->num_alloc=sk->num_alloc;
  106.   	ret->comp=sk->comp;

crypto/stack/stack.c:105:2: 
  103.   	memcpy(ret->data,sk->data,sizeof(char *)*sk->num);
  104.   	ret->sorted=sk->sorted;
  105. > 	ret->num_alloc=sk->num_alloc;
  106.   	ret->comp=sk->comp;
  107.   	return(ret);

crypto/stack/stack.c:106:2: 
  104.   	ret->sorted=sk->sorted;
  105.   	ret->num_alloc=sk->num_alloc;
  106. > 	ret->comp=sk->comp;
  107.   	return(ret);
  108.   err:

crypto/stack/stack.c:107:2: 
  105.   	ret->num_alloc=sk->num_alloc;
  106.   	ret->comp=sk->comp;
  107. > 	return(ret);
  108.   err:
  109.   	if(ret)

crypto/stack/stack.c:112:2: return from a call to sk_dup
  110.   		sk_free(ret);
  111.   	return(NULL);
  112.   	}
          ^
  113.   
  114.   STACK *sk_new_null(void)

crypto/x509/x509_vfy.c:132:9: Taking false branch
130.   	/* We use a temporary STACK so we can chop and hack at it */
131.   	if (ctx->untrusted != NULL
132.   	    && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
               ^
133.   		{
134.   		X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);

crypto/x509/x509_vfy.c:138:2: 
136.   		}
137.   
138. > 	num=sk_X509_num(ctx->chain);
139.   	x=sk_X509_value(ctx->chain,num-1);
140.   	depth=ctx->depth;

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:139:2: 
137.   
138.   	num=sk_X509_num(ctx->chain);
139. > 	x=sk_X509_value(ctx->chain,num-1);
140.   	depth=ctx->depth;
141.   

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:140:2: 
138.   	num=sk_X509_num(ctx->chain);
139.   	x=sk_X509_value(ctx->chain,num-1);
140. > 	depth=ctx->depth;
141.   
142.   

crypto/x509/x509_vfy.c:178:3: Loop condition is true. Entering loop body
176.   			}
177.   		break;
178.   		}
         ^
179.   
180.   	/* at this point, chain should contain a list of untrusted

crypto/x509/x509_vfy.c:146:7: Taking false branch
144.   		{
145.   		/* If we have enough, we break */
146.   		if (depth < num) break; /* FIXME: If this happens, we should take
             ^
147.   		                         * note of it and, if appropriate, use the
148.   		                         * X509_V_ERR_CERT_CHAIN_TOO_LONG error

crypto/x509/x509_vfy.c:153:3: 
151.   
152.   		/* If we are self signed, we break */
153. > 		xn=X509_get_issuer_name(x);
154.   		if (ctx->check_issued(ctx, x,x)) break;
155.   

crypto/x509/x509_cmp.c:115:1: start of procedure X509_get_issuer_name()
  113.   	}
  114.   
  115. > X509_NAME *X509_get_issuer_name(X509 *a)
  116.   	{
  117.   	return(a->cert_info->issuer);

crypto/x509/x509_cmp.c:117:2: 
  115.   X509_NAME *X509_get_issuer_name(X509 *a)
  116.   	{
  117. > 	return(a->cert_info->issuer);
  118.   	}
  119.   

crypto/x509/x509_cmp.c:118:2: return from a call to X509_get_issuer_name
  116.   	{
  117.   	return(a->cert_info->issuer);
  118.   	}
          ^
  119.   
  120.   unsigned long X509_issuer_name_hash(X509 *x)

crypto/x509/x509_vfy.c:154:7: Taking true branch
152.   		/* If we are self signed, we break */
153.   		xn=X509_get_issuer_name(x);
154.   		if (ctx->check_issued(ctx, x,x)) break;
             ^
155.   
156.   		/* If we were passed a cert chain, use it first */

crypto/x509/x509_vfy.c:188:2: 
186.    	 */
187.   
188. > 	i=sk_X509_num(ctx->chain);
189.   	x=sk_X509_value(ctx->chain,i-1);
190.   	xn = X509_get_subject_name(x);

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 true branch
  301.   int sk_num(const STACK *st)
  302.   {
  303.   	if(st == NULL) return -1;
             ^
  304.   	return st->num;
  305.   }

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

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:189:2: 
187.   
188.   	i=sk_X509_num(ctx->chain);
189. > 	x=sk_X509_value(ctx->chain,i-1);
190.   	xn = X509_get_subject_name(x);
191.   	if (ctx->check_issued(ctx, x, x))

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:190:2: 
188.   	i=sk_X509_num(ctx->chain);
189.   	x=sk_X509_value(ctx->chain,i-1);
190. > 	xn = X509_get_subject_name(x);
191.   	if (ctx->check_issued(ctx, x, x))
192.   		{

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

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

int X509_verify_cert(X509_STORE_CTX *ctx)
	{
	X509 *x,*xtmp,*chain_ss=NULL;
	X509_NAME *xn;
	int depth,i,ok=0;
	int num;
	int (*cb)();
	STACK_OF(X509) *sktmp=NULL;
	if (ctx->cert == NULL)
		{
		X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
		return -1;
		}
	cb=ctx->verify_cb;
	if (ctx->chain == NULL)
		{
		if (	((ctx->chain=sk_X509_new_null()) == NULL) ||
			(!sk_X509_push(ctx->chain,ctx->cert)))
			{
			X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
			goto end;
			}
		CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
		ctx->last_untrusted=1;
		}
	if (ctx->untrusted != NULL
	    && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
		{
		X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
		goto end;
		}
	num=sk_X509_num(ctx->chain);
	x=sk_X509_value(ctx->chain,num-1);
	depth=ctx->depth;
	for (;;)
		{
		if (depth < num) break;
		xn=X509_get_issuer_name(x);
		if (ctx->check_issued(ctx, x,x)) break;
		if (ctx->untrusted != NULL)
			{
			xtmp=find_issuer(ctx, sktmp,x);
			if (xtmp != NULL)
				{
				if (!sk_X509_push(ctx->chain,xtmp))
					{
					X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
					goto end;
					}
				CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
				sk_X509_delete_ptr(sktmp,xtmp);
				ctx->last_untrusted++;
				x=xtmp;
				num++;
				continue;
				}
			}
		break;
		}
	i=sk_X509_num(ctx->chain);
	x=sk_X509_value(ctx->chain,i-1);
	xn = X509_get_subject_name(x);
	if (ctx->check_issued(ctx, x, x))
		{
		if (sk_X509_num(ctx->chain) == 1)
			{
			ok = ctx->get_issuer(&xtmp, ctx, x);
			if ((ok <= 0) || X509_cmp(x, xtmp))
				{
				ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
				ctx->current_cert=x;
				ctx->error_depth=i-1;
				if (ok == 1) X509_free(xtmp);
				ok=cb(0,ctx);
				if (!ok) goto end;
				}
			else
				{
				X509_free(x);
				x = xtmp;
				sk_X509_set(ctx->chain, i - 1, x);
				ctx->last_untrusted=0;
				}
			}
		else
			{
			chain_ss=sk_X509_pop(ctx->chain);
			ctx->last_untrusted--;
			num--;
			x=sk_X509_value(ctx->chain,num-1);
			}
		}
	for (;;)
		{
		if (depth < num) break;
		xn=X509_get_issuer_name(x);
		if (ctx->check_issued(ctx,x,x)) break;
		ok = ctx->get_issuer(&xtmp, ctx, x);
		if (ok < 0) return ok;
		if (ok == 0) break;
		x = xtmp;
		if (!sk_X509_push(ctx->chain,x))
			{
			X509_free(xtmp);
			X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
			return 0;
			}
		num++;
		}
	xn=X509_get_issuer_name(x);
	if (!ctx->check_issued(ctx,x,x))
		{
		if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss))
			{
			if (ctx->last_untrusted >= num)
				ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
			else
				ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
			ctx->current_cert=x;
			}
		else
			{
			sk_X509_push(ctx->chain,chain_ss);
			num++;
			ctx->last_untrusted=num;
			ctx->current_cert=chain_ss;
			ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
			chain_ss=NULL;
			}
		ctx->error_depth=num-1;
		ok=cb(0,ctx);
		if (!ok) goto end;
		}
	if (ctx->purpose > 0) ok = check_chain_purpose(ctx);
	if (!ok) goto end;
	if (ctx->trust > 0) ok = check_trust(ctx);
	if (!ok) goto end;
	X509_get_pubkey_parameters(NULL,ctx->chain);
	ok = ctx->check_revocation(ctx);
	if(!ok) goto end;
	if (ctx->verify != NULL)
		ok=ctx->verify(ctx);
	else
		ok=internal_verify(ctx);
	if (0)
		{
end:
		X509_get_pubkey_parameters(NULL,ctx->chain);
		}
	if (sktmp != NULL) sk_X509_free(sktmp);
	if (chain_ss != NULL) X509_free(chain_ss);
	return ok;
	}
['int X509_verify_cert(X509_STORE_CTX *ctx)\n\t{\n\tX509 *x,*xtmp,*chain_ss=NULL;\n\tX509_NAME *xn;\n\tint depth,i,ok=0;\n\tint num;\n\tint (*cb)();\n\tSTACK_OF(X509) *sktmp=NULL;\n\tif (ctx->cert == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);\n\t\treturn -1;\n\t\t}\n\tcb=ctx->verify_cb;\n\tif (ctx->chain == NULL)\n\t\t{\n\t\tif (\t((ctx->chain=sk_X509_new_null()) == NULL) ||\n\t\t\t(!sk_X509_push(ctx->chain,ctx->cert)))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto end;\n\t\t\t}\n\t\tCRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);\n\t\tctx->last_untrusted=1;\n\t\t}\n\tif (ctx->untrusted != NULL\n\t    && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\tgoto end;\n\t\t}\n\tnum=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,num-1);\n\tdepth=ctx->depth;\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (ctx->check_issued(ctx, x,x)) break;\n\t\tif (ctx->untrusted != NULL)\n\t\t\t{\n\t\t\txtmp=find_issuer(ctx, sktmp,x);\n\t\t\tif (xtmp != NULL)\n\t\t\t\t{\n\t\t\t\tif (!sk_X509_push(ctx->chain,xtmp))\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tCRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);\n\t\t\t\tsk_X509_delete_ptr(sktmp,xtmp);\n\t\t\t\tctx->last_untrusted++;\n\t\t\t\tx=xtmp;\n\t\t\t\tnum++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\tbreak;\n\t\t}\n\ti=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,i-1);\n\txn = X509_get_subject_name(x);\n\tif (ctx->check_issued(ctx, x, x))\n\t\t{\n\t\tif (sk_X509_num(ctx->chain) == 1)\n\t\t\t{\n\t\t\tok = ctx->get_issuer(&xtmp, ctx, x);\n\t\t\tif ((ok <= 0) || X509_cmp(x, xtmp))\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;\n\t\t\t\tctx->current_cert=x;\n\t\t\t\tctx->error_depth=i-1;\n\t\t\t\tif (ok == 1) X509_free(xtmp);\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\n\t\t\t\t{\n\t\t\t\tX509_free(x);\n\t\t\t\tx = xtmp;\n\t\t\t\tsk_X509_set(ctx->chain, i - 1, x);\n\t\t\t\tctx->last_untrusted=0;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tchain_ss=sk_X509_pop(ctx->chain);\n\t\t\tctx->last_untrusted--;\n\t\t\tnum--;\n\t\t\tx=sk_X509_value(ctx->chain,num-1);\n\t\t\t}\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (ctx->check_issued(ctx,x,x)) break;\n\t\tok = ctx->get_issuer(&xtmp, ctx, x);\n\t\tif (ok < 0) return ok;\n\t\tif (ok == 0) break;\n\t\tx = xtmp;\n\t\tif (!sk_X509_push(ctx->chain,x))\n\t\t\t{\n\t\t\tX509_free(xtmp);\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t\t}\n\t\tnum++;\n\t\t}\n\txn=X509_get_issuer_name(x);\n\tif (!ctx->check_issued(ctx,x,x))\n\t\t{\n\t\tif ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss))\n\t\t\t{\n\t\t\tif (ctx->last_untrusted >= num)\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;\n\t\t\telse\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsk_X509_push(ctx->chain,chain_ss);\n\t\t\tnum++;\n\t\t\tctx->last_untrusted=num;\n\t\t\tctx->current_cert=chain_ss;\n\t\t\tctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;\n\t\t\tchain_ss=NULL;\n\t\t\t}\n\t\tctx->error_depth=num-1;\n\t\tok=cb(0,ctx);\n\t\tif (!ok) goto end;\n\t\t}\n\tif (ctx->purpose > 0) ok = check_chain_purpose(ctx);\n\tif (!ok) goto end;\n\tif (ctx->trust > 0) ok = check_trust(ctx);\n\tif (!ok) goto end;\n\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\tok = ctx->check_revocation(ctx);\n\tif(!ok) goto end;\n\tif (ctx->verify != NULL)\n\t\tok=ctx->verify(ctx);\n\telse\n\t\tok=internal_verify(ctx);\n\tif (0)\n\t\t{\nend:\n\t\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\t\t}\n\tif (sktmp != NULL) sk_X509_free(sktmp);\n\tif (chain_ss != NULL) X509_free(chain_ss);\n\treturn ok;\n\t}', 'STACK *sk_dup(STACK *sk)\n\t{\n\tSTACK *ret;\n\tchar **s;\n\tif ((ret=sk_new(sk->comp)) == NULL) goto err;\n\ts=(char **)OPENSSL_realloc((char *)ret->data,\n\t\t(unsigned int)sizeof(char *)*sk->num_alloc);\n\tif (s == NULL) goto err;\n\tret->data=s;\n\tret->num=sk->num;\n\tmemcpy(ret->data,sk->data,sizeof(char *)*sk->num);\n\tret->sorted=sk->sorted;\n\tret->num_alloc=sk->num_alloc;\n\tret->comp=sk->comp;\n\treturn(ret);\nerr:\n\tif(ret)\n\t\tsk_free(ret);\n\treturn(NULL);\n\t}', 'void *CRYPTO_realloc(void *str, int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (realloc_debug_func != NULL)\n\t\trealloc_debug_func(str, NULL, num, file, line, 0);\n\tret = realloc_ex_func(str,num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         | 0x%p -> 0x%p (%d)\\n", str, ret, num);\n#endif\n\tif (realloc_debug_func != NULL)\n\t\trealloc_debug_func(str, ret, num, file, line, 1);\n\treturn ret;\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}', 'X509_NAME *X509_get_issuer_name(X509 *a)\n\t{\n\treturn(a->cert_info->issuer);\n\t}', 'X509_NAME *X509_get_subject_name(X509 *a)\n\t{\n\treturn(a->cert_info->subject);\n\t}']