crypto/rand/drbg_lib.c:1089: error: NULL_DEREFERENCE
  pointer `drbg` last assigned on line 1087 could be null and is dereferenced by call to `rand_drbg_seedlen()` at line 1089, column 22.
Showing all 16 steps of the trace


crypto/rand/drbg_lib.c:1084:1: start of procedure drbg_add()
1082.   
1083.   /* Implements the default OpenSSL RAND_add() method */
1084. > static int drbg_add(const void *buf, int num, double randomness)
1085.   {
1086.       int ret = 0;

crypto/rand/drbg_lib.c:1086:5: 
1084.   static int drbg_add(const void *buf, int num, double randomness)
1085.   {
1086. >     int ret = 0;
1087.       RAND_DRBG *drbg = RAND_DRBG_get0_master();
1088.       size_t buflen;

crypto/rand/drbg_lib.c:1087:5: 
1085.   {
1086.       int ret = 0;
1087. >     RAND_DRBG *drbg = RAND_DRBG_get0_master();
1088.       size_t buflen;
1089.       size_t seedlen = rand_drbg_seedlen(drbg);

crypto/rand/drbg_lib.c:1166:1: start of procedure RAND_DRBG_get0_master()
  1164.    *
  1165.    */
  1166. > RAND_DRBG *RAND_DRBG_get0_master(void)
  1167.   {
  1168.       if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))

crypto/rand/drbg_lib.c:1168:10: 
  1166.   RAND_DRBG *RAND_DRBG_get0_master(void)
  1167.   {
  1168. >     if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))
  1169.           return NULL;
  1170.   

crypto/threads_pthread.c:111:1: start of procedure CRYPTO_THREAD_run_once()
    109.   }
    110.   
    111. > int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
    112.   {
    113.       if (pthread_once(once, init) != 0)

crypto/threads_pthread.c:113:9: Taking true branch
    111.   int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
    112.   {
    113.       if (pthread_once(once, init) != 0)
                   ^
    114.           return 0;
    115.   

crypto/threads_pthread.c:114:9: 
    112.   {
    113.       if (pthread_once(once, init) != 0)
    114. >         return 0;
    115.   
    116.       return 1;

crypto/threads_pthread.c:117:1: return from a call to CRYPTO_THREAD_run_once
    115.   
    116.       return 1;
    117. > }
    118.   
    119.   int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))

crypto/rand/drbg_lib.c:1168:10: Condition is false
  1166.   RAND_DRBG *RAND_DRBG_get0_master(void)
  1167.   {
  1168.       if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))
                   ^
  1169.           return NULL;
  1170.   

crypto/rand/drbg_lib.c:1168:10: Taking true branch
  1166.   RAND_DRBG *RAND_DRBG_get0_master(void)
  1167.   {
  1168.       if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))
                   ^
  1169.           return NULL;
  1170.   

crypto/rand/drbg_lib.c:1169:9: 
  1167.   {
  1168.       if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))
  1169. >         return NULL;
  1170.   
  1171.       return master_drbg;

crypto/rand/drbg_lib.c:1172:1: return from a call to RAND_DRBG_get0_master
  1170.   
  1171.       return master_drbg;
  1172. > }
  1173.   
  1174.   /*

crypto/rand/drbg_lib.c:1089:5: 
1087.       RAND_DRBG *drbg = RAND_DRBG_get0_master();
1088.       size_t buflen;
1089. >     size_t seedlen = rand_drbg_seedlen(drbg);
1090.   
1091.       if (drbg == NULL)

crypto/rand/drbg_lib.c:1052:1: start of procedure rand_drbg_seedlen()
  1050.    *       the copy accordingly.
  1051.    */
  1052. > static size_t rand_drbg_seedlen(RAND_DRBG *drbg)
  1053.   {
  1054.       /*

crypto/rand/drbg_lib.c:1060:5: 
  1058.        * in RAND_DRBG_instantiate().
  1059.        */
  1060. >     size_t min_entropy = drbg->strength;
  1061.       size_t min_entropylen = drbg->min_entropylen;
  1062.   

static int drbg_add(const void *buf, int num, double randomness)
{
    int ret = 0;
    RAND_DRBG *drbg = RAND_DRBG_get0_master();
    size_t buflen;
    size_t seedlen = rand_drbg_seedlen(drbg);
    if (drbg == NULL)
        return 0;
    if (num < 0 || randomness < 0.0)
        return 0;
    buflen = (size_t)num;
    if (buflen < seedlen || randomness < (double) seedlen) {
#if defined(OPENSSL_RAND_SEED_NONE)
        unsigned char dummy[1];
        return RAND_DRBG_generate(drbg, dummy, sizeof(dummy), 0, buf, buflen);
#else
        randomness = 0.0;
#endif
    }
    if (randomness > (double)seedlen) {
        randomness = (double)seedlen;
    }
    rand_drbg_lock(drbg);
    ret = rand_drbg_restart(drbg, buf, buflen, (size_t)(8 * randomness));
    rand_drbg_unlock(drbg);
    return ret;
}
['static int drbg_add(const void *buf, int num, double randomness)\n{\n    int ret = 0;\n    RAND_DRBG *drbg = RAND_DRBG_get0_master();\n    size_t buflen;\n    size_t seedlen = rand_drbg_seedlen(drbg);\n    if (drbg == NULL)\n        return 0;\n    if (num < 0 || randomness < 0.0)\n        return 0;\n    buflen = (size_t)num;\n    if (buflen < seedlen || randomness < (double) seedlen) {\n#if defined(OPENSSL_RAND_SEED_NONE)\n        unsigned char dummy[1];\n        return RAND_DRBG_generate(drbg, dummy, sizeof(dummy), 0, buf, buflen);\n#else\n        randomness = 0.0;\n#endif\n    }\n    if (randomness > (double)seedlen) {\n        randomness = (double)seedlen;\n    }\n    rand_drbg_lock(drbg);\n    ret = rand_drbg_restart(drbg, buf, buflen, (size_t)(8 * randomness));\n    rand_drbg_unlock(drbg);\n    return ret;\n}', 'RAND_DRBG *RAND_DRBG_get0_master(void)\n{\n    if (!RUN_ONCE(&rand_drbg_init, do_rand_drbg_init))\n        return NULL;\n    return master_drbg;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n    if (pthread_once(once, init) != 0)\n        return 0;\n    return 1;\n}', 'static size_t rand_drbg_seedlen(RAND_DRBG *drbg)\n{\n    size_t min_entropy = drbg->strength;\n    size_t min_entropylen = drbg->min_entropylen;\n    if (drbg->min_noncelen > 0 && drbg->get_nonce == NULL) {\n        min_entropy += drbg->strength / 2;\n        min_entropylen += drbg->min_noncelen;\n    }\n    min_entropy >>= 3;\n    return min_entropy > min_entropylen ? min_entropy : min_entropylen;\n}']