crypto/x509/x509_trs.c:163: error: NULL_DEREFERENCE
  pointer `trtmp` last assigned on line 160 could be null and is dereferenced at line 163, column 5.
Showing all 23 steps of the trace


crypto/x509/x509_trs.c:142:1: start of procedure X509_TRUST_add()
140.   }
141.   
142. > int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
143.   					char *name, int arg1, void *arg2)
144.   {

crypto/x509/x509_trs.c:148:2: 
146.   	X509_TRUST *trtmp;
147.   	/* This is set according to what we change: application can't set it */
148. > 	flags &= ~X509_TRUST_DYNAMIC;
149.   	/* This will always be set for application modified trust entries */
150.   	flags |= X509_TRUST_DYNAMIC_NAME;

crypto/x509/x509_trs.c:150:2: 
148.   	flags &= ~X509_TRUST_DYNAMIC;
149.   	/* This will always be set for application modified trust entries */
150. > 	flags |= X509_TRUST_DYNAMIC_NAME;
151.   	/* Get existing entry if any */
152.   	idx = X509_TRUST_get_by_id(id);

crypto/x509/x509_trs.c:152:2: 
150.   	flags |= X509_TRUST_DYNAMIC_NAME;
151.   	/* Get existing entry if any */
152. > 	idx = X509_TRUST_get_by_id(id);
153.   	/* Need a new entry */
154.   	if(idx == -1) {

crypto/x509/x509_trs.c:129:1: start of procedure X509_TRUST_get_by_id()
  127.   }
  128.   
  129. > int X509_TRUST_get_by_id(int id)
  130.   {
  131.   	X509_TRUST tmp;

crypto/x509/x509_trs.c:133:6: Taking true branch
  131.   	X509_TRUST tmp;
  132.   	int idx;
  133.   	if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
              ^
  134.   				 return id - X509_TRUST_MIN;
  135.   	tmp.trust = id;

crypto/x509/x509_trs.c:133:32: Taking true branch
  131.   	X509_TRUST tmp;
  132.   	int idx;
  133.   	if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
                                        ^
  134.   				 return id - X509_TRUST_MIN;
  135.   	tmp.trust = id;

crypto/x509/x509_trs.c:134:6: 
  132.   	int idx;
  133.   	if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
  134. > 				 return id - X509_TRUST_MIN;
  135.   	tmp.trust = id;
  136.   	if(!trtable) return -1;

crypto/x509/x509_trs.c:140:1: return from a call to X509_TRUST_get_by_id
  138.   	if(idx == -1) return -1;
  139.   	return idx + X509_TRUST_COUNT;
  140. > }
  141.   
  142.   int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),

crypto/x509/x509_trs.c:154:5: Taking false branch
152.   	idx = X509_TRUST_get_by_id(id);
153.   	/* Need a new entry */
154.   	if(idx == -1) {
           ^
155.   		if(!(trtmp = Malloc(sizeof(X509_TRUST)))) {
156.   			X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);

crypto/x509/x509_trs.c:160:9: 
158.   		}
159.   		trtmp->flags = X509_TRUST_DYNAMIC;
160. > 	} else trtmp = X509_TRUST_iget(idx);
161.   
162.   	/* Free existing name if dynamic */

crypto/x509/x509_trs.c:122:1: start of procedure X509_TRUST_iget()
  120.   }
  121.   
  122. > X509_TRUST * X509_TRUST_iget(int idx)
  123.   {
  124.   	if(idx < 0) return NULL;

crypto/x509/x509_trs.c:124:5: Taking false branch
  122.   X509_TRUST * X509_TRUST_iget(int idx)
  123.   {
  124.   	if(idx < 0) return NULL;
             ^
  125.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
  126.   	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);

crypto/x509/x509_trs.c:125:5: Taking false branch
  123.   {
  124.   	if(idx < 0) return NULL;
  125.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
             ^
  126.   	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
  127.   }

crypto/x509/x509_trs.c:126:2: 
  124.   	if(idx < 0) return NULL;
  125.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
  126. > 	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
  127.   }
  128.   

crypto/x509/x509_trs.c:87:1: start of procedure sk_X509_TRUST_value()
    85.   #define X509_TRUST_COUNT	(sizeof(trstandard)/sizeof(X509_TRUST))
    86.   
    87. > IMPLEMENT_STACK_OF(X509_TRUST)
    88.   
    89.   static STACK_OF(X509_TRUST) *trtable = NULL;

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_trs.c:87:1: return from a call to sk_X509_TRUST_value
    85.   #define X509_TRUST_COUNT	(sizeof(trstandard)/sizeof(X509_TRUST))
    86.   
    87. > IMPLEMENT_STACK_OF(X509_TRUST)
    88.   
    89.   static STACK_OF(X509_TRUST) *trtable = NULL;

crypto/x509/x509_trs.c:127:1: return from a call to X509_TRUST_iget
  125.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
  126.   	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
  127. > }
  128.   
  129.   int X509_TRUST_get_by_id(int id)

crypto/x509/x509_trs.c:163:5: 
161.   
162.   	/* Free existing name if dynamic */
163. > 	if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name);
164.   	/* dup supplied name */
165.   	if(!(trtmp->name = BUF_strdup(name))) {

int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
					char *name, int arg1, void *arg2)
{
	int idx;
	X509_TRUST *trtmp;
	flags &= ~X509_TRUST_DYNAMIC;
	flags |= X509_TRUST_DYNAMIC_NAME;
	idx = X509_TRUST_get_by_id(id);
	if(idx == -1) {
		if(!(trtmp = Malloc(sizeof(X509_TRUST)))) {
			X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
			return 0;
		}
		trtmp->flags = X509_TRUST_DYNAMIC;
	} else trtmp = X509_TRUST_iget(idx);
	if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name);
	if(!(trtmp->name = BUF_strdup(name))) {
		X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
		return 0;
	}
	trtmp->flags &= X509_TRUST_DYNAMIC;
	trtmp->flags |= flags;
	trtmp->trust = id;
	trtmp->check_trust = ck;
	trtmp->arg1 = arg1;
	trtmp->arg2 = arg2;
	if(idx == -1) {
		if(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
			X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
			return 0;
		}
		if (!sk_X509_TRUST_push(trtable, trtmp)) {
			X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
			return 0;
		}
	}
	return 1;
}
['int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),\n\t\t\t\t\tchar *name, int arg1, void *arg2)\n{\n\tint idx;\n\tX509_TRUST *trtmp;\n\tflags &= ~X509_TRUST_DYNAMIC;\n\tflags |= X509_TRUST_DYNAMIC_NAME;\n\tidx = X509_TRUST_get_by_id(id);\n\tif(idx == -1) {\n\t\tif(!(trtmp = Malloc(sizeof(X509_TRUST)))) {\n\t\t\tX509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t}\n\t\ttrtmp->flags = X509_TRUST_DYNAMIC;\n\t} else trtmp = X509_TRUST_iget(idx);\n\tif(trtmp->flags & X509_TRUST_DYNAMIC_NAME) Free(trtmp->name);\n\tif(!(trtmp->name = BUF_strdup(name))) {\n\t\tX509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);\n\t\treturn 0;\n\t}\n\ttrtmp->flags &= X509_TRUST_DYNAMIC;\n\ttrtmp->flags |= flags;\n\ttrtmp->trust = id;\n\ttrtmp->check_trust = ck;\n\ttrtmp->arg1 = arg1;\n\ttrtmp->arg2 = arg2;\n\tif(idx == -1) {\n\t\tif(!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {\n\t\t\tX509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t}\n\t\tif (!sk_X509_TRUST_push(trtable, trtmp)) {\n\t\t\tX509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 1;\n}', 'int X509_TRUST_get_by_id(int id)\n{\n\tX509_TRUST tmp;\n\tint idx;\n\tif((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))\n\t\t\t\t return id - X509_TRUST_MIN;\n\ttmp.trust = id;\n\tif(!trtable) return -1;\n\tidx = sk_X509_TRUST_find(trtable, &tmp);\n\tif(idx == -1) return -1;\n\treturn idx + X509_TRUST_COUNT;\n}', 'X509_TRUST * X509_TRUST_iget(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_TRUST_COUNT) return trstandard + idx;\n\treturn sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);\n}', 'IMPLEMENT_STACK_OF(X509_TRUST)', 'char *sk_value(STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}']