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


crypto/x509/x509_trs.c:146:1: start of procedure X509_TRUST_add()
144.   }
145.   
146. > int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
147.   					char *name, int arg1, void *arg2)
148.   {

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

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

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

crypto/x509/x509_trs.c:133:1: start of procedure X509_TRUST_get_by_id()
  131.   }
  132.   
  133. > int X509_TRUST_get_by_id(int id)
  134.   {
  135.   	X509_TRUST tmp;

crypto/x509/x509_trs.c:137:6: Taking true branch
  135.   	X509_TRUST tmp;
  136.   	int idx;
  137.   	if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
              ^
  138.   				 return id - X509_TRUST_MIN;
  139.   	tmp.trust = id;

crypto/x509/x509_trs.c:137:32: Taking false branch
  135.   	X509_TRUST tmp;
  136.   	int idx;
  137.   	if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
                                        ^
  138.   				 return id - X509_TRUST_MIN;
  139.   	tmp.trust = id;

crypto/x509/x509_trs.c:139:2: 
  137.   	if((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX))
  138.   				 return id - X509_TRUST_MIN;
  139. > 	tmp.trust = id;
  140.   	if(!trtable) return -1;
  141.   	idx = sk_X509_TRUST_find(trtable, &tmp);

crypto/x509/x509_trs.c:140:6: Taking false branch
  138.   				 return id - X509_TRUST_MIN;
  139.   	tmp.trust = id;
  140.   	if(!trtable) return -1;
              ^
  141.   	idx = sk_X509_TRUST_find(trtable, &tmp);
  142.   	if(idx == -1) return -1;

crypto/x509/x509_trs.c:141:2: Skipping sk_find(): empty list of specs
  139.   	tmp.trust = id;
  140.   	if(!trtable) return -1;
  141.   	idx = sk_X509_TRUST_find(trtable, &tmp);
          ^
  142.   	if(idx == -1) return -1;
  143.   	return idx + X509_TRUST_COUNT;

crypto/x509/x509_trs.c:142:5: Taking false branch
  140.   	if(!trtable) return -1;
  141.   	idx = sk_X509_TRUST_find(trtable, &tmp);
  142.   	if(idx == -1) return -1;
             ^
  143.   	return idx + X509_TRUST_COUNT;
  144.   }

crypto/x509/x509_trs.c:143:2: 
  141.   	idx = sk_X509_TRUST_find(trtable, &tmp);
  142.   	if(idx == -1) return -1;
  143. > 	return idx + X509_TRUST_COUNT;
  144.   }
  145.   

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

crypto/x509/x509_trs.c:158:5: Taking false branch
156.   	idx = X509_TRUST_get_by_id(id);
157.   	/* Need a new entry */
158.   	if(idx == -1) {
           ^
159.   		if(!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) {
160.   			X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);

crypto/x509/x509_trs.c:164:9: 
162.   		}
163.   		trtmp->flags = X509_TRUST_DYNAMIC;
164. > 	} else trtmp = X509_TRUST_get0(idx);
165.   
166.   	/* OPENSSL_free existing name if dynamic */

crypto/x509/x509_trs.c:126:1: start of procedure X509_TRUST_get0()
  124.   }
  125.   
  126. > X509_TRUST * X509_TRUST_get0(int idx)
  127.   {
  128.   	if(idx < 0) return NULL;

crypto/x509/x509_trs.c:128:5: Taking true branch
  126.   X509_TRUST * X509_TRUST_get0(int idx)
  127.   {
  128.   	if(idx < 0) return NULL;
             ^
  129.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
  130.   	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);

crypto/x509/x509_trs.c:128:14: 
  126.   X509_TRUST * X509_TRUST_get0(int idx)
  127.   {
  128. > 	if(idx < 0) return NULL;
  129.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
  130.   	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);

crypto/x509/x509_trs.c:131:1: return from a call to X509_TRUST_get0
  129.   	if(idx < X509_TRUST_COUNT) return trstandard + idx;
  130.   	return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
  131. > }
  132.   
  133.   int X509_TRUST_get_by_id(int id)

crypto/x509/x509_trs.c:167:5: 
165.   
166.   	/* OPENSSL_free existing name if dynamic */
167. > 	if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name);
168.   	/* dup supplied name */
169.   	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 = OPENSSL_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_get0(idx);
	if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_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 = OPENSSL_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_get0(idx);\n\tif(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_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_get0(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}']