crypto/x509v3/v3_purp.c:120: error: NULL_DEREFERENCE
  pointer `pt` last assigned on line 119 could be null and is dereferenced at line 120, column 9.
Showing all 39 steps of the trace


crypto/x509v3/v3_purp.c:107:1: start of procedure X509_check_purpose()
105.    * I really can't because it does recalculate hashes and do other non-const
106.    * things. */
107. > int X509_check_purpose(X509 *x, int id, int ca)
108.   {
109.   	int idx;

crypto/x509v3/v3_purp.c:111:7: Taking true branch
109.   	int idx;
110.   	const X509_PURPOSE *pt;
111.   	if(!(x->ex_flags & EXFLAG_SET)) {
             ^
112.   		CRYPTO_w_lock(CRYPTO_LOCK_X509);
113.   		x509v3_cache_extensions(x);

crypto/x509v3/v3_purp.c:112:3: 
110.   	const X509_PURPOSE *pt;
111.   	if(!(x->ex_flags & EXFLAG_SET)) {
112. > 		CRYPTO_w_lock(CRYPTO_LOCK_X509);
113.   		x509v3_cache_extensions(x);
114.   		CRYPTO_w_unlock(CRYPTO_LOCK_X509);

crypto/cryptlib.c:372:1: start of procedure CRYPTO_lock()
  370.   	}
  371.   
  372. > void CRYPTO_lock(int mode, int type, const char *file, int line)
  373.   	{
  374.   #ifdef LOCK_DEBUG

crypto/cryptlib.c:397:6: Taking false branch
  395.   		}
  396.   #endif
  397.   	if (type < 0)
              ^
  398.   		{
  399.   		int i = -type - 1;

crypto/cryptlib.c:411:7: Taking true branch
  409.   		}
  410.   	else
  411.   		if (locking_callback != NULL)
               ^
  412.   			locking_callback(mode,type,file,line);
  413.   	}

crypto/cryptlib.c:412:4: Skipping __function_pointer__(): unresolved function pointer
  410.   	else
  411.   		if (locking_callback != NULL)
  412.   			locking_callback(mode,type,file,line);
            ^
  413.   	}
  414.   

crypto/cryptlib.c:397:2: 
  395.   		}
  396.   #endif
  397. > 	if (type < 0)
  398.   		{
  399.   		int i = -type - 1;

crypto/cryptlib.c:413:2: return from a call to CRYPTO_lock
  411.   		if (locking_callback != NULL)
  412.   			locking_callback(mode,type,file,line);
  413.   	}
          ^
  414.   
  415.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/x509v3/v3_purp.c:113:3: 
111.   	if(!(x->ex_flags & EXFLAG_SET)) {
112.   		CRYPTO_w_lock(CRYPTO_LOCK_X509);
113. > 		x509v3_cache_extensions(x);
114.   		CRYPTO_w_unlock(CRYPTO_LOCK_X509);
115.   	}

crypto/x509v3/v3_purp.c:259:1: start of procedure x509v3_cache_extensions()
  257.   }
  258.   
  259. > static void x509v3_cache_extensions(X509 *x)
  260.   {
  261.   	BASIC_CONSTRAINTS *bs;

crypto/x509v3/v3_purp.c:267:5: Taking true branch
  265.   	
  266.   	int i;
  267.   	if(x->ex_flags & EXFLAG_SET) return;
             ^
  268.   #ifndef NO_SHA
  269.   	X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);

crypto/x509v3/v3_purp.c:267:31: 
  265.   	
  266.   	int i;
  267. > 	if(x->ex_flags & EXFLAG_SET) return;
  268.   #ifndef NO_SHA
  269.   	X509_digest(x, EVP_sha1(), x->sha1_hash, NULL);

crypto/x509v3/v3_purp.c:337:1: return from a call to x509v3_cache_extensions
  335.   	x->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);
  336.   	x->ex_flags |= EXFLAG_SET;
  337. > }
  338.   
  339.   /* CA checks common to all purposes

crypto/x509v3/v3_purp.c:114:3: 
112.   		CRYPTO_w_lock(CRYPTO_LOCK_X509);
113.   		x509v3_cache_extensions(x);
114. > 		CRYPTO_w_unlock(CRYPTO_LOCK_X509);
115.   	}
116.   	if(id == -1) return 1;

crypto/cryptlib.c:372:1: start of procedure CRYPTO_lock()
  370.   	}
  371.   
  372. > void CRYPTO_lock(int mode, int type, const char *file, int line)
  373.   	{
  374.   #ifdef LOCK_DEBUG

crypto/cryptlib.c:397:6: Taking false branch
  395.   		}
  396.   #endif
  397.   	if (type < 0)
              ^
  398.   		{
  399.   		int i = -type - 1;

crypto/cryptlib.c:411:7: Taking true branch
  409.   		}
  410.   	else
  411.   		if (locking_callback != NULL)
               ^
  412.   			locking_callback(mode,type,file,line);
  413.   	}

crypto/cryptlib.c:412:4: Skipping __function_pointer__(): unresolved function pointer
  410.   	else
  411.   		if (locking_callback != NULL)
  412.   			locking_callback(mode,type,file,line);
            ^
  413.   	}
  414.   

crypto/cryptlib.c:397:2: 
  395.   		}
  396.   #endif
  397. > 	if (type < 0)
  398.   		{
  399.   		int i = -type - 1;

crypto/cryptlib.c:413:2: return from a call to CRYPTO_lock
  411.   		if (locking_callback != NULL)
  412.   			locking_callback(mode,type,file,line);
  413.   	}
          ^
  414.   
  415.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/x509v3/v3_purp.c:116:5: Taking false branch
114.   		CRYPTO_w_unlock(CRYPTO_LOCK_X509);
115.   	}
116.   	if(id == -1) return 1;
           ^
117.   	idx = X509_PURPOSE_get_by_id(id);
118.   	if(idx == -1) return -1;

crypto/x509v3/v3_purp.c:117:2: 
115.   	}
116.   	if(id == -1) return 1;
117. > 	idx = X509_PURPOSE_get_by_id(id);
118.   	if(idx == -1) return -1;
119.   	pt = X509_PURPOSE_get0(idx);

crypto/x509v3/v3_purp.c:148:1: start of procedure X509_PURPOSE_get_by_id()
  146.   
  147.   
  148. > int X509_PURPOSE_get_by_id(int purpose)
  149.   {
  150.   	X509_PURPOSE tmp;

crypto/x509v3/v3_purp.c:152:6: Taking true branch
  150.   	X509_PURPOSE tmp;
  151.   	int idx;
  152.   	if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
              ^
  153.   		return purpose - X509_PURPOSE_MIN;
  154.   	tmp.purpose = purpose;

crypto/x509v3/v3_purp.c:152:39: Taking false branch
  150.   	X509_PURPOSE tmp;
  151.   	int idx;
  152.   	if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
                                               ^
  153.   		return purpose - X509_PURPOSE_MIN;
  154.   	tmp.purpose = purpose;

crypto/x509v3/v3_purp.c:154:2: 
  152.   	if((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
  153.   		return purpose - X509_PURPOSE_MIN;
  154. > 	tmp.purpose = purpose;
  155.   	if(!xptable) return -1;
  156.   	idx = sk_X509_PURPOSE_find(xptable, &tmp);

crypto/x509v3/v3_purp.c:155:6: Taking false branch
  153.   		return purpose - X509_PURPOSE_MIN;
  154.   	tmp.purpose = purpose;
  155.   	if(!xptable) return -1;
              ^
  156.   	idx = sk_X509_PURPOSE_find(xptable, &tmp);
  157.   	if(idx == -1) return -1;

crypto/x509v3/v3_purp.c:156:2: Skipping sk_find(): empty list of specs
  154.   	tmp.purpose = purpose;
  155.   	if(!xptable) return -1;
  156.   	idx = sk_X509_PURPOSE_find(xptable, &tmp);
          ^
  157.   	if(idx == -1) return -1;
  158.   	return idx + X509_PURPOSE_COUNT;

crypto/x509v3/v3_purp.c:157:5: Taking false branch
  155.   	if(!xptable) return -1;
  156.   	idx = sk_X509_PURPOSE_find(xptable, &tmp);
  157.   	if(idx == -1) return -1;
             ^
  158.   	return idx + X509_PURPOSE_COUNT;
  159.   }

crypto/x509v3/v3_purp.c:158:2: 
  156.   	idx = sk_X509_PURPOSE_find(xptable, &tmp);
  157.   	if(idx == -1) return -1;
  158. > 	return idx + X509_PURPOSE_COUNT;
  159.   }
  160.   

crypto/x509v3/v3_purp.c:159:1: return from a call to X509_PURPOSE_get_by_id
  157.   	if(idx == -1) return -1;
  158.   	return idx + X509_PURPOSE_COUNT;
  159. > }
  160.   
  161.   int X509_PURPOSE_add(int id, int trust, int flags,

crypto/x509v3/v3_purp.c:118:5: Taking false branch
116.   	if(id == -1) return 1;
117.   	idx = X509_PURPOSE_get_by_id(id);
118.   	if(idx == -1) return -1;
           ^
119.   	pt = X509_PURPOSE_get0(idx);
120.   	return pt->check_purpose(pt, x, ca);

crypto/x509v3/v3_purp.c:119:2: 
117.   	idx = X509_PURPOSE_get_by_id(id);
118.   	if(idx == -1) return -1;
119. > 	pt = X509_PURPOSE_get0(idx);
120.   	return pt->check_purpose(pt, x, ca);
121.   }

crypto/x509v3/v3_purp.c:129:1: start of procedure X509_PURPOSE_get0()
  127.   }
  128.   
  129. > X509_PURPOSE * X509_PURPOSE_get0(int idx)
  130.   {
  131.   	if(idx < 0) return NULL;

crypto/x509v3/v3_purp.c:131:5: Taking true branch
  129.   X509_PURPOSE * X509_PURPOSE_get0(int idx)
  130.   {
  131.   	if(idx < 0) return NULL;
             ^
  132.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
  133.   	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);

crypto/x509v3/v3_purp.c:131:14: 
  129.   X509_PURPOSE * X509_PURPOSE_get0(int idx)
  130.   {
  131. > 	if(idx < 0) return NULL;
  132.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
  133.   	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);

crypto/x509v3/v3_purp.c:134:1: return from a call to X509_PURPOSE_get0
  132.   	if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
  133.   	return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
  134. > }
  135.   
  136.   int X509_PURPOSE_get_by_sname(char *sname)

crypto/x509v3/v3_purp.c:120:2: 
118.   	if(idx == -1) return -1;
119.   	pt = X509_PURPOSE_get0(idx);
120. > 	return pt->check_purpose(pt, x, ca);
121.   }
122.   

int X509_check_purpose(X509 *x, int id, int ca)
{
	int idx;
	const X509_PURPOSE *pt;
	if(!(x->ex_flags & EXFLAG_SET)) {
		CRYPTO_w_lock(CRYPTO_LOCK_X509);
		x509v3_cache_extensions(x);
		CRYPTO_w_unlock(CRYPTO_LOCK_X509);
	}
	if(id == -1) return 1;
	idx = X509_PURPOSE_get_by_id(id);
	if(idx == -1) return -1;
	pt = X509_PURPOSE_get0(idx);
	return pt->check_purpose(pt, x, ca);
}
['int X509_check_purpose(X509 *x, int id, int ca)\n{\n\tint idx;\n\tconst X509_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_get0(idx);\n\treturn pt->check_purpose(pt, x, ca);\n}', '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\tint i = -type - 1;\n\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t= CRYPTO_get_dynlock_value(i);\n\t\tif (pointer)\n\t\t\t{\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\t}\n\t\tCRYPTO_destroy_dynlockid(i);\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'static void x509v3_cache_extensions(X509 *x)\n{\n\tBASIC_CONSTRAINTS *bs;\n\tASN1_BIT_STRING *usage;\n\tASN1_BIT_STRING *ns;\n\tEXTENDED_KEY_USAGE *extusage;\n\tint i;\n\tif(x->ex_flags & EXFLAG_SET) return;\n#ifndef NO_SHA\n\tX509_digest(x, EVP_sha1(), x->sha1_hash, NULL);\n#endif\n\tif(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))\n\t\t\t x->ex_flags |= EXFLAG_SS;\n\tif(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;\n\tif((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {\n\t\tif(bs->ca) x->ex_flags |= EXFLAG_CA;\n\t\tif(bs->pathlen) {\n\t\t\tif((bs->pathlen->type == V_ASN1_NEG_INTEGER)\n\t\t\t\t\t\t|| !bs->ca) {\n\t\t\t\tx->ex_flags |= EXFLAG_INVALID;\n\t\t\t\tx->ex_pathlen = 0;\n\t\t\t} else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);\n\t\t} else x->ex_pathlen = -1;\n\t\tBASIC_CONSTRAINTS_free(bs);\n\t\tx->ex_flags |= EXFLAG_BCONS;\n\t}\n\tif((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {\n\t\tif(usage->length > 0) {\n\t\t\tx->ex_kusage = usage->data[0];\n\t\t\tif(usage->length > 1)\n\t\t\t\tx->ex_kusage |= usage->data[1] << 8;\n\t\t} else x->ex_kusage = 0;\n\t\tx->ex_flags |= EXFLAG_KUSAGE;\n\t\tASN1_BIT_STRING_free(usage);\n\t}\n\tx->ex_xkusage = 0;\n\tif((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {\n\t\tx->ex_flags |= EXFLAG_XKUSAGE;\n\t\tfor(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {\n\t\t\tswitch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {\n\t\t\t\tcase NID_server_auth:\n\t\t\t\tx->ex_xkusage |= XKU_SSL_SERVER;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_client_auth:\n\t\t\t\tx->ex_xkusage |= XKU_SSL_CLIENT;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_email_protect:\n\t\t\t\tx->ex_xkusage |= XKU_SMIME;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_code_sign:\n\t\t\t\tx->ex_xkusage |= XKU_CODE_SIGN;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_ms_sgc:\n\t\t\t\tcase NID_ns_sgc:\n\t\t\t\tx->ex_xkusage |= XKU_SGC;\n\t\t\t}\n\t\t}\n\t\tsk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);\n\t}\n\tif((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {\n\t\tif(ns->length > 0) x->ex_nscert = ns->data[0];\n\t\telse x->ex_nscert = 0;\n\t\tx->ex_flags |= EXFLAG_NSCERT;\n\t\tASN1_BIT_STRING_free(ns);\n\t}\n\tx->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);\n\tx->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);\n\tx->ex_flags |= EXFLAG_SET;\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n\tX509_PURPOSE tmp;\n\tint idx;\n\tif((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n\t\treturn purpose - X509_PURPOSE_MIN;\n\ttmp.purpose = purpose;\n\tif(!xptable) return -1;\n\tidx = sk_X509_PURPOSE_find(xptable, &tmp);\n\tif(idx == -1) return -1;\n\treturn idx + X509_PURPOSE_COUNT;\n}', 'X509_PURPOSE * X509_PURPOSE_get0(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_PURPOSE_COUNT) return xstandard + idx;\n\treturn sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']