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:448:1: start of procedure sk_X509_PURPOSE_find()
    446.   # define X509V3_ADD_SILENT               0x10
    447.   
    448. > DEFINE_STACK_OF(X509_PURPOSE)
    449.   
    450.   DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)

crypto/stack/stack.c:270:1: start of procedure OPENSSL_sk_find()
      268.   }
      269.   
      270. > int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      271.   {
      272.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:272:5: 
      270.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      271.   {
      272. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      273.   }
      274.   

crypto/stack/stack.c:245:1: start of procedure internal_find()
        243.   }
        244.   
        245. > static int internal_find(OPENSSL_STACK *st, const void *data,
        246.                            int ret_val_options)
        247.   {

crypto/stack/stack.c:251:9: Taking false branch
        249.       int i;
        250.   
        251.       if (st == NULL)
                       ^
        252.           return -1;
        253.   

crypto/stack/stack.c:254:9: Taking true branch
        252.           return -1;
        253.   
        254.       if (st->comp == NULL) {
                       ^
        255.           for (i = 0; i < st->num; i++)
        256.               if (st->data[i] == data)

crypto/stack/stack.c:255:14: 
        253.   
        254.       if (st->comp == NULL) {
        255. >         for (i = 0; i < st->num; i++)
        256.               if (st->data[i] == data)
        257.                   return (i);

crypto/stack/stack.c:255:21: Loop condition is true. Entering loop body
        253.   
        254.       if (st->comp == NULL) {
        255.           for (i = 0; i < st->num; i++)
                                   ^
        256.               if (st->data[i] == data)
        257.                   return (i);

crypto/stack/stack.c:256:17: Taking false branch
        254.       if (st->comp == NULL) {
        255.           for (i = 0; i < st->num; i++)
        256.               if (st->data[i] == data)
                               ^
        257.                   return (i);
        258.           return (-1);

crypto/stack/stack.c:255:34: 
        253.   
        254.       if (st->comp == NULL) {
        255. >         for (i = 0; i < st->num; i++)
        256.               if (st->data[i] == data)
        257.                   return (i);

crypto/stack/stack.c:255:21: Loop condition is true. Entering loop body
        253.   
        254.       if (st->comp == NULL) {
        255.           for (i = 0; i < st->num; i++)
                                   ^
        256.               if (st->data[i] == data)
        257.                   return (i);

crypto/stack/stack.c:256:17: Taking true branch
        254.       if (st->comp == NULL) {
        255.           for (i = 0; i < st->num; i++)
        256.               if (st->data[i] == data)
                               ^
        257.                   return (i);
        258.           return (-1);

crypto/stack/stack.c:257:17: 
        255.           for (i = 0; i < st->num; i++)
        256.               if (st->data[i] == data)
        257. >                 return (i);
        258.           return (-1);
        259.       }

crypto/stack/stack.c:268:1: return from a call to internal_find
        266.           return (-1);
        267.       return (int)((const void **)r - st->data);
        268. > }
        269.   
        270.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)

crypto/stack/stack.c:273:1: return from a call to OPENSSL_sk_find
      271.   {
      272.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      273. > }
      274.   
      275.   int OPENSSL_sk_find_ex(OPENSSL_STACK *st, const void *data)

include/openssl/x509v3.h:448:1: return from a call to sk_X509_PURPOSE_find
    446.   # define X509V3_ADD_SILENT               0x10
    447.   
    448. > DEFINE_STACK_OF(X509_PURPOSE)
    449.   
    450.   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);

int X509_PURPOSE_add(int id, int trust, int flags,
                     int (*ck) (const X509_PURPOSE *, const X509 *, int),
                     const char *name, const 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(*ptmp))) == NULL) {
            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 = OPENSSL_strdup(name);
    ptmp->sname = OPENSSL_strdup(sname);
    if (!ptmp->name || !ptmp->sname) {
        X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    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 == NULL
            && (xptable = sk_X509_PURPOSE_new(xp_cmp)) == NULL) {
            X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);
            goto err;
        }
        if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
            X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);
            goto err;
        }
    }
    return 1;
 err:
    if (idx == -1) {
        OPENSSL_free(ptmp->name);
        OPENSSL_free(ptmp->sname);
        OPENSSL_free(ptmp);
    }
    return 0;
}
['int X509_PURPOSE_add(int id, int trust, int flags,\n                     int (*ck) (const X509_PURPOSE *, const X509 *, int),\n                     const char *name, const char *sname, void *arg)\n{\n    int idx;\n    X509_PURPOSE *ptmp;\n    flags &= ~X509_PURPOSE_DYNAMIC;\n    flags |= X509_PURPOSE_DYNAMIC_NAME;\n    idx = X509_PURPOSE_get_by_id(id);\n    if (idx == -1) {\n        if ((ptmp = OPENSSL_malloc(sizeof(*ptmp))) == NULL) {\n            X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);\n            return 0;\n        }\n        ptmp->flags = X509_PURPOSE_DYNAMIC;\n    } else\n        ptmp = X509_PURPOSE_get0(idx);\n    if (ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {\n        OPENSSL_free(ptmp->name);\n        OPENSSL_free(ptmp->sname);\n    }\n    ptmp->name = OPENSSL_strdup(name);\n    ptmp->sname = OPENSSL_strdup(sname);\n    if (!ptmp->name || !ptmp->sname) {\n        X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    ptmp->flags &= X509_PURPOSE_DYNAMIC;\n    ptmp->flags |= flags;\n    ptmp->purpose = id;\n    ptmp->trust = trust;\n    ptmp->check_purpose = ck;\n    ptmp->usr_data = arg;\n    if (idx == -1) {\n        if (xptable == NULL\n            && (xptable = sk_X509_PURPOSE_new(xp_cmp)) == NULL) {\n            X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        if (!sk_X509_PURPOSE_push(xptable, ptmp)) {\n            X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n    }\n    return 1;\n err:\n    if (idx == -1) {\n        OPENSSL_free(ptmp->name);\n        OPENSSL_free(ptmp->sname);\n        OPENSSL_free(ptmp);\n    }\n    return 0;\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n    X509_PURPOSE tmp;\n    int idx;\n    if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n        return purpose - X509_PURPOSE_MIN;\n    tmp.purpose = purpose;\n    if (!xptable)\n        return -1;\n    idx = sk_X509_PURPOSE_find(xptable, &tmp);\n    if (idx == -1)\n        return -1;\n    return idx + X509_PURPOSE_COUNT;\n}', 'DEFINE_STACK_OF(X509_PURPOSE)', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n    return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n                         int ret_val_options)\n{\n    const void *r;\n    int i;\n    if (st == NULL)\n        return -1;\n    if (st->comp == NULL) {\n        for (i = 0; i < st->num; i++)\n            if (st->data[i] == data)\n                return (i);\n        return (-1);\n    }\n    OPENSSL_sk_sort(st);\n    if (data == NULL)\n        return (-1);\n    r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n                        ret_val_options);\n    if (r == NULL)\n        return (-1);\n    return (int)((const void **)r - st->data);\n}', 'X509_PURPOSE *X509_PURPOSE_get0(int idx)\n{\n    if (idx < 0)\n        return NULL;\n    if (idx < (int)X509_PURPOSE_COUNT)\n        return xstandard + idx;\n    return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']