crypto/x509/x509_lu.c:520: error: NULL_DEREFERENCE
  pointer `obj` last assigned on line 519 could be null and is dereferenced at line 520, column 13.
Showing all 25 steps of the trace


crypto/x509/x509_lu.c:485:1: start of procedure X509_STORE_CTX_get1_certs()
483.   }
484.   
485. > STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm)
486.   {
487.       int i, idx, cnt;

crypto/x509/x509_lu.c:488:5: 
486.   {
487.       int i, idx, cnt;
488. >     STACK_OF(X509) *sk = NULL;
489.       X509 *x;
490.       X509_OBJECT *obj;

crypto/x509/x509_lu.c:492:5: 
490.       X509_OBJECT *obj;
491.   
492. >     CRYPTO_THREAD_write_lock(ctx->ctx->lock);
493.       idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
494.       if (idx < 0) {

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

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

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

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

crypto/x509/x509_lu.c:493:5: Skipping x509_object_idx_cnt(): empty list of specs
491.   
492.       CRYPTO_THREAD_write_lock(ctx->ctx->lock);
493.       idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
           ^
494.       if (idx < 0) {
495.           /*

crypto/x509/x509_lu.c:494:9: Taking false branch
492.       CRYPTO_THREAD_write_lock(ctx->ctx->lock);
493.       idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
494.       if (idx < 0) {
               ^
495.           /*
496.            * Nothing found in cache: do lookup to possibly add new objects to

crypto/x509/x509_lu.c:517:5: 
515.       }
516.   
517. >     sk = sk_X509_new_null();
518.       for (i = 0; i < cnt; i++, idx++) {
519.           obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);

include/openssl/x509.h:97:1: start of procedure sk_X509_new_null()
  95.   typedef struct x509_cinf_st X509_CINF;
  96.   
  97. > DEFINE_STACK_OF(X509)
  98.   
  99.   /* This is used for a table of trust checking functions */

crypto/stack/stack.c:99:1: start of procedure OPENSSL_sk_new_null()
    97.   }
    98.   
    99. > OPENSSL_STACK *OPENSSL_sk_new_null(void)
    100.   {
    101.       return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);

crypto/stack/stack.c:101:5: Skipping OPENSSL_sk_new(): empty list of specs
    99.   OPENSSL_STACK *OPENSSL_sk_new_null(void)
    100.   {
    101.       return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);
               ^
    102.   }
    103.   

crypto/stack/stack.c:102:1: return from a call to OPENSSL_sk_new_null
    100.   {
    101.       return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);
    102. > }
    103.   
    104.   OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)

include/openssl/x509.h:97:1: return from a call to sk_X509_new_null
  95.   typedef struct x509_cinf_st X509_CINF;
  96.   
  97. > DEFINE_STACK_OF(X509)
  98.   
  99.   /* This is used for a table of trust checking functions */

crypto/x509/x509_lu.c:518:10: 
516.   
517.       sk = sk_X509_new_null();
518. >     for (i = 0; i < cnt; i++, idx++) {
519.           obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
520.           x = obj->data.x509;

crypto/x509/x509_lu.c:518:17: Loop condition is true. Entering loop body
516.   
517.       sk = sk_X509_new_null();
518.       for (i = 0; i < cnt; i++, idx++) {
                       ^
519.           obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
520.           x = obj->data.x509;

crypto/x509/x509_lu.c:519:9: 
517.       sk = sk_X509_new_null();
518.       for (i = 0; i < cnt; i++, idx++) {
519. >         obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
520.           x = obj->data.x509;
521.           X509_up_ref(x);

include/openssl/x509_vfy.h:58:1: start of procedure sk_X509_OBJECT_value()
  56.   
  57.   DEFINE_STACK_OF(X509_LOOKUP)
  58. > DEFINE_STACK_OF(X509_OBJECT)
  59.   DEFINE_STACK_OF(X509_VERIFY_PARAM)
  60.   

crypto/stack/stack.c:284:1: start of procedure OPENSSL_sk_value()
    282.   }
    283.   
    284. > void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)

crypto/stack/stack.c:286:9: Taking true branch
    284.   void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)
                   ^
    287.           return NULL;
    288.       return (void *)st->data[i];

crypto/stack/stack.c:287:9: 
    285.   {
    286.       if (st == NULL || i < 0 || i >= st->num)
    287. >         return NULL;
    288.       return (void *)st->data[i];
    289.   }

crypto/stack/stack.c:289:1: return from a call to OPENSSL_sk_value
    287.           return NULL;
    288.       return (void *)st->data[i];
    289. > }
    290.   
    291.   void *OPENSSL_sk_set(OPENSSL_STACK *st, int i, const void *data)

include/openssl/x509_vfy.h:58:1: return from a call to sk_X509_OBJECT_value
  56.   
  57.   DEFINE_STACK_OF(X509_LOOKUP)
  58. > DEFINE_STACK_OF(X509_OBJECT)
  59.   DEFINE_STACK_OF(X509_VERIFY_PARAM)
  60.   

crypto/x509/x509_lu.c:520:9: 
518.       for (i = 0; i < cnt; i++, idx++) {
519.           obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
520. >         x = obj->data.x509;
521.           X509_up_ref(x);
522.           if (!sk_X509_push(sk, x)) {

STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm)
{
    int i, idx, cnt;
    STACK_OF(X509) *sk = NULL;
    X509 *x;
    X509_OBJECT *obj;
    CRYPTO_THREAD_write_lock(ctx->ctx->lock);
    idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
    if (idx < 0) {
        X509_OBJECT *xobj = X509_OBJECT_new();
        CRYPTO_THREAD_unlock(ctx->ctx->lock);
        if (xobj == NULL)
            return NULL;
        if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509, nm, xobj)) {
            X509_OBJECT_free(xobj);
            return NULL;
        }
        X509_OBJECT_free(xobj);
        CRYPTO_THREAD_write_lock(ctx->ctx->lock);
        idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
        if (idx < 0) {
            CRYPTO_THREAD_unlock(ctx->ctx->lock);
            return NULL;
        }
    }
    sk = sk_X509_new_null();
    for (i = 0; i < cnt; i++, idx++) {
        obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
        x = obj->data.x509;
        X509_up_ref(x);
        if (!sk_X509_push(sk, x)) {
            CRYPTO_THREAD_unlock(ctx->ctx->lock);
            X509_free(x);
            sk_X509_pop_free(sk, X509_free);
            return NULL;
        }
    }
    CRYPTO_THREAD_unlock(ctx->ctx->lock);
    return sk;
}
['STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm)\n{\n    int i, idx, cnt;\n    STACK_OF(X509) *sk = NULL;\n    X509 *x;\n    X509_OBJECT *obj;\n    CRYPTO_THREAD_write_lock(ctx->ctx->lock);\n    idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);\n    if (idx < 0) {\n        X509_OBJECT *xobj = X509_OBJECT_new();\n        CRYPTO_THREAD_unlock(ctx->ctx->lock);\n        if (xobj == NULL)\n            return NULL;\n        if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509, nm, xobj)) {\n            X509_OBJECT_free(xobj);\n            return NULL;\n        }\n        X509_OBJECT_free(xobj);\n        CRYPTO_THREAD_write_lock(ctx->ctx->lock);\n        idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);\n        if (idx < 0) {\n            CRYPTO_THREAD_unlock(ctx->ctx->lock);\n            return NULL;\n        }\n    }\n    sk = sk_X509_new_null();\n    for (i = 0; i < cnt; i++, idx++) {\n        obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);\n        x = obj->data.x509;\n        X509_up_ref(x);\n        if (!sk_X509_push(sk, x)) {\n            CRYPTO_THREAD_unlock(ctx->ctx->lock);\n            X509_free(x);\n            sk_X509_pop_free(sk, X509_free);\n            return NULL;\n        }\n    }\n    CRYPTO_THREAD_unlock(ctx->ctx->lock);\n    return sk;\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}', 'DEFINE_STACK_OF(X509)', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n    return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n    if (st == NULL || i < 0 || i >= st->num)\n        return NULL;\n    return (void *)st->data[i];\n}']