crypto/x509v3/v3_purp.c:93: error: NULL_DEREFERENCE
  pointer `pt` last assigned on line 92 could be null and is dereferenced at line 93, column 12.
Showing all 45 steps of the trace


crypto/x509v3/v3_purp.c:77:1: start of procedure X509_check_purpose()
75.    * things.
76.    */
77. > int X509_check_purpose(X509 *x, int id, int ca)
78.   {
79.       int idx;

crypto/x509v3/v3_purp.c:81:11: Taking true branch
79.       int idx;
80.       const X509_PURPOSE *pt;
81.       if (!(x->ex_flags & EXFLAG_SET)) {
                ^
82.           CRYPTO_THREAD_write_lock(x->lock);
83.           x509v3_cache_extensions(x);

crypto/x509v3/v3_purp.c:82:9: 
80.       const X509_PURPOSE *pt;
81.       if (!(x->ex_flags & EXFLAG_SET)) {
82. >         CRYPTO_THREAD_write_lock(x->lock);
83.           x509v3_cache_extensions(x);
84.           CRYPTO_THREAD_unlock(x->lock);

crypto/threads_pthread.c:64:1: start of procedure CRYPTO_THREAD_write_lock()
  62.   }
  63.   
  64. > int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
  65.   {
  66.   # ifdef USE_RWLOCK

crypto/threads_pthread.c:67:9: Taking true branch
  65.   {
  66.   # ifdef USE_RWLOCK
  67.       if (pthread_rwlock_wrlock(lock) != 0)
                ^
  68.           return 0;
  69.   # else

crypto/threads_pthread.c:68:9: 
  66.   # ifdef USE_RWLOCK
  67.       if (pthread_rwlock_wrlock(lock) != 0)
  68. >         return 0;
  69.   # else
  70.       if (pthread_mutex_lock(lock) != 0)

crypto/threads_pthread.c:75:1: return from a call to CRYPTO_THREAD_write_lock
  73.   
  74.       return 1;
  75. > }
  76.   
  77.   int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)

crypto/x509v3/v3_purp.c:83:9: Skipping x509v3_cache_extensions(): empty list of specs
81.       if (!(x->ex_flags & EXFLAG_SET)) {
82.           CRYPTO_THREAD_write_lock(x->lock);
83.           x509v3_cache_extensions(x);
              ^
84.           CRYPTO_THREAD_unlock(x->lock);
85.       }

crypto/x509v3/v3_purp.c:84:9: 
82.           CRYPTO_THREAD_write_lock(x->lock);
83.           x509v3_cache_extensions(x);
84. >         CRYPTO_THREAD_unlock(x->lock);
85.       }
86.       /* Return if side-effect only call */

crypto/threads_pthread.c:77:1: start of procedure CRYPTO_THREAD_unlock()
  75.   }
  76.   
  77. > int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
  78.   {
  79.   # ifdef USE_RWLOCK

crypto/threads_pthread.c:80:9: Taking true branch
  78.   {
  79.   # ifdef USE_RWLOCK
  80.       if (pthread_rwlock_unlock(lock) != 0)
                ^
  81.           return 0;
  82.   # else

crypto/threads_pthread.c:81:9: 
  79.   # ifdef USE_RWLOCK
  80.       if (pthread_rwlock_unlock(lock) != 0)
  81. >         return 0;
  82.   # else
  83.       if (pthread_mutex_unlock(lock) != 0)

crypto/threads_pthread.c:88:1: return from a call to CRYPTO_THREAD_unlock
  86.   
  87.       return 1;
  88. > }
  89.   
  90.   void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock)

crypto/x509v3/v3_purp.c:87:9: Taking false branch
85.       }
86.       /* Return if side-effect only call */
87.       if (id == -1)
              ^
88.           return 1;
89.       idx = X509_PURPOSE_get_by_id(id);

crypto/x509v3/v3_purp.c:89:5: 
87.       if (id == -1)
88.           return 1;
89. >     idx = X509_PURPOSE_get_by_id(id);
90.       if (idx == -1)
91.           return -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:297:1: start of procedure OPENSSL_sk_find()
      295.   }
      296.   
      297. > int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      298.   {
      299.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);

crypto/stack/stack.c:299:5: 
      297.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)
      298.   {
      299. >     return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      300.   }
      301.   

crypto/stack/stack.c:272:1: start of procedure internal_find()
        270.   }
        271.   
        272. > static int internal_find(OPENSSL_STACK *st, const void *data,
        273.                            int ret_val_options)
        274.   {

crypto/stack/stack.c:278:9: Taking false branch
        276.       int i;
        277.   
        278.       if (st == NULL || st->num == 0)
                       ^
        279.           return -1;
        280.   

crypto/stack/stack.c:278:23: Taking false branch
        276.       int i;
        277.   
        278.       if (st == NULL || st->num == 0)
                                     ^
        279.           return -1;
        280.   

crypto/stack/stack.c:281:9: Taking true branch
        279.           return -1;
        280.   
        281.       if (st->comp == NULL) {
                       ^
        282.           for (i = 0; i < st->num; i++)
        283.               if (st->data[i] == data)

crypto/stack/stack.c:282:14: 
        280.   
        281.       if (st->comp == NULL) {
        282. >         for (i = 0; i < st->num; i++)
        283.               if (st->data[i] == data)
        284.                   return (i);

crypto/stack/stack.c:282:21: Loop condition is true. Entering loop body
        280.   
        281.       if (st->comp == NULL) {
        282.           for (i = 0; i < st->num; i++)
                                   ^
        283.               if (st->data[i] == data)
        284.                   return (i);

crypto/stack/stack.c:283:17: Taking true branch
        281.       if (st->comp == NULL) {
        282.           for (i = 0; i < st->num; i++)
        283.               if (st->data[i] == data)
                               ^
        284.                   return (i);
        285.           return (-1);

crypto/stack/stack.c:284:17: 
        282.           for (i = 0; i < st->num; i++)
        283.               if (st->data[i] == data)
        284. >                 return (i);
        285.           return (-1);
        286.       }

crypto/stack/stack.c:295:1: return from a call to internal_find
        293.           return (-1);
        294.       return (int)((const void **)r - st->data);
        295. > }
        296.   
        297.   int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)

crypto/stack/stack.c:300:1: return from a call to OPENSSL_sk_find
      298.   {
      299.       return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);
      300. > }
      301.   
      302.   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:90:9: Taking false branch
88.           return 1;
89.       idx = X509_PURPOSE_get_by_id(id);
90.       if (idx == -1)
              ^
91.           return -1;
92.       pt = X509_PURPOSE_get0(idx);

crypto/x509v3/v3_purp.c:92:5: 
90.       if (idx == -1)
91.           return -1;
92. >     pt = X509_PURPOSE_get0(idx);
93.       return pt->check_purpose(pt, x, ca);
94.   }

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:93:5: 
91.           return -1;
92.       pt = X509_PURPOSE_get0(idx);
93. >     return pt->check_purpose(pt, x, ca);
94.   }
95.   

int X509_check_purpose(X509 *x, int id, int ca)
{
    int idx;
    const X509_PURPOSE *pt;
    if (!(x->ex_flags & EXFLAG_SET)) {
        CRYPTO_THREAD_write_lock(x->lock);
        x509v3_cache_extensions(x);
        CRYPTO_THREAD_unlock(x->lock);
    }
    if (id == -1)
        return 1;
    idx = X509_PURPOSE_get_by_id(id);
    if (idx == -1)
        return -1;
    pt = X509_PURPOSE_get0(idx);
    return pt->check_purpose(pt, x, ca);
}
['int X509_check_purpose(X509 *x, int id, int ca)\n{\n    int idx;\n    const X509_PURPOSE *pt;\n    if (!(x->ex_flags & EXFLAG_SET)) {\n        CRYPTO_THREAD_write_lock(x->lock);\n        x509v3_cache_extensions(x);\n        CRYPTO_THREAD_unlock(x->lock);\n    }\n    if (id == -1)\n        return 1;\n    idx = X509_PURPOSE_get_by_id(id);\n    if (idx == -1)\n        return -1;\n    pt = X509_PURPOSE_get0(idx);\n    return pt->check_purpose(pt, x, ca);\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n    if (pthread_rwlock_wrlock(lock) != 0)\n        return 0;\n# else\n    if (pthread_mutex_lock(lock) != 0)\n        return 0;\n# endif\n    return 1;\n}', 'int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n    if (pthread_rwlock_unlock(lock) != 0)\n        return 0;\n# else\n    if (pthread_mutex_unlock(lock) != 0)\n        return 0;\n# endif\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    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}']