crypto/x509/x509_vfy.c:2086: error: NULL_DEREFERENCE
  pointer `ptmp` last assigned on line 2085 could be null and is dereferenced at line 2086, column 13.
Showing all 33 steps of the trace


crypto/x509/x509_vfy.c:2069:1: start of procedure X509_STORE_CTX_purpose_inherit()
2067.    */
2068.   
2069. > int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2070.                                      int purpose, int trust)
2071.   {

crypto/x509/x509_vfy.c:2074:10: Taking false branch
2072.       int idx;
2073.       /* If purpose not set use default */
2074.       if (!purpose)
                 ^
2075.           purpose = def_purpose;
2076.       /* If we have a purpose then check it is valid */

crypto/x509/x509_vfy.c:2077:9: Taking true branch
2075.           purpose = def_purpose;
2076.       /* If we have a purpose then check it is valid */
2077.       if (purpose) {
                ^
2078.           X509_PURPOSE *ptmp;
2079.           idx = X509_PURPOSE_get_by_id(purpose);

crypto/x509/x509_vfy.c:2079:9: 
2077.       if (purpose) {
2078.           X509_PURPOSE *ptmp;
2079. >         idx = X509_PURPOSE_get_by_id(purpose);
2080.           if (idx == -1) {
2081.               X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,

crypto/x509v3/v3_purp.c:183:1: start of procedure X509_PURPOSE_get_by_id()
  181.   }
  182.   
  183. > int X509_PURPOSE_get_by_id(int purpose)
  184.   {
  185.       X509_PURPOSE tmp;

crypto/x509v3/v3_purp.c:187:10: Taking true branch
  185.       X509_PURPOSE tmp;
  186.       int idx;
  187.       if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
                  ^
  188.           return purpose - X509_PURPOSE_MIN;
  189.       tmp.purpose = purpose;

crypto/x509v3/v3_purp.c:187:43: Taking false branch
  185.       X509_PURPOSE tmp;
  186.       int idx;
  187.       if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
                                                   ^
  188.           return purpose - X509_PURPOSE_MIN;
  189.       tmp.purpose = purpose;

crypto/x509v3/v3_purp.c:189:5: 
  187.       if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))
  188.           return purpose - X509_PURPOSE_MIN;
  189. >     tmp.purpose = purpose;
  190.       if (!xptable)
  191.           return -1;

crypto/x509v3/v3_purp.c:190:10: Taking false branch
  188.           return purpose - X509_PURPOSE_MIN;
  189.       tmp.purpose = purpose;
  190.       if (!xptable)
                  ^
  191.           return -1;
  192.       idx = sk_X509_PURPOSE_find(xptable, &tmp);

crypto/x509v3/v3_purp.c:192:5: 
  190.       if (!xptable)
  191.           return -1;
  192. >     idx = sk_X509_PURPOSE_find(xptable, &tmp);
  193.       if (idx == -1)
  194.           return -1;

include/openssl/x509v3.h:499:1: start of procedure sk_X509_PURPOSE_find()
    497.   # define X509V3_ADD_SILENT               0x10
    498.   
    499. > DEFINE_STACK_OF(X509_PURPOSE)
    500.   
    501.   DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)

crypto/stack/stack.c:248:1: start of procedure sk_find()
      246.   }
      247.   
      248. > int sk_find(_STACK *st, void *data)
      249.   {
      250.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:250:5: 
      248.   int sk_find(_STACK *st, void *data)
      249.   {
      250. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      251.   }
      252.   

crypto/stack/stack.c:224:1: start of procedure internal_find()
        222.   }
        223.   
        224. > static int internal_find(_STACK *st, void *data, int ret_val_options)
        225.   {
        226.       const void *const *r;

crypto/stack/stack.c:229:9: Taking false branch
        227.       int i;
        228.   
        229.       if (st == NULL)
                       ^
        230.           return -1;
        231.   

crypto/stack/stack.c:232:9: Taking true branch
        230.           return -1;
        231.   
        232.       if (st->comp == NULL) {
                       ^
        233.           for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)

crypto/stack/stack.c:233:14: 
        231.   
        232.       if (st->comp == NULL) {
        233. >         for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)
        235.                   return (i);

crypto/stack/stack.c:233:21: Loop condition is true. Entering loop body
        231.   
        232.       if (st->comp == NULL) {
        233.           for (i = 0; i < st->num; i++)
                                   ^
        234.               if (st->data[i] == data)
        235.                   return (i);

crypto/stack/stack.c:234:17: Taking true branch
        232.       if (st->comp == NULL) {
        233.           for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)
                               ^
        235.                   return (i);
        236.           return (-1);

crypto/stack/stack.c:235:17: 
        233.           for (i = 0; i < st->num; i++)
        234.               if (st->data[i] == data)
        235. >                 return (i);
        236.           return (-1);
        237.       }

crypto/stack/stack.c:246:1: return from a call to internal_find
        244.           return (-1);
        245.       return (int)((char **)r - st->data);
        246. > }
        247.   
        248.   int sk_find(_STACK *st, void *data)

crypto/stack/stack.c:251:1: return from a call to sk_find
      249.   {
      250.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      251. > }
      252.   
      253.   int sk_find_ex(_STACK *st, void *data)

include/openssl/x509v3.h:499:1: return from a call to sk_X509_PURPOSE_find
    497.   # define X509V3_ADD_SILENT               0x10
    498.   
    499. > DEFINE_STACK_OF(X509_PURPOSE)
    500.   
    501.   DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)

crypto/x509v3/v3_purp.c:193:9: Taking false branch
  191.           return -1;
  192.       idx = sk_X509_PURPOSE_find(xptable, &tmp);
  193.       if (idx == -1)
                 ^
  194.           return -1;
  195.       return idx + X509_PURPOSE_COUNT;

crypto/x509v3/v3_purp.c:195:5: 
  193.       if (idx == -1)
  194.           return -1;
  195. >     return idx + X509_PURPOSE_COUNT;
  196.   }
  197.   

crypto/x509v3/v3_purp.c:196:1: return from a call to X509_PURPOSE_get_by_id
  194.           return -1;
  195.       return idx + X509_PURPOSE_COUNT;
  196. > }
  197.   
  198.   int X509_PURPOSE_add(int id, int trust, int flags,

crypto/x509/x509_vfy.c:2080:13: Taking false branch
2078.           X509_PURPOSE *ptmp;
2079.           idx = X509_PURPOSE_get_by_id(purpose);
2080.           if (idx == -1) {
                    ^
2081.               X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
2082.                       X509_R_UNKNOWN_PURPOSE_ID);

crypto/x509/x509_vfy.c:2085:9: 
2083.               return 0;
2084.           }
2085. >         ptmp = X509_PURPOSE_get0(idx);
2086.           if (ptmp->trust == X509_TRUST_DEFAULT) {
2087.               idx = X509_PURPOSE_get_by_id(def_purpose);

crypto/x509v3/v3_purp.c:162:1: start of procedure X509_PURPOSE_get0()
  160.   }
  161.   
  162. > X509_PURPOSE *X509_PURPOSE_get0(int idx)
  163.   {
  164.       if (idx < 0)

crypto/x509v3/v3_purp.c:164:9: Taking true branch
  162.   X509_PURPOSE *X509_PURPOSE_get0(int idx)
  163.   {
  164.       if (idx < 0)
                 ^
  165.           return NULL;
  166.       if (idx < (int)X509_PURPOSE_COUNT)

crypto/x509v3/v3_purp.c:165:9: 
  163.   {
  164.       if (idx < 0)
  165. >         return NULL;
  166.       if (idx < (int)X509_PURPOSE_COUNT)
  167.           return xstandard + idx;

crypto/x509v3/v3_purp.c:169:1: return from a call to X509_PURPOSE_get0
  167.           return xstandard + idx;
  168.       return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
  169. > }
  170.   
  171.   int X509_PURPOSE_get_by_sname(char *sname)

crypto/x509/x509_vfy.c:2086:13: 
2084.           }
2085.           ptmp = X509_PURPOSE_get0(idx);
2086. >         if (ptmp->trust == X509_TRUST_DEFAULT) {
2087.               idx = X509_PURPOSE_get_by_id(def_purpose);
2088.               /*

int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
                                   int purpose, int trust)
{
    int idx;
    if (!purpose)
        purpose = def_purpose;
    if (purpose) {
        X509_PURPOSE *ptmp;
        idx = X509_PURPOSE_get_by_id(purpose);
        if (idx == -1) {
            X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
                    X509_R_UNKNOWN_PURPOSE_ID);
            return 0;
        }
        ptmp = X509_PURPOSE_get0(idx);
        if (ptmp->trust == X509_TRUST_DEFAULT) {
            idx = X509_PURPOSE_get_by_id(def_purpose);
            if (idx == -1) {
                X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
                        X509_R_UNKNOWN_PURPOSE_ID);
                return 0;
            }
            ptmp = X509_PURPOSE_get0(idx);
        }
        if (!trust)
            trust = ptmp->trust;
    }
    if (trust) {
        idx = X509_TRUST_get_by_id(trust);
        if (idx == -1) {
            X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
                    X509_R_UNKNOWN_TRUST_ID);
            return 0;
        }
    }
    if (purpose && !ctx->param->purpose)
        ctx->param->purpose = purpose;
    if (trust && !ctx->param->trust)
        ctx->param->trust = trust;
    return 1;
}
['int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,\n                                   int purpose, int trust)\n{\n    int idx;\n    if (!purpose)\n        purpose = def_purpose;\n    if (purpose) {\n        X509_PURPOSE *ptmp;\n        idx = X509_PURPOSE_get_by_id(purpose);\n        if (idx == -1) {\n            X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,\n                    X509_R_UNKNOWN_PURPOSE_ID);\n            return 0;\n        }\n        ptmp = X509_PURPOSE_get0(idx);\n        if (ptmp->trust == X509_TRUST_DEFAULT) {\n            idx = X509_PURPOSE_get_by_id(def_purpose);\n            if (idx == -1) {\n                X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,\n                        X509_R_UNKNOWN_PURPOSE_ID);\n                return 0;\n            }\n            ptmp = X509_PURPOSE_get0(idx);\n        }\n        if (!trust)\n            trust = ptmp->trust;\n    }\n    if (trust) {\n        idx = X509_TRUST_get_by_id(trust);\n        if (idx == -1) {\n            X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,\n                    X509_R_UNKNOWN_TRUST_ID);\n            return 0;\n        }\n    }\n    if (purpose && !ctx->param->purpose)\n        ctx->param->purpose = purpose;\n    if (trust && !ctx->param->trust)\n        ctx->param->trust = trust;\n    return 1;\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 sk_find(_STACK *st, void *data)\n{\n    return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(_STACK *st, void *data, int ret_val_options)\n{\n    const void *const *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    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)((char **)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}']