crypto/x509v3/v3_purp.c:174: error: NULL_DEREFERENCE
  pointer `ptmp` last assigned on line 171 could be null and is dereferenced at line 174, column 9.
Showing all 36 steps of the trace


crypto/x509v3/v3_purp.c:149:1: start of procedure X509_PURPOSE_add()
147.   }
148.   
149. > int X509_PURPOSE_add(int id, int trust, int flags,
150.                        int (*ck) (const X509_PURPOSE *, const X509 *, int),
151.                        const char *name, const char *sname, void *arg)

crypto/x509v3/v3_purp.c:158:5: 
156.        * This is set according to what we change: application can't set it
157.        */
158. >     flags &= ~X509_PURPOSE_DYNAMIC;
159.       /* This will always be set for application modified trust entries */
160.       flags |= X509_PURPOSE_DYNAMIC_NAME;

crypto/x509v3/v3_purp.c:160:5: 
158.       flags &= ~X509_PURPOSE_DYNAMIC;
159.       /* This will always be set for application modified trust entries */
160. >     flags |= X509_PURPOSE_DYNAMIC_NAME;
161.       /* Get existing entry if any */
162.       idx = X509_PURPOSE_get_by_id(id);

crypto/x509v3/v3_purp.c:162:5: 
160.       flags |= X509_PURPOSE_DYNAMIC_NAME;
161.       /* Get existing entry if any */
162. >     idx = X509_PURPOSE_get_by_id(id);
163.       /* Need a new entry */
164.       if (idx == -1) {

crypto/x509v3/v3_purp.c:134:1: start of procedure X509_PURPOSE_get_by_id()
  132.   }
  133.   
  134. > int X509_PURPOSE_get_by_id(int purpose)
  135.   {
  136.       X509_PURPOSE tmp;

crypto/x509v3/v3_purp.c:138:10: Taking true branch
  136.       X509_PURPOSE tmp;
  137.       int idx;
  138.       if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
                  ^
  139.           return purpose - X509_PURPOSE_MIN;
  140.       tmp.purpose = purpose;

crypto/x509v3/v3_purp.c:138:43: Taking false branch
  136.       X509_PURPOSE tmp;
  137.       int idx;
  138.       if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
                                                   ^
  139.           return purpose - X509_PURPOSE_MIN;
  140.       tmp.purpose = purpose;

crypto/x509v3/v3_purp.c:140:5: 
  138.       if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
  139.           return purpose - X509_PURPOSE_MIN;
  140. >     tmp.purpose = purpose;
  141.       if (!xptable)
  142.           return -1;

crypto/x509v3/v3_purp.c:141:10: Taking false branch
  139.           return purpose - X509_PURPOSE_MIN;
  140.       tmp.purpose = purpose;
  141.       if (!xptable)
                  ^
  142.           return -1;
  143.       idx = sk_X509_PURPOSE_find(xptable, &tmp);

crypto/x509v3/v3_purp.c:143:5: 
  141.       if (!xptable)
  142.           return -1;
  143. >     idx = sk_X509_PURPOSE_find(xptable, &tmp);
  144.       if (idx == -1)
  145.           return -1;

include/openssl/x509v3.h:445:1: start of procedure sk_X509_PURPOSE_find()
    443.   # define X509V3_ADD_SILENT               0x10
    444.   
    445. > DEFINE_STACK_OF(X509_PURPOSE)
    446.   
    447.   DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)

crypto/stack/stack.c:190:1: start of procedure OPENSSL_sk_find()
      188.   }
      189.   
      190. > int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      191.   {
      192.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:192:5: 
      190.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      191.   {
      192. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      193.   }
      194.   

crypto/stack/stack.c:165:1: start of procedure internal_find()
        163.   }
        164.   
        165. > static int internal_find(OPENSSL_STACK *st, const void *data,
        166.                            int ret_val_options)
        167.   {

crypto/stack/stack.c:171:9: Taking false branch
        169.       int i;
        170.   
        171.       if (st == NULL)
                       ^
        172.           return -1;
        173.   

crypto/stack/stack.c:174:9: Taking true branch
        172.           return -1;
        173.   
        174.       if (st->comp == NULL) {
                       ^
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)

crypto/stack/stack.c:175:14: 
        173.   
        174.       if (st->comp == NULL) {
        175. >         for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:175:21: Loop condition is true. Entering loop body
        173.   
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
                                   ^
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:176:17: Taking false branch
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
                               ^
        177.                   return (i);
        178.           return (-1);

crypto/stack/stack.c:175:34: 
        173.   
        174.       if (st->comp == NULL) {
        175. >         for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:175:21: Loop condition is true. Entering loop body
        173.   
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
                                   ^
        176.               if (st->data[i] == data)
        177.                   return (i);

crypto/stack/stack.c:176:17: Taking true branch
        174.       if (st->comp == NULL) {
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
                               ^
        177.                   return (i);
        178.           return (-1);

crypto/stack/stack.c:177:17: 
        175.           for (i = 0; i < st->num; i++)
        176.               if (st->data[i] == data)
        177. >                 return (i);
        178.           return (-1);
        179.       }

crypto/stack/stack.c:188:1: return from a call to internal_find
        186.           return (-1);
        187.       return (int)((const char **)r - st->data);
        188. > }
        189.   
        190.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)

crypto/stack/stack.c:193:1: return from a call to OPENSSL_sk_find
      191.   {
      192.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      193. > }
      194.   
      195.   int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data)

include/openssl/x509v3.h:445:1: return from a call to sk_X509_PURPOSE_find
    443.   # define X509V3_ADD_SILENT               0x10
    444.   
    445. > DEFINE_STACK_OF(X509_PURPOSE)
    446.   
    447.   DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)

crypto/x509v3/v3_purp.c:144:9: Taking false branch
  142.           return -1;
  143.       idx = sk_X509_PURPOSE_find(xptable, &tmp);
  144.       if (idx == -1)
                 ^
  145.           return -1;
  146.       return idx + X509_PURPOSE_COUNT;

crypto/x509v3/v3_purp.c:146:5: 
  144.       if (idx == -1)
  145.           return -1;
  146. >     return idx + X509_PURPOSE_COUNT;
  147.   }
  148.   

crypto/x509v3/v3_purp.c:147:1: return from a call to X509_PURPOSE_get_by_id
  145.           return -1;
  146.       return idx + X509_PURPOSE_COUNT;
  147. > }
  148.   
  149.   int X509_PURPOSE_add(int id, int trust, int flags,

crypto/x509v3/v3_purp.c:164:9: Taking false branch
162.       idx = X509_PURPOSE_get_by_id(id);
163.       /* Need a new entry */
164.       if (idx == -1) {
               ^
165.           if ((ptmp = OPENSSL_malloc(sizeof(*ptmp))) == NULL) {
166.               X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);

crypto/x509v3/v3_purp.c:171:9: 
169.           ptmp->flags = X509_PURPOSE_DYNAMIC;
170.       } else
171. >         ptmp = X509_PURPOSE_get0(idx);
172.   
173.       /* OPENSSL_free existing name if dynamic */

crypto/x509v3/v3_purp.c:113:1: start of procedure X509_PURPOSE_get0()
  111.   }
  112.   
  113. > X509_PURPOSE *X509_PURPOSE_get0(int idx)
  114.   {
  115.       if (idx < 0)

crypto/x509v3/v3_purp.c:115:9: Taking true branch
  113.   X509_PURPOSE *X509_PURPOSE_get0(int idx)
  114.   {
  115.       if (idx < 0)
                 ^
  116.           return NULL;
  117.       if (idx < (int)X509_PURPOSE_COUNT)

crypto/x509v3/v3_purp.c:116:9: 
  114.   {
  115.       if (idx < 0)
  116. >         return NULL;
  117.       if (idx < (int)X509_PURPOSE_COUNT)
  118.           return xstandard + idx;

crypto/x509v3/v3_purp.c:120:1: return from a call to X509_PURPOSE_get0
  118.           return xstandard + idx;
  119.       return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
  120. > }
  121.   
  122.   int X509_PURPOSE_get_by_sname(const char *sname)

crypto/x509v3/v3_purp.c:174:9: 
172.   
173.       /* OPENSSL_free existing name if dynamic */
174. >     if (ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
175.           OPENSSL_free(ptmp->name);
176.           OPENSSL_free(ptmp->sname);
