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


crypto/x509/x509_vfy.c:2129:1: start of procedure X509_STORE_CTX_purpose_inherit()
2127.    */
2128.   
2129. > int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2130.                                      int purpose, int trust)
2131.   {

crypto/x509/x509_vfy.c:2134:10: Taking false branch
2132.       int idx;
2133.       /* If purpose not set use default */
2134.       if (!purpose)
                 ^
2135.           purpose = def_purpose;
2136.       /* If we have a purpose then check it is valid */

crypto/x509/x509_vfy.c:2137:9: Taking true branch
2135.           purpose = def_purpose;
2136.       /* If we have a purpose then check it is valid */
2137.       if (purpose) {
                ^
2138.           X509_PURPOSE *ptmp;
2139.           idx = X509_PURPOSE_get_by_id(purpose);

crypto/x509/x509_vfy.c:2139:9: 
2137.       if (purpose) {
2138.           X509_PURPOSE *ptmp;
2139. >         idx = X509_PURPOSE_get_by_id(purpose);
2140.           if (idx == -1) {
2141.               X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,

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

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

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

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

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

crypto/x509v3/v3_purp.c:141:5: 
  139.       if (!xptable)
  140.           return -1;
  141. >     idx = sk_X509_PURPOSE_find(xptable, &tmp);
  142.       if (idx == -1)
  143.           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:316:1: start of procedure OPENSSL_sk_find()
      314.   }
      315.   
      316. > int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      317.   {
      318.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:318:5: 
      316.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      317.   {
      318. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      319.   }
      320.   

crypto/stack/stack.c:287:1: start of procedure internal_find()
        285.   }
        286.   
        287. > static int internal_find(OPENSSL_STACK *st, const void *data,
        288.                            int ret_val_options)
        289.   {

crypto/stack/stack.c:293:9: Taking false branch
        291.       int i;
        292.   
        293.       if (st == NULL || st->num == 0)
                       ^
        294.           return -1;
        295.   

crypto/stack/stack.c:293:23: Taking false branch
        291.       int i;
        292.   
        293.       if (st == NULL || st->num == 0)
                                     ^
        294.           return -1;
        295.   

crypto/stack/stack.c:296:9: Taking true branch
        294.           return -1;
        295.   
        296.       if (st->comp == NULL) {
                       ^
        297.           for (i = 0; i < st->num; i++)
        298.               if (st->data[i] == data)

crypto/stack/stack.c:297:14: 
        295.   
        296.       if (st->comp == NULL) {
        297. >         for (i = 0; i < st->num; i++)
        298.               if (st->data[i] == data)
        299.                   return i;

crypto/stack/stack.c:297:21: Loop condition is true. Entering loop body
        295.   
        296.       if (st->comp == NULL) {
        297.           for (i = 0; i < st->num; i++)
                                   ^
        298.               if (st->data[i] == data)
        299.                   return i;

crypto/stack/stack.c:298:17: Taking true branch
        296.       if (st->comp == NULL) {
        297.           for (i = 0; i < st->num; i++)
        298.               if (st->data[i] == data)
                               ^
        299.                   return i;
        300.           return -1;

crypto/stack/stack.c:299:17: 
        297.           for (i = 0; i < st->num; i++)
        298.               if (st->data[i] == data)
        299. >                 return i;
        300.           return -1;
        301.       }

crypto/stack/stack.c:314:1: return from a call to internal_find
        312.   
        313.       return r == NULL ? -1 : (int)((const void **)r - st->data);
        314. > }
        315.   
        316.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)

crypto/stack/stack.c:319:1: return from a call to OPENSSL_sk_find
      317.   {
      318.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      319. > }
      320.   
      321.   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:142:9: Taking false branch
  140.           return -1;
  141.       idx = sk_X509_PURPOSE_find(xptable, &tmp);
  142.       if (idx == -1)
                 ^
  143.           return -1;
  144.       return idx + X509_PURPOSE_COUNT;

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

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

crypto/x509/x509_vfy.c:2140:13: Taking false branch
2138.           X509_PURPOSE *ptmp;
2139.           idx = X509_PURPOSE_get_by_id(purpose);
2140.           if (idx == -1) {
                    ^
2141.               X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
2142.                       X509_R_UNKNOWN_PURPOSE_ID);

crypto/x509/x509_vfy.c:2145:9: 
2143.               return 0;
2144.           }
2145. >         ptmp = X509_PURPOSE_get0(idx);
2146.           if (ptmp->trust == X509_TRUST_DEFAULT) {
2147.               idx = X509_PURPOSE_get_by_id(def_purpose);

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

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

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

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

crypto/x509/x509_vfy.c:2146:13: 
2144.           }
2145.           ptmp = X509_PURPOSE_get0(idx);
2146. >         if (ptmp->trust == X509_TRUST_DEFAULT) {
2147.               idx = X509_PURPOSE_get_by_id(def_purpose);
2148.               /*

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 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 || st->num == 0)\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    if (!st->sorted) {\n        if (st->num > 1)\n            qsort(st->data, st->num, sizeof(void *), st->comp);\n        st->sorted = 1;\n    }\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    return r == NULL ? -1 : (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}']