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


crypto/x509/x509_vfy.c:2146:1: start of procedure X509_STORE_CTX_purpose_inherit()
2144.    */
2145.   
2146. > int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2147.                                      int purpose, int trust)
2148.   {

crypto/x509/x509_vfy.c:2151:10: Taking false branch
2149.       int idx;
2150.       /* If purpose not set use default */
2151.       if (!purpose)
                 ^
2152.           purpose = def_purpose;
2153.       /* If we have a purpose then check it is valid */

crypto/x509/x509_vfy.c:2154:9: Taking true branch
2152.           purpose = def_purpose;
2153.       /* If we have a purpose then check it is valid */
2154.       if (purpose) {
                ^
2155.           X509_PURPOSE *ptmp;
2156.           idx = X509_PURPOSE_get_by_id(purpose);

crypto/x509/x509_vfy.c:2156:9: 
2154.       if (purpose) {
2155.           X509_PURPOSE *ptmp;
2156. >         idx = X509_PURPOSE_get_by_id(purpose);
2157.           if (idx == -1) {
2158.               X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,

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:197:1: start of procedure OPENSSL_sk_find()
      195.   }
      196.   
      197. > int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      198.   {
      199.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:199:5: 
      197.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      198.   {
      199. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      200.   }
      201.   

crypto/stack/stack.c:172:1: start of procedure internal_find()
        170.   }
        171.   
        172. > static int internal_find(OPENSSL_STACK *st, const void *data,
        173.                            int ret_val_options)
        174.   {

crypto/stack/stack.c:178:9: Taking false branch
        176.       int i;
        177.   
        178.       if (st == NULL)
                       ^
        179.           return -1;
        180.   

crypto/stack/stack.c:181:9: Taking true branch
        179.           return -1;
        180.   
        181.       if (st->comp == NULL) {
                       ^
        182.           for (i = 0; i < st->num; i++)
        183.               if (st->data[i] == data)

crypto/stack/stack.c:182:14: 
        180.   
        181.       if (st->comp == NULL) {
        182. >         for (i = 0; i < st->num; i++)
        183.               if (st->data[i] == data)
        184.                   return (i);

crypto/stack/stack.c:182:21: Loop condition is true. Entering loop body
        180.   
        181.       if (st->comp == NULL) {
        182.           for (i = 0; i < st->num; i++)
                                   ^
        183.               if (st->data[i] == data)
        184.                   return (i);

crypto/stack/stack.c:183:17: Taking false branch
        181.       if (st->comp == NULL) {
        182.           for (i = 0; i < st->num; i++)
        183.               if (st->data[i] == data)
                               ^
        184.                   return (i);
        185.           return (-1);

crypto/stack/stack.c:182:34: 
        180.   
        181.       if (st->comp == NULL) {
        182. >         for (i = 0; i < st->num; i++)
        183.               if (st->data[i] == data)
        184.                   return (i);

crypto/stack/stack.c:182:21: Loop condition is true. Entering loop body
        180.   
        181.       if (st->comp == NULL) {
        182.           for (i = 0; i < st->num; i++)
                                   ^
        183.               if (st->data[i] == data)
        184.                   return (i);

crypto/stack/stack.c:183:17: Taking true branch
        181.       if (st->comp == NULL) {
        182.           for (i = 0; i < st->num; i++)
        183.               if (st->data[i] == data)
                               ^
        184.                   return (i);
        185.           return (-1);

crypto/stack/stack.c:184:17: 
        182.           for (i = 0; i < st->num; i++)
        183.               if (st->data[i] == data)
        184. >                 return (i);
        185.           return (-1);
        186.       }

crypto/stack/stack.c:195:1: return from a call to internal_find
        193.           return (-1);
        194.       return (int)((char **)r - st->data);
        195. > }
        196.   
        197.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)

crypto/stack/stack.c:200:1: return from a call to OPENSSL_sk_find
      198.   {
      199.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      200. > }
      201.   
      202.   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/x509/x509_vfy.c:2157:13: Taking false branch
2155.           X509_PURPOSE *ptmp;
2156.           idx = X509_PURPOSE_get_by_id(purpose);
2157.           if (idx == -1) {
                    ^
2158.               X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,
2159.                       X509_R_UNKNOWN_PURPOSE_ID);

crypto/x509/x509_vfy.c:2162:9: 
2160.               return 0;
2161.           }
2162. >         ptmp = X509_PURPOSE_get0(idx);
2163.           if (ptmp->trust == X509_TRUST_DEFAULT) {
2164.               idx = X509_PURPOSE_get_by_id(def_purpose);

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/x509/x509_vfy.c:2163:13: 
2161.           }
2162.           ptmp = X509_PURPOSE_get0(idx);
2163. >         if (ptmp->trust == X509_TRUST_DEFAULT) {
2164.               idx = X509_PURPOSE_get_by_id(def_purpose);
2165.               /*

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 *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    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)((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}']