crypto/x509v3/v3_purp.c:182: error: NULL_DEREFERENCE
  pointer `ptmp` last assigned on line 179 could be null and is dereferenced at line 182, column 5.
Showing all 20 steps of the trace


crypto/x509v3/v3_purp.c:160:1: start of procedure X509_PURPOSE_add()
158.   }
159.   
160. > int X509_PURPOSE_add(int id, int trust, int flags,
161.   			int (*ck)(const X509_PURPOSE *, const X509 *, int),
162.   					char *name, char *sname, void *arg)

crypto/x509v3/v3_purp.c:167:2: 
165.   	X509_PURPOSE *ptmp;
166.   	/* This is set according to what we change: application can't set it */
167. > 	flags &= ~X509_PURPOSE_DYNAMIC;
168.   	/* This will always be set for application modified trust entries */
169.   	flags |= X509_PURPOSE_DYNAMIC_NAME;

crypto/x509v3/v3_purp.c:169:2: 
167.   	flags &= ~X509_PURPOSE_DYNAMIC;
168.   	/* This will always be set for application modified trust entries */
169. > 	flags |= X509_PURPOSE_DYNAMIC_NAME;
170.   	/* Get existing entry if any */
171.   	idx = X509_PURPOSE_get_by_id(id);

crypto/x509v3/v3_purp.c:171:2: 
169.   	flags |= X509_PURPOSE_DYNAMIC_NAME;
170.   	/* Get existing entry if any */
171. > 	idx = X509_PURPOSE_get_by_id(id);
172.   	/* Need a new entry */
173.   	if(idx == -1) {

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

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

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

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

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

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

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

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

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

crypto/x509v3/v3_purp.c:173:5: Taking false branch
171.   	idx = X509_PURPOSE_get_by_id(id);
172.   	/* Need a new entry */
173.   	if(idx == -1) {
           ^
174.   		if(!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) {
175.   			X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);

crypto/x509v3/v3_purp.c:179:9: 
177.   		}
178.   		ptmp->flags = X509_PURPOSE_DYNAMIC;
179. > 	} else ptmp = X509_PURPOSE_get0(idx);
180.   
181.   	/* OPENSSL_free existing name if dynamic */

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

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

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

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

crypto/x509v3/v3_purp.c:182:5: 
180.   
181.   	/* OPENSSL_free existing name if dynamic */
182. > 	if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
183.   		OPENSSL_free(ptmp->name);
184.   		OPENSSL_free(ptmp->sname);

int X509_PURPOSE_add(int id, int trust, int flags,
			int (*ck)(const X509_PURPOSE *, const X509 *, int),
					char *name, char *sname, void *arg)
{
	int idx;
	X509_PURPOSE *ptmp;
	flags &= ~X509_PURPOSE_DYNAMIC;
	flags |= X509_PURPOSE_DYNAMIC_NAME;
	idx = X509_PURPOSE_get_by_id(id);
	if(idx == -1) {
		if(!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) {
			X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
			return 0;
		}
		ptmp->flags = X509_PURPOSE_DYNAMIC;
	} else ptmp = X509_PURPOSE_get0(idx);
	if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
		OPENSSL_free(ptmp->name);
		OPENSSL_free(ptmp->sname);
	}
	ptmp->name = BUF_strdup(name);
	ptmp->sname = BUF_strdup(sname);
	if(!ptmp->name || !ptmp->sname) {
		X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
		return 0;
	}
	ptmp->flags &= X509_PURPOSE_DYNAMIC;
	ptmp->flags |= flags;
	ptmp->purpose = id;
	ptmp->trust = trust;
	ptmp->check_purpose = ck;
	ptmp->usr_data = arg;
	if(idx == -1) {
		if(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
			X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
			return 0;
		}
		if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
			X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
			return 0;
		}
	}
	return 1;
}
['int X509_PURPOSE_add(int id, int trust, int flags,\n\t\t\tint (*ck)(const X509_PURPOSE *, const X509 *, int),\n\t\t\t\t\tchar *name, char *sname, void *arg)\n{\n\tint idx;\n\tX509_PURPOSE *ptmp;\n\tflags &= ~X509_PURPOSE_DYNAMIC;\n\tflags |= X509_PURPOSE_DYNAMIC_NAME;\n\tidx = X509_PURPOSE_get_by_id(id);\n\tif(idx == -1) {\n\t\tif(!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) {\n\t\t\tX509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t}\n\t\tptmp->flags = X509_PURPOSE_DYNAMIC;\n\t} else ptmp = X509_PURPOSE_get0(idx);\n\tif(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {\n\t\tOPENSSL_free(ptmp->name);\n\t\tOPENSSL_free(ptmp->sname);\n\t}\n\tptmp->name = BUF_strdup(name);\n\tptmp->sname = BUF_strdup(sname);\n\tif(!ptmp->name || !ptmp->sname) {\n\t\tX509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);\n\t\treturn 0;\n\t}\n\tptmp->flags &= X509_PURPOSE_DYNAMIC;\n\tptmp->flags |= flags;\n\tptmp->purpose = id;\n\tptmp->trust = trust;\n\tptmp->check_purpose = ck;\n\tptmp->usr_data = arg;\n\tif(idx == -1) {\n\t\tif(!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {\n\t\t\tX509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t}\n\t\tif (!sk_X509_PURPOSE_push(xptable, ptmp)) {\n\t\t\tX509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t}\n\t}\n\treturn 1;\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}']