crypto/x509/x509_vfy.c:165: error: NULL_DEREFERENCE
  pointer `sktmp` last assigned on line 103 could be null and is dereferenced by call to `sk_delete_ptr()` at line 165, column 5.
Showing all 63 steps of the trace


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

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

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

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

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

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

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

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

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

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

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

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

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

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

crypto/stack/stack.c:308:1: start of procedure sk_value()
  306.   }
  307.   
  308. > char *sk_value(const STACK *st, int i)
  309.   {
  310.   	if(!st || (i < 0) || (i >= st->num)) return NULL;

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

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

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

crypto/stack/stack.c:311:2: 
  309.   {
  310.   	if(!st || (i < 0) || (i >= st->num)) return NULL;
  311. > 	return st->data[i];
  312.   }
  313.   

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

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

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

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

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

crypto/x509/x509_cmp.c:119:1: start of procedure X509_get_issuer_name()
  117.   	}
  118.   
  119. > X509_NAME *X509_get_issuer_name(X509 *a)
  120.   	{
  121.   	return(a->cert_info->issuer);

crypto/x509/x509_cmp.c:121:2: 
  119.   X509_NAME *X509_get_issuer_name(X509 *a)
  120.   	{
  121. > 	return(a->cert_info->issuer);
  122.   	}
  123.   

crypto/x509/x509_cmp.c:122:2: return from a call to X509_get_issuer_name
  120.   	{
  121.   	return(a->cert_info->issuer);
  122.   	}
          ^
  123.   
  124.   unsigned long X509_issuer_name_hash(X509 *x)

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

crypto/x509/x509_vfy.c:154:7: Taking true branch
152.   
153.   		/* If we were passed a cert chain, use it first */
154.   		if (ctx->untrusted != NULL)
             ^
155.   			{
156.   			xtmp=find_issuer(ctx, sktmp,x);

crypto/x509/x509_vfy.c:156:4: Skipping find_issuer(): empty list of specs
154.   		if (ctx->untrusted != NULL)
155.   			{
156.   			xtmp=find_issuer(ctx, sktmp,x);
          ^
157.   			if (xtmp != NULL)
158.   				{

crypto/x509/x509_vfy.c:157:8: Taking true branch
155.   			{
156.   			xtmp=find_issuer(ctx, sktmp,x);
157.   			if (xtmp != NULL)
              ^
158.   				{
159.   				if (!sk_X509_push(ctx->chain,xtmp))

crypto/x509/x509_vfy.c:159:10: 
157.   			if (xtmp != NULL)
158.   				{
159. > 				if (!sk_X509_push(ctx->chain,xtmp))
160.   					{
161.   					X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);

crypto/stack/stack.c:252:1: start of procedure sk_push()
  250.   	}
  251.   
  252. > int sk_push(STACK *st, char *data)
  253.   	{
  254.   	return(sk_insert(st,data,st->num));

crypto/stack/stack.c:254:2: Skipping sk_insert(): empty list of specs
  252.   int sk_push(STACK *st, char *data)
  253.   	{
  254.   	return(sk_insert(st,data,st->num));
          ^
  255.   	}
  256.   

crypto/stack/stack.c:255:2: return from a call to sk_push
  253.   	{
  254.   	return(sk_insert(st,data,st->num));
  255.   	}
          ^
  256.   
  257.   int sk_unshift(STACK *st, char *data)

crypto/x509/x509_vfy.c:159:10: Taking false branch
157.   			if (xtmp != NULL)
158.   				{
159.   				if (!sk_X509_push(ctx->chain,xtmp))
                ^
160.   					{
161.   					X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);

crypto/x509/x509_vfy.c:164:5: 
162.   					goto end;
163.   					}
164. > 				CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
165.   				sk_X509_delete_ptr(sktmp,xtmp);
166.   				ctx->last_untrusted++;

crypto/cryptlib.c:495:1: start of procedure CRYPTO_add_lock()
  493.   	}
  494.   
  495. > int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
  496.   	     int line)
  497.   	{

crypto/cryptlib.c:498:2: 
  496.   	     int line)
  497.   	{
  498. > 	int ret = 0;
  499.   
  500.   	if (add_lock_callback != NULL)

crypto/cryptlib.c:500:6: Taking false branch
  498.   	int ret = 0;
  499.   
  500.   	if (add_lock_callback != NULL)
              ^
  501.   		{
  502.   #ifdef LOCK_DEBUG

crypto/cryptlib.c:517:3: 
  515.   	else
  516.   		{
  517. > 		CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
  518.   
  519.   		ret= *pointer+amount;

crypto/cryptlib.c:451:1: start of procedure CRYPTO_lock()
    449.   	}
    450.   
    451. > void CRYPTO_lock(int mode, int type, const char *file, int line)
    452.   	{
    453.   #ifdef LOCK_DEBUG

crypto/cryptlib.c:476:6: Taking false branch
    474.   		}
    475.   #endif
    476.   	if (type < 0)
                ^
    477.   		{
    478.   		if (dynlock_lock_callback != NULL)

crypto/cryptlib.c:491:7: Taking false branch
    489.   		}
    490.   	else
    491.   		if (locking_callback != NULL)
                 ^
    492.   			locking_callback(mode,type,file,line);
    493.   	}

crypto/cryptlib.c:476:2: 
    474.   		}
    475.   #endif
    476. > 	if (type < 0)
    477.   		{
    478.   		if (dynlock_lock_callback != NULL)

crypto/cryptlib.c:493:2: return from a call to CRYPTO_lock
    491.   		if (locking_callback != NULL)
    492.   			locking_callback(mode,type,file,line);
    493.   	}
            ^
    494.   
    495.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/cryptlib.c:519:3: 
  517.   		CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);
  518.   
  519. > 		ret= *pointer+amount;
  520.   #ifdef LOCK_DEBUG
  521.   		fprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\n",

crypto/cryptlib.c:527:3: 
  525.   			file,line);
  526.   #endif
  527. > 		*pointer=ret;
  528.   		CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
  529.   		}

crypto/cryptlib.c:528:3: 
  526.   #endif
  527.   		*pointer=ret;
  528. > 		CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
  529.   		}
  530.   	return(ret);

crypto/cryptlib.c:451:1: start of procedure CRYPTO_lock()
    449.   	}
    450.   
    451. > void CRYPTO_lock(int mode, int type, const char *file, int line)
    452.   	{
    453.   #ifdef LOCK_DEBUG

crypto/cryptlib.c:476:6: Taking false branch
    474.   		}
    475.   #endif
    476.   	if (type < 0)
                ^
    477.   		{
    478.   		if (dynlock_lock_callback != NULL)

crypto/cryptlib.c:491:7: Taking false branch
    489.   		}
    490.   	else
    491.   		if (locking_callback != NULL)
                 ^
    492.   			locking_callback(mode,type,file,line);
    493.   	}

crypto/cryptlib.c:476:2: 
    474.   		}
    475.   #endif
    476. > 	if (type < 0)
    477.   		{
    478.   		if (dynlock_lock_callback != NULL)

crypto/cryptlib.c:493:2: return from a call to CRYPTO_lock
    491.   		if (locking_callback != NULL)
    492.   			locking_callback(mode,type,file,line);
    493.   	}
            ^
    494.   
    495.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/cryptlib.c:530:2: 
  528.   		CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);
  529.   		}
  530. > 	return(ret);
  531.   	}
  532.   

crypto/cryptlib.c:531:2: return from a call to CRYPTO_add_lock
  529.   		}
  530.   	return(ret);
  531.   	}
          ^
  532.   
  533.   const char *CRYPTO_get_lock_name(int type)

crypto/x509/x509_vfy.c:165:5: 
163.   					}
164.   				CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
165. > 				sk_X509_delete_ptr(sktmp,xtmp);
166.   				ctx->last_untrusted++;
167.   				x=xtmp;

crypto/stack/stack.c:180:1: start of procedure sk_delete_ptr()
  178.   	}
  179.   
  180. > char *sk_delete_ptr(STACK *st, char *p)
  181.   	{
  182.   	int i;

crypto/stack/stack.c:184:7: 
  182.   	int i;
  183.   
  184. > 	for (i=0; i<st->num; i++)
  185.   		if (st->data[i] == p)
  186.   			return(sk_delete(st,i));

crypto/stack/stack.c:184:12: Loop condition is true. Entering loop body
  182.   	int i;
  183.   
  184.   	for (i=0; i<st->num; i++)
                    ^
  185.   		if (st->data[i] == p)
  186.   			return(sk_delete(st,i));

crypto/stack/stack.c:185:7: Taking false branch
  183.   
  184.   	for (i=0; i<st->num; i++)
  185.   		if (st->data[i] == p)
               ^
  186.   			return(sk_delete(st,i));
  187.   	return(NULL);

crypto/stack/stack.c:184:23: 
  182.   	int i;
  183.   
  184. > 	for (i=0; i<st->num; i++)
  185.   		if (st->data[i] == p)
  186.   			return(sk_delete(st,i));

crypto/stack/stack.c:184:12: 
  182.   	int i;
  183.   
  184. > 	for (i=0; i<st->num; i++)
  185.   		if (st->data[i] == p)
  186.   			return(sk_delete(st,i));

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}', '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 || (i < 0) || (i >= st->num)) 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}', 'int sk_push(STACK *st, char *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n\t     int line)\n\t{\n\tint ret = 0;\n\tif (add_lock_callback != NULL)\n\t\t{\n#ifdef LOCK_DEBUG\n\t\tint before= *pointer;\n#endif\n\t\tret=add_lock_callback(pointer,amount,type,file,line);\n#ifdef LOCK_DEBUG\n\t\tfprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(),\n\t\t\tbefore,amount,ret,\n\t\t\tCRYPTO_get_lock_name(type),\n\t\t\tfile,line);\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tCRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);\n\t\tret= *pointer+amount;\n#ifdef LOCK_DEBUG\n\t\tfprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(),\n\t\t\t*pointer,amount,ret,\n\t\t\tCRYPTO_get_lock_name(type),\n\t\t\tfile,line);\n#endif\n\t\t*pointer=ret;\n\t\tCRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);\n\t\t}\n\treturn(ret);\n\t}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock  ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tif (dynlock_lock_callback != NULL)\n\t\t\t{\n\t\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t\t= CRYPTO_get_dynlock_value(type);\n\t\t\tOPENSSL_assert(pointer != NULL);\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\tCRYPTO_destroy_dynlockid(type);\n\t\t\t}\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'char *sk_delete_ptr(STACK *st, char *p)\n\t{\n\tint i;\n\tfor (i=0; i<st->num; i++)\n\t\tif (st->data[i] == p)\n\t\t\treturn(sk_delete(st,i));\n\treturn(NULL);\n\t}']