crypto/x509v3/v3_utl.c:528: error: NULL_DEREFERENCE
  pointer `email` last assigned on line 527 could be null and is dereferenced by call to `append_ia5()` at line 528, column 7.
Showing all 43 steps of the trace


crypto/x509v3/v3_utl.c:514:1: start of procedure get_email()
512.   
513.   
514. > static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
515.   {
516.   	STACK *ret = NULL;

crypto/x509v3/v3_utl.c:516:2: 
514.   static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
515.   {
516. > 	STACK *ret = NULL;
517.   	X509_NAME_ENTRY *ne;
518.   	ASN1_IA5STRING *email;

crypto/x509v3/v3_utl.c:522:2: 
520.   	int i;
521.   	/* Now add any email address(es) to STACK */
522. > 	i = -1;
523.   	/* First supplied X509_NAME */
524.   	while((i = X509_NAME_get_index_by_NID(name,

crypto/x509v3/v3_utl.c:524:8: 
522.   	i = -1;
523.   	/* First supplied X509_NAME */
524. > 	while((i = X509_NAME_get_index_by_NID(name,
525.   					 NID_pkcs9_emailAddress, i)) >= 0) {
526.   		ne = X509_NAME_get_entry(name, i);

crypto/x509/x509name.c:98:1: start of procedure X509_NAME_get_index_by_NID()
  96.   	}
  97.   
  98. > int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
  99.   	{
  100.   	ASN1_OBJECT *obj;

crypto/x509/x509name.c:102:2: 
  100.   	ASN1_OBJECT *obj;
  101.   
  102. > 	obj=OBJ_nid2obj(nid);
  103.   	if (obj == NULL) return(-2);
  104.   	return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));

crypto/objects/obj_dat.c:293:1: start of procedure OBJ_nid2obj()
    291.   	}
    292.   
    293. > ASN1_OBJECT *OBJ_nid2obj(int n)
    294.   	{
    295.   	ADDED_OBJ ad,*adp;

crypto/objects/obj_dat.c:298:7: Taking true branch
    296.   	ASN1_OBJECT ob;
    297.   
    298.   	if ((n >= 0) && (n < NUM_NID))
                 ^
    299.   		{
    300.   		if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))

crypto/objects/obj_dat.c:298:19: Taking true branch
    296.   	ASN1_OBJECT ob;
    297.   
    298.   	if ((n >= 0) && (n < NUM_NID))
                             ^
    299.   		{
    300.   		if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))

crypto/objects/obj_dat.c:300:8: Taking true branch
    298.   	if ((n >= 0) && (n < NUM_NID))
    299.   		{
    300.   		if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
                  ^
    301.   			{
    302.   			OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);

crypto/objects/obj_dat.c:300:28: Taking false branch
    298.   	if ((n >= 0) && (n < NUM_NID))
    299.   		{
    300.   		if ((n != NID_undef) && (nid_objs[n].nid == NID_undef))
                                      ^
    301.   			{
    302.   			OBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);

crypto/objects/obj_dat.c:305:3: 
    303.   			return(NULL);
    304.   			}
    305. > 		return((ASN1_OBJECT *)&(nid_objs[n]));
    306.   		}
    307.   	else if (added == NULL)

crypto/objects/obj_dat.c:323:2: return from a call to OBJ_nid2obj
    321.   			}
    322.   		}
    323.   	}
            ^
    324.   
    325.   const char *OBJ_nid2sn(int n)

crypto/x509/x509name.c:103:6: Taking false branch
  101.   
  102.   	obj=OBJ_nid2obj(nid);
  103.   	if (obj == NULL) return(-2);
              ^
  104.   	return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));
  105.   	}

crypto/x509/x509name.c:104:2: Skipping X509_NAME_get_index_by_OBJ(): empty list of specs
  102.   	obj=OBJ_nid2obj(nid);
  103.   	if (obj == NULL) return(-2);
  104.   	return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));
          ^
  105.   	}
  106.   

crypto/x509/x509name.c:105:2: return from a call to X509_NAME_get_index_by_NID
  103.   	if (obj == NULL) return(-2);
  104.   	return(X509_NAME_get_index_by_OBJ(name,obj,lastpos));
  105.   	}
          ^
  106.   
  107.   /* NOTE: you should be passsing -1, not 0 as lastpos */

crypto/x509v3/v3_utl.c:524:8: Loop condition is true. Entering loop body
522.   	i = -1;
523.   	/* First supplied X509_NAME */
524.   	while((i = X509_NAME_get_index_by_NID(name,
              ^
525.   					 NID_pkcs9_emailAddress, i)) >= 0) {
526.   		ne = X509_NAME_get_entry(name, i);

crypto/x509v3/v3_utl.c:526:3: 
524.   	while((i = X509_NAME_get_index_by_NID(name,
525.   					 NID_pkcs9_emailAddress, i)) >= 0) {
526. > 		ne = X509_NAME_get_entry(name, i);
527.   		email = X509_NAME_ENTRY_get_data(ne);
528.   		if(!append_ia5(&ret, email)) return NULL;

crypto/x509/x509name.c:129:1: start of procedure X509_NAME_get_entry()
  127.   	}
  128.   
  129. > X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
  130.   	{
  131.   	if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc

crypto/x509/x509name.c:131:5: Taking false branch
  129.   X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
  130.   	{
  131.   	if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
             ^
  132.   	   || loc < 0)
  133.   		return(NULL);

crypto/x509/x509name.c:131:21: 
  129.   X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
  130.   	{
  131. > 	if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
  132.   	   || loc < 0)
  133.   		return(NULL);

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/x509name.c:131:21: Taking false branch
  129.   X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
  130.   	{
  131.   	if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
                             ^
  132.   	   || loc < 0)
  133.   		return(NULL);

crypto/x509/x509name.c:132:8: Taking false branch
  130.   	{
  131.   	if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
  132.   	   || loc < 0)
                ^
  133.   		return(NULL);
  134.   	else

crypto/x509/x509name.c:135:3: 
  133.   		return(NULL);
  134.   	else
  135. > 		return(sk_X509_NAME_ENTRY_value(name->entries,loc));
  136.   	}
  137.   

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 || (i < 0) || (i >= st->num)) return NULL;

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

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

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

crypto/stack/stack.c:310:2: 
    308.   {
    309.   	if(!st || (i < 0) || (i >= st->num)) 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 || (i < 0) || (i >= st->num)) return NULL;
    310.   	return st->data[i];
    311. > }
    312.   
    313.   char *sk_set(STACK *st, int i, char *value)

crypto/x509/x509name.c:136:2: return from a call to X509_NAME_get_entry
  134.   	else
  135.   		return(sk_X509_NAME_ENTRY_value(name->entries,loc));
  136.   	}
          ^
  137.   
  138.   X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)

crypto/x509v3/v3_utl.c:527:3: 
525.   					 NID_pkcs9_emailAddress, i)) >= 0) {
526.   		ne = X509_NAME_get_entry(name, i);
527. > 		email = X509_NAME_ENTRY_get_data(ne);
528.   		if(!append_ia5(&ret, email)) return NULL;
529.   	}

crypto/x509/x509name.c:378:1: start of procedure X509_NAME_ENTRY_get_data()
  376.   	}
  377.   
  378. > ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
  379.   	{
  380.   	if (ne == NULL) return(NULL);

crypto/x509/x509name.c:380:6: Taking true branch
  378.   ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
  379.   	{
  380.   	if (ne == NULL) return(NULL);
              ^
  381.   	return(ne->value);
  382.   	}

crypto/x509/x509name.c:380:18: 
  378.   ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
  379.   	{
  380. > 	if (ne == NULL) return(NULL);
  381.   	return(ne->value);
  382.   	}

crypto/x509/x509name.c:382:2: return from a call to X509_NAME_ENTRY_get_data
  380.   	if (ne == NULL) return(NULL);
  381.   	return(ne->value);
  382.   	}
          ^
  383.   

crypto/x509v3/v3_utl.c:528:7: 
526.   		ne = X509_NAME_get_entry(name, i);
527.   		email = X509_NAME_ENTRY_get_data(ne);
528. > 		if(!append_ia5(&ret, email)) return NULL;
529.   	}
530.   	for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)

crypto/x509v3/v3_utl.c:544:1: start of procedure append_ia5()
  542.   }
  543.   
  544. > static int append_ia5(STACK **sk, ASN1_IA5STRING *email)
  545.   {
  546.   	char *emtmp;

crypto/x509v3/v3_utl.c:548:5: 
  546.   	char *emtmp;
  547.   	/* First some sanity checks */
  548. > 	if(email->type != V_ASN1_IA5STRING) return 1;
  549.   	if(!email->data || !email->length) return 1;
  550.   	if(!*sk) *sk = sk_new(sk_strcmp);

static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
{
	STACK *ret = NULL;
	X509_NAME_ENTRY *ne;
	ASN1_IA5STRING *email;
	GENERAL_NAME *gen;
	int i;
	i = -1;
	while((i = X509_NAME_get_index_by_NID(name,
					 NID_pkcs9_emailAddress, i)) >= 0) {
		ne = X509_NAME_get_entry(name, i);
		email = X509_NAME_ENTRY_get_data(ne);
		if(!append_ia5(&ret, email)) return NULL;
	}
	for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
	{
		gen = sk_GENERAL_NAME_value(gens, i);
		if(gen->type != GEN_EMAIL) continue;
		if(!append_ia5(&ret, gen->d.ia5)) return NULL;
	}
	return ret;
}
['static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)\n{\n\tSTACK *ret = NULL;\n\tX509_NAME_ENTRY *ne;\n\tASN1_IA5STRING *email;\n\tGENERAL_NAME *gen;\n\tint i;\n\ti = -1;\n\twhile((i = X509_NAME_get_index_by_NID(name,\n\t\t\t\t\t NID_pkcs9_emailAddress, i)) >= 0) {\n\t\tne = X509_NAME_get_entry(name, i);\n\t\temail = X509_NAME_ENTRY_get_data(ne);\n\t\tif(!append_ia5(&ret, email)) return NULL;\n\t}\n\tfor(i = 0; i < sk_GENERAL_NAME_num(gens); i++)\n\t{\n\t\tgen = sk_GENERAL_NAME_value(gens, i);\n\t\tif(gen->type != GEN_EMAIL) continue;\n\t\tif(!append_ia5(&ret, gen->d.ia5)) return NULL;\n\t}\n\treturn ret;\n}', 'int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)\n\t{\n\tASN1_OBJECT *obj;\n\tobj=OBJ_nid2obj(nid);\n\tif (obj == NULL) return(-2);\n\treturn(X509_NAME_get_index_by_OBJ(name,obj,lastpos));\n\t}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn((ASN1_OBJECT *)&(nid_objs[n]));\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}', 'X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)\n\t{\n\tif(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc\n\t   || loc < 0)\n\t\treturn(NULL);\n\telse\n\t\treturn(sk_X509_NAME_ENTRY_value(name->entries,loc));\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}', 'ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)\n\t{\n\tif (ne == NULL) return(NULL);\n\treturn(ne->value);\n\t}', 'static int append_ia5(STACK **sk, ASN1_IA5STRING *email)\n{\n\tchar *emtmp;\n\tif(email->type != V_ASN1_IA5STRING) return 1;\n\tif(!email->data || !email->length) return 1;\n\tif(!*sk) *sk = sk_new(sk_strcmp);\n\tif(!*sk) return 0;\n\tif(sk_find(*sk, (char *)email->data) != -1) return 1;\n\temtmp = BUF_strdup((char *)email->data);\n\tif(!emtmp || !sk_push(*sk, emtmp)) {\n\t\tX509_email_free(*sk);\n\t\t*sk = NULL;\n\t\treturn 0;\n\t}\n\treturn 1;\n}']