test/drbgtest.c:540: error: NULL_DEREFERENCE
  pointer `ctx` last assigned on line 538 could be null and is dereferenced at line 540, column 25.
Showing all 13 steps of the trace


test/drbgtest.c:536:1: start of procedure unhook_drbg()
534.   
535.   /* Installs the hook for the get_entropy() callback of the given drbg */
536. > static void unhook_drbg(RAND_DRBG *drbg)
537.   {
538.       HOOK_CTX *ctx = get_hook_ctx(drbg);

test/drbgtest.c:538:5: 
536.   static void unhook_drbg(RAND_DRBG *drbg)
537.   {
538. >     HOOK_CTX *ctx = get_hook_ctx(drbg);
539.   
540.       drbg->get_entropy = ctx->get_entropy;

test/drbgtest.c:501:1: start of procedure get_hook_ctx()
  499.   static HOOK_CTX master_ctx, public_ctx, private_ctx;
  500.   
  501. > static HOOK_CTX *get_hook_ctx(RAND_DRBG *drbg)
  502.   {
  503.       return (HOOK_CTX *)RAND_DRBG_get_ex_data(drbg, app_data_index);

test/drbgtest.c:503:5: 
  501.   static HOOK_CTX *get_hook_ctx(RAND_DRBG *drbg)
  502.   {
  503. >     return (HOOK_CTX *)RAND_DRBG_get_ex_data(drbg, app_data_index);
  504.   }
  505.   

crypto/rand/drbg_lib.c:878:1: start of procedure RAND_DRBG_get_ex_data()
    876.   }
    877.   
    878. > void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx)
    879.   {
    880.       return CRYPTO_get_ex_data(&drbg->ex_data, idx);

crypto/rand/drbg_lib.c:880:5: 
    878.   void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx)
    879.   {
    880. >     return CRYPTO_get_ex_data(&drbg->ex_data, idx);
    881.   }
    882.   

crypto/ex_data.c:393:1: start of procedure CRYPTO_get_ex_data()
      391.    * particular index in the class used by this variable
      392.    */
      393. > void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
      394.   {
      395.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))

crypto/ex_data.c:395:9: Taking true branch
      393.   void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)
      394.   {
      395.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
                     ^
      396.           return NULL;
      397.       return sk_void_value(ad->sk, idx);

crypto/ex_data.c:396:9: 
      394.   {
      395.       if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
      396. >         return NULL;
      397.       return sk_void_value(ad->sk, idx);
      398.   }

crypto/ex_data.c:398:1: return from a call to CRYPTO_get_ex_data
      396.           return NULL;
      397.       return sk_void_value(ad->sk, idx);
      398. > }

crypto/rand/drbg_lib.c:881:1: return from a call to RAND_DRBG_get_ex_data
    879.   {
    880.       return CRYPTO_get_ex_data(&drbg->ex_data, idx);
    881. > }
    882.   
    883.   

test/drbgtest.c:504:1: return from a call to get_hook_ctx
  502.   {
  503.       return (HOOK_CTX *)RAND_DRBG_get_ex_data(drbg, app_data_index);
  504. > }
  505.   
  506.   /* Intercepts and counts calls to the get_entropy() callback */

test/drbgtest.c:540:5: 
538.       HOOK_CTX *ctx = get_hook_ctx(drbg);
539.   
540. >     drbg->get_entropy = ctx->get_entropy;
541.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DRBG, drbg, &drbg->ex_data);
542.   }

static void unhook_drbg(RAND_DRBG *drbg)
{
    HOOK_CTX *ctx = get_hook_ctx(drbg);
    drbg->get_entropy = ctx->get_entropy;
    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DRBG, drbg, &drbg->ex_data);
}
['static void unhook_drbg(RAND_DRBG *drbg)\n{\n    HOOK_CTX *ctx = get_hook_ctx(drbg);\n    drbg->get_entropy = ctx->get_entropy;\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DRBG, drbg, &drbg->ex_data);\n}', 'static HOOK_CTX *get_hook_ctx(RAND_DRBG *drbg)\n{\n    return (HOOK_CTX *)RAND_DRBG_get_ex_data(drbg, app_data_index);\n}', 'void *RAND_DRBG_get_ex_data(const RAND_DRBG *drbg, int idx)\n{\n    return CRYPTO_get_ex_data(&drbg->ex_data, idx);\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n    if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n        return NULL;\n    return sk_void_value(ad->sk, idx);\n}']