crypto/initthread.c:347: error: NULL_DEREFERENCE
  pointer `local` last assigned on line 334 could be null and is dereferenced by call to `init_get_thread_local()` at line 347, column 13.
Showing all 17 steps of the trace


crypto/initthread.c:321:1: start of procedure ossl_init_thread_start()
319.   }
320.   
321. > int ossl_init_thread_start(const void *index, void *arg,
322.                              OSSL_thread_stop_handler_fn handfn)
323.   {

crypto/initthread.c:327:5: 
325.       THREAD_EVENT_HANDLER *hand;
326.   #ifdef FIPS_MODE
327. >     OPENSSL_CTX *ctx = arg;
328.   
329.       /*

crypto/initthread.c:334:5: 
332.        * gets informed about thread stop events individually.
333.        */
334. >     CRYPTO_THREAD_LOCAL *local
335.           = openssl_ctx_get_data(ctx, OPENSSL_CTX_THREAD_EVENT_HANDLER_INDEX,
336.                                  &thread_event_ossl_ctx_method);

crypto/context.c:186:1: start of procedure openssl_ctx_get_data()
  184.   }
  185.   
  186. > void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,
  187.                              const OPENSSL_CTX_METHOD *meth)
  188.   {

crypto/context.c:189:5: 
  187.                              const OPENSSL_CTX_METHOD *meth)
  188.   {
  189. >     void *data = NULL;
  190.   
  191.       ctx = openssl_ctx_get_concrete(ctx);

crypto/context.c:191:5: 
  189.       void *data = NULL;
  190.   
  191. >     ctx = openssl_ctx_get_concrete(ctx);
  192.       if (ctx == NULL)
  193.           return NULL;

crypto/context.c:134:1: start of procedure openssl_ctx_get_concrete()
    132.   }
    133.   
    134. > OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)
    135.   {
    136.   #ifndef FIPS_MODE

crypto/context.c:143:5: 
    141.       }
    142.   #endif
    143. >     return ctx;
    144.   }
    145.   

crypto/context.c:144:1: return from a call to openssl_ctx_get_concrete
    142.   #endif
    143.       return ctx;
    144. > }
    145.   
    146.   static void openssl_ctx_generic_new(void *parent_ign, void *ptr_ign,

crypto/context.c:192:9: Taking true branch
  190.   
  191.       ctx = openssl_ctx_get_concrete(ctx);
  192.       if (ctx == NULL)
                 ^
  193.           return NULL;
  194.   

crypto/context.c:193:9: 
  191.       ctx = openssl_ctx_get_concrete(ctx);
  192.       if (ctx == NULL)
  193. >         return NULL;
  194.   
  195.       CRYPTO_THREAD_read_lock(ctx->lock);

crypto/context.c:211:1: return from a call to openssl_ctx_get_data
  209.   
  210.       return data;
  211. > }
  212.   
  213.   OSSL_EX_DATA_GLOBAL *openssl_ctx_get_ex_data_global(OPENSSL_CTX *ctx)

crypto/initthread.c:347:5: 
345.   #endif
346.   
347. >     hands = init_get_thread_local(local, 1, 0);
348.       if (hands == NULL)
349.           return 0;

crypto/initthread.c:88:1: start of procedure init_get_thread_local()
  86.   static void init_thread_stop(void *arg, THREAD_EVENT_HANDLER **hands);
  87.   
  88. > static THREAD_EVENT_HANDLER **
  89.   init_get_thread_local(CRYPTO_THREAD_LOCAL *local, int alloc, int keep)
  90.   {

crypto/initthread.c:91:5: 
  89.   init_get_thread_local(CRYPTO_THREAD_LOCAL *local, int alloc, int keep)
  90.   {
  91. >     THREAD_EVENT_HANDLER **hands = CRYPTO_THREAD_get_local(local);
  92.   
  93.       if (alloc) {

crypto/threads_pthread.c:127:1: start of procedure CRYPTO_THREAD_get_local()
    125.   }
    126.   
    127. > void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)
    128.   {
    129.       return pthread_getspecific(*key);

crypto/threads_pthread.c:129:5: Skipping pthread_getspecific(): method has no implementation
    127.   void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)
    128.   {
    129.       return pthread_getspecific(*key);
               ^
    130.   }
    131.   

int ossl_init_thread_start(const void *index, void *arg,
                           OSSL_thread_stop_handler_fn handfn)
{
    THREAD_EVENT_HANDLER **hands;
    THREAD_EVENT_HANDLER *hand;
#ifdef FIPS_MODE
    OPENSSL_CTX *ctx = arg;
    CRYPTO_THREAD_LOCAL *local
        = openssl_ctx_get_data(ctx, OPENSSL_CTX_THREAD_EVENT_HANDLER_INDEX,
                               &thread_event_ossl_ctx_method);
#else
    CRYPTO_THREAD_LOCAL *local = &destructor_key.value;
#endif
    hands = init_get_thread_local(local, 1, 0);
    if (hands == NULL)
        return 0;
#ifdef FIPS_MODE
    if (*hands == NULL) {
        if (!c_thread_start(FIPS_get_provider(ctx), ossl_ctx_thread_stop))
            return 0;
    }
#endif
    hand = OPENSSL_malloc(sizeof(*hand));
    if (hand == NULL)
        return 0;
    hand->handfn = handfn;
    hand->arg = arg;
    hand->index = index;
    hand->next = *hands;
    *hands = hand;
    return 1;
}
['int ossl_init_thread_start(const void *index, void *arg,\n                           OSSL_thread_stop_handler_fn handfn)\n{\n    THREAD_EVENT_HANDLER **hands;\n    THREAD_EVENT_HANDLER *hand;\n#ifdef FIPS_MODE\n    OPENSSL_CTX *ctx = arg;\n    CRYPTO_THREAD_LOCAL *local\n        = openssl_ctx_get_data(ctx, OPENSSL_CTX_THREAD_EVENT_HANDLER_INDEX,\n                               &thread_event_ossl_ctx_method);\n#else\n    CRYPTO_THREAD_LOCAL *local = &destructor_key.value;\n#endif\n    hands = init_get_thread_local(local, 1, 0);\n    if (hands == NULL)\n        return 0;\n#ifdef FIPS_MODE\n    if (*hands == NULL) {\n        if (!c_thread_start(FIPS_get_provider(ctx), ossl_ctx_thread_stop))\n            return 0;\n    }\n#endif\n    hand = OPENSSL_malloc(sizeof(*hand));\n    if (hand == NULL)\n        return 0;\n    hand->handfn = handfn;\n    hand->arg = arg;\n    hand->index = index;\n    hand->next = *hands;\n    *hands = hand;\n    return 1;\n}', 'void *openssl_ctx_get_data(OPENSSL_CTX *ctx, int index,\n                           const OPENSSL_CTX_METHOD *meth)\n{\n    void *data = NULL;\n    ctx = openssl_ctx_get_concrete(ctx);\n    if (ctx == NULL)\n        return NULL;\n    CRYPTO_THREAD_read_lock(ctx->lock);\n    if (ctx->dyn_indexes[index] == -1\n            && !openssl_ctx_init_index(ctx, index, meth)) {\n        CRYPTO_THREAD_unlock(ctx->lock);\n        return NULL;\n    }\n    if (CRYPTO_alloc_ex_data(CRYPTO_EX_INDEX_OPENSSL_CTX, NULL,\n                             &ctx->data, ctx->dyn_indexes[index]))\n        data = CRYPTO_get_ex_data(&ctx->data, ctx->dyn_indexes[index]);\n    CRYPTO_THREAD_unlock(ctx->lock);\n    return data;\n}', 'OPENSSL_CTX *openssl_ctx_get_concrete(OPENSSL_CTX *ctx)\n{\n#ifndef FIPS_MODE\n    if (ctx == NULL) {\n        if (!RUN_ONCE(&default_context_init, do_default_context_init))\n            return 0;\n        return default_context;\n    }\n#endif\n    return ctx;\n}', 'static THREAD_EVENT_HANDLER **\ninit_get_thread_local(CRYPTO_THREAD_LOCAL *local, int alloc, int keep)\n{\n    THREAD_EVENT_HANDLER **hands = CRYPTO_THREAD_get_local(local);\n    if (alloc) {\n        if (hands == NULL) {\n            if ((hands = OPENSSL_zalloc(sizeof(*hands))) == NULL)\n                return NULL;\n            if (!CRYPTO_THREAD_set_local(local, hands)) {\n                OPENSSL_free(hands);\n                return NULL;\n            }\n#ifndef FIPS_MODE\n            if (!init_thread_push_handlers(hands)) {\n                CRYPTO_THREAD_set_local(local, NULL);\n                OPENSSL_free(hands);\n                return NULL;\n            }\n#endif\n        }\n    } else if (!keep) {\n        CRYPTO_THREAD_set_local(local, NULL);\n    }\n    return hands;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n    return pthread_getspecific(*key);\n}']