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


crypto/x509/x509_trs.c:157:1: start of procedure X509_TRUST_add()
155.   }
156.   
157. > int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
158.   					char *name, int arg1, void *arg2)
159.   {

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

crypto/x509/x509_trs.c:165:2: 
163.   	flags &= ~X509_TRUST_DYNAMIC;
164.   	/* This will always be set for application modified trust entries */
165. > 	flags |= X509_TRUST_DYNAMIC_NAME;
166.   	/* Get existing entry if any */
167.   	idx = X509_TRUST_get_by_id(id);

crypto/x509/x509_trs.c:167:2: 
165.   	flags |= X509_TRUST_DYNAMIC_NAME;
166.   	/* Get existing entry if any */
167. > 	idx = X509_TRUST_get_by_id(id);
168.   	/* Need a new entry */
169.   	if(idx == -1) {

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

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

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

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

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

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

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

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

crypto/x509/x509_trs.c:145:1: return from a call to X509_TRUST_get_by_id
  143.   	if(idx == -1) return -1;
  144.   	return idx + X509_TRUST_COUNT;
  145. > }
  146.   
  147.   int X509_TRUST_set(int *t, int trust)

crypto/x509/x509_trs.c:169:5: Taking false branch
167.   	idx = X509_TRUST_get_by_id(id);
168.   	/* Need a new entry */
169.   	if(idx == -1) {
           ^
170.   		if(!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) {
171.   			X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);

crypto/x509/x509_trs.c:175:9: 
173.   		}
174.   		trtmp->flags = X509_TRUST_DYNAMIC;
175. > 	} else trtmp = X509_TRUST_get0(idx);
176.   
177.   	/* OPENSSL_free existing name if dynamic */

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

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

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

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

crypto/x509/x509_trs.c:178:5: 
176.   
177.   	/* OPENSSL_free existing name if dynamic */
178. > 	if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name);
179.   	/* dup supplied name */
180.   	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}']