crypto/ec/ec_25519.c:117: error: NULL_DEREFERENCE
  pointer `eckey->custom_data` last assigned on line 114 could be null and is dereferenced by call to `BN_bn2lebinpad()` at line 117, column 9.
Showing all 59 steps of the trace


crypto/ec/ec_25519.c:110:1: start of procedure x25519_set_private()
108.   }
109.   
110. > static int x25519_set_private(EC_KEY *eckey, const BIGNUM *priv_key)
111.   {
112.       if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)

crypto/ec/ec_25519.c:112:9: 
110.   static int x25519_set_private(EC_KEY *eckey, const BIGNUM *priv_key)
111.   {
112. >     if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)
113.           return 0;
114.       if (x25519_init_private(eckey, NULL))

crypto/bn/bn_lib.c:214:1: start of procedure BN_num_bits()
  212.   }
  213.   
  214. > int BN_num_bits(const BIGNUM *a)
  215.   {
  216.       int i = a->top - 1;

crypto/bn/bn_lib.c:216:5: 
  214.   int BN_num_bits(const BIGNUM *a)
  215.   {
  216. >     int i = a->top - 1;
  217.       bn_check_top(a);
  218.   

crypto/bn/bn_lib.c:219:9: 
  217.       bn_check_top(a);
  218.   
  219. >     if (BN_is_zero(a))
  220.           return 0;
  221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:975:1: start of procedure BN_is_zero()
    973.   }
    974.   
    975. > int BN_is_zero(const BIGNUM *a)
    976.   {
    977.       return a->top == 0;

crypto/bn/bn_lib.c:977:12: Condition is false
    975.   int BN_is_zero(const BIGNUM *a)
    976.   {
    977.       return a->top == 0;
                      ^
    978.   }
    979.   

crypto/bn/bn_lib.c:977:5: 
    975.   int BN_is_zero(const BIGNUM *a)
    976.   {
    977. >     return a->top == 0;
    978.   }
    979.   

crypto/bn/bn_lib.c:978:1: return from a call to BN_is_zero
    976.   {
    977.       return a->top == 0;
    978. > }
    979.   
    980.   int BN_is_one(const BIGNUM *a)

crypto/bn/bn_lib.c:219:9: Taking false branch
  217.       bn_check_top(a);
  218.   
  219.       if (BN_is_zero(a))
                 ^
  220.           return 0;
  221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:221:5: Skipping BN_num_bits_word(): empty list of specs
  219.       if (BN_is_zero(a))
  220.           return 0;
  221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
             ^
  222.   }
  223.   

crypto/bn/bn_lib.c:222:1: return from a call to BN_num_bits
  220.           return 0;
  221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
  222. > }
  223.   
  224.   static void bn_free_d(BIGNUM *a)

crypto/ec/ec_25519.c:112:9: Taking false branch
110.   static int x25519_set_private(EC_KEY *eckey, const BIGNUM *priv_key)
111.   {
112.       if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)
               ^
113.           return 0;
114.       if (x25519_init_private(eckey, NULL))

crypto/ec/ec_25519.c:114:9: 
112.       if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)
113.           return 0;
114. >     if (x25519_init_private(eckey, NULL))
115.           return 0;
116.       /* Convert BIGNUM form private key to internal format */

crypto/ec/ec_25519.c:78:1: start of procedure x25519_init_private()
  76.   
  77.   /* Copy Curve25519 private key buffer, allocating is necessary */
  78. > static int x25519_init_private(EC_KEY *dst, const void *src)
  79.   {
  80.       if (dst->custom_data == NULL) {

crypto/ec/ec_25519.c:80:9: Taking true branch
  78.   static int x25519_init_private(EC_KEY *dst, const void *src)
  79.   {
  80.       if (dst->custom_data == NULL) {
                ^
  81.           dst->custom_data = OPENSSL_secure_malloc(EC_X25519_KEYLEN);
  82.           if (dst->custom_data == NULL)

crypto/ec/ec_25519.c:81:9: 
  79.   {
  80.       if (dst->custom_data == NULL) {
  81. >         dst->custom_data = OPENSSL_secure_malloc(EC_X25519_KEYLEN);
  82.           if (dst->custom_data == NULL)
  83.               return 0;

crypto/mem_sec.c:93:1: start of procedure CRYPTO_secure_malloc()
    91.   }
    92.   
    93. > void *CRYPTO_secure_malloc(size_t num, const char *file, int line)
    94.   {
    95.   #ifdef IMPLEMENTED

crypto/mem_sec.c:99:10: Taking false branch
    97.       size_t actual_size;
    98.   
    99.       if (!secure_mem_initialized) {
                    ^
    100.           too_late = 1;
    101.           return CRYPTO_malloc(num, file, line);

crypto/mem_sec.c:103:5: 
    101.           return CRYPTO_malloc(num, file, line);
    102.       }
    103. >     LOCK();
    104.       ret = sh_malloc(num);
    105.       actual_size = ret ? sh_actual_size(ret) : 0;

crypto/lock.c:414:1: start of procedure CRYPTO_lock()
      412.   }
      413.   
      414. > void CRYPTO_lock(int mode, int type, const char *file, int line)
      415.   {
      416.   #ifdef LOCK_DEBUG

crypto/lock.c:441:9: Taking false branch
      439.       }
      440.   #endif
      441.       if (type < 0) {
                     ^
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:452:16: Taking true branch
      450.               CRYPTO_destroy_dynlockid(type);
      451.           }
      452.       } else if (locking_callback != NULL)
                            ^
      453.           locking_callback(mode, type, file, line);
      454.   }

crypto/lock.c:453:9: Skipping __function_pointer__(): unresolved function pointer
      451.           }
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
                     ^
      454.   }
      455.   

crypto/lock.c:441:5: 
      439.       }
      440.   #endif
      441. >     if (type < 0) {
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:454:1: return from a call to CRYPTO_lock
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
      454. > }
      455.   
      456.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/mem_sec.c:104:5: Skipping sh_malloc(): empty list of specs
    102.       }
    103.       LOCK();
    104.       ret = sh_malloc(num);
               ^
    105.       actual_size = ret ? sh_actual_size(ret) : 0;
    106.       secure_mem_used += actual_size;

crypto/mem_sec.c:105:19: Condition is false
    103.       LOCK();
    104.       ret = sh_malloc(num);
    105.       actual_size = ret ? sh_actual_size(ret) : 0;
                             ^
    106.       secure_mem_used += actual_size;
    107.       UNLOCK();

crypto/mem_sec.c:105:5: 
    103.       LOCK();
    104.       ret = sh_malloc(num);
    105. >     actual_size = ret ? sh_actual_size(ret) : 0;
    106.       secure_mem_used += actual_size;
    107.       UNLOCK();

crypto/mem_sec.c:106:5: 
    104.       ret = sh_malloc(num);
    105.       actual_size = ret ? sh_actual_size(ret) : 0;
    106. >     secure_mem_used += actual_size;
    107.       UNLOCK();
    108.       return ret;

crypto/mem_sec.c:107:5: 
    105.       actual_size = ret ? sh_actual_size(ret) : 0;
    106.       secure_mem_used += actual_size;
    107. >     UNLOCK();
    108.       return ret;
    109.   #else

crypto/lock.c:414:1: start of procedure CRYPTO_lock()
      412.   }
      413.   
      414. > void CRYPTO_lock(int mode, int type, const char *file, int line)
      415.   {
      416.   #ifdef LOCK_DEBUG

crypto/lock.c:441:9: Taking false branch
      439.       }
      440.   #endif
      441.       if (type < 0) {
                     ^
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:452:16: Taking true branch
      450.               CRYPTO_destroy_dynlockid(type);
      451.           }
      452.       } else if (locking_callback != NULL)
                            ^
      453.           locking_callback(mode, type, file, line);
      454.   }

crypto/lock.c:453:9: Skipping __function_pointer__(): unresolved function pointer
      451.           }
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
                     ^
      454.   }
      455.   

crypto/lock.c:441:5: 
      439.       }
      440.   #endif
      441. >     if (type < 0) {
      442.           if (dynlock_lock_callback != NULL) {
      443.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:454:1: return from a call to CRYPTO_lock
      452.       } else if (locking_callback != NULL)
      453.           locking_callback(mode, type, file, line);
      454. > }
      455.   
      456.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/mem_sec.c:108:5: 
    106.       secure_mem_used += actual_size;
    107.       UNLOCK();
    108. >     return ret;
    109.   #else
    110.       return CRYPTO_malloc(num, file, line);

crypto/mem_sec.c:112:1: return from a call to CRYPTO_secure_malloc
    110.       return CRYPTO_malloc(num, file, line);
    111.   #endif /* IMPLEMENTED */
    112. > }
    113.   
    114.   void *CRYPTO_secure_zalloc(size_t num, const char *file, int line)

crypto/ec/ec_25519.c:82:13: Taking true branch
  80.       if (dst->custom_data == NULL) {
  81.           dst->custom_data = OPENSSL_secure_malloc(EC_X25519_KEYLEN);
  82.           if (dst->custom_data == NULL)
                    ^
  83.               return 0;
  84.       }

crypto/ec/ec_25519.c:83:13: 
  81.           dst->custom_data = OPENSSL_secure_malloc(EC_X25519_KEYLEN);
  82.           if (dst->custom_data == NULL)
  83. >             return 0;
  84.       }
  85.       if (src != NULL)

crypto/ec/ec_25519.c:88:1: return from a call to x25519_init_private
  86.           memcpy(dst->custom_data, src, EC_X25519_KEYLEN);
  87.       return 1;
  88. > }
  89.   
  90.   static int x25519_group_init(EC_GROUP *grp)

crypto/ec/ec_25519.c:114:9: Taking false branch
112.       if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)
113.           return 0;
114.       if (x25519_init_private(eckey, NULL))
               ^
115.           return 0;
116.       /* Convert BIGNUM form private key to internal format */

crypto/ec/ec_25519.c:117:9: 
115.           return 0;
116.       /* Convert BIGNUM form private key to internal format */
117. >     if (BN_bn2lebinpad(priv_key, eckey->custom_data, EC_X25519_KEYLEN)
118.           != EC_X25519_KEYLEN)
119.           return 0;

crypto/bn/bn_lib.c:659:1: start of procedure BN_bn2lebinpad()
  657.   }
  658.   
  659. > int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)
  660.   {
  661.       int i;

crypto/bn/bn_lib.c:664:5: 
  662.       BN_ULONG l;
  663.       bn_check_top(a);
  664. >     i = BN_num_bytes(a);
  665.       if (tolen < i)
  666.           return -1;

crypto/bn/bn_lib.c:214:1: start of procedure BN_num_bits()
    212.   }
    213.   
    214. > int BN_num_bits(const BIGNUM *a)
    215.   {
    216.       int i = a->top - 1;

crypto/bn/bn_lib.c:216:5: 
    214.   int BN_num_bits(const BIGNUM *a)
    215.   {
    216. >     int i = a->top - 1;
    217.       bn_check_top(a);
    218.   

crypto/bn/bn_lib.c:219:9: 
    217.       bn_check_top(a);
    218.   
    219. >     if (BN_is_zero(a))
    220.           return 0;
    221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:975:1: start of procedure BN_is_zero()
      973.   }
      974.   
      975. > int BN_is_zero(const BIGNUM *a)
      976.   {
      977.       return a->top == 0;

crypto/bn/bn_lib.c:977:12: Condition is false
      975.   int BN_is_zero(const BIGNUM *a)
      976.   {
      977.       return a->top == 0;
                        ^
      978.   }
      979.   

crypto/bn/bn_lib.c:977:5: 
      975.   int BN_is_zero(const BIGNUM *a)
      976.   {
      977. >     return a->top == 0;
      978.   }
      979.   

crypto/bn/bn_lib.c:978:1: return from a call to BN_is_zero
      976.   {
      977.       return a->top == 0;
      978. > }
      979.   
      980.   int BN_is_one(const BIGNUM *a)

crypto/bn/bn_lib.c:219:9: Taking false branch
    217.       bn_check_top(a);
    218.   
    219.       if (BN_is_zero(a))
                   ^
    220.           return 0;
    221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:221:5: Skipping BN_num_bits_word(): empty list of specs
    219.       if (BN_is_zero(a))
    220.           return 0;
    221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
               ^
    222.   }
    223.   

crypto/bn/bn_lib.c:222:1: return from a call to BN_num_bits
    220.           return 0;
    221.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
    222. > }
    223.   
    224.   static void bn_free_d(BIGNUM *a)

crypto/bn/bn_lib.c:665:9: Taking true branch
  663.       bn_check_top(a);
  664.       i = BN_num_bytes(a);
  665.       if (tolen < i)
                 ^
  666.           return -1;
  667.       /* Add trailing zeroes if necessary */

crypto/bn/bn_lib.c:666:9: 
  664.       i = BN_num_bytes(a);
  665.       if (tolen < i)
  666. >         return -1;
  667.       /* Add trailing zeroes if necessary */
  668.       if (tolen > i)

crypto/bn/bn_lib.c:676:1: return from a call to BN_bn2lebinpad
  674.       }
  675.       return tolen;
  676. > }
  677.   
  678.   int BN_ucmp(const BIGNUM *a, const BIGNUM *b)

static int x25519_set_private(EC_KEY *eckey, const BIGNUM *priv_key)
{
    if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)
        return 0;
    if (x25519_init_private(eckey, NULL))
        return 0;
    if (BN_bn2lebinpad(priv_key, eckey->custom_data, EC_X25519_KEYLEN)
        != EC_X25519_KEYLEN)
        return 0;
    return 1;
}
['static int x25519_set_private(EC_KEY *eckey, const BIGNUM *priv_key)\n{\n    if (BN_num_bytes(priv_key) > EC_X25519_KEYLEN)\n        return 0;\n    if (x25519_init_private(eckey, NULL))\n        return 0;\n    if (BN_bn2lebinpad(priv_key, eckey->custom_data, EC_X25519_KEYLEN)\n        != EC_X25519_KEYLEN)\n        return 0;\n    return 1;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'static int x25519_init_private(EC_KEY *dst, const void *src)\n{\n    if (dst->custom_data == NULL) {\n        dst->custom_data = OPENSSL_secure_malloc(EC_X25519_KEYLEN);\n        if (dst->custom_data == NULL)\n            return 0;\n    }\n    if (src != NULL)\n        memcpy(dst->custom_data, src, EC_X25519_KEYLEN);\n    return 1;\n}', 'void *CRYPTO_secure_malloc(size_t num, const char *file, int line)\n{\n#ifdef IMPLEMENTED\n    void *ret;\n    size_t actual_size;\n    if (!secure_mem_initialized) {\n        too_late = 1;\n        return CRYPTO_malloc(num, file, line);\n    }\n    LOCK();\n    ret = sh_malloc(num);\n    actual_size = ret ? sh_actual_size(ret) : 0;\n    secure_mem_used += actual_size;\n    UNLOCK();\n    return ret;\n#else\n    return CRYPTO_malloc(num, file, line);\n#endif\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n    {\n        CRYPTO_THREADID id;\n        char *rw_text, *operation_text;\n        if (mode & CRYPTO_LOCK)\n            operation_text = "lock  ";\n        else if (mode & CRYPTO_UNLOCK)\n            operation_text = "unlock";\n        else\n            operation_text = "ERROR ";\n        if (mode & CRYPTO_READ)\n            rw_text = "r";\n        else if (mode & CRYPTO_WRITE)\n            rw_text = "w";\n        else\n            rw_text = "ERROR";\n        CRYPTO_THREADID_current(&id);\n        fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n                CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n                CRYPTO_get_lock_name(type), file, line);\n    }\n#endif\n    if (type < 0) {\n        if (dynlock_lock_callback != NULL) {\n            struct CRYPTO_dynlock_value *pointer\n                = CRYPTO_get_dynlock_value(type);\n            OPENSSL_assert(pointer != NULL);\n            dynlock_lock_callback(mode, pointer, file, line);\n            CRYPTO_destroy_dynlockid(type);\n        }\n    } else if (locking_callback != NULL)\n        locking_callback(mode, type, file, line);\n}', 'int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)\n{\n    int i;\n    BN_ULONG l;\n    bn_check_top(a);\n    i = BN_num_bytes(a);\n    if (tolen < i)\n        return -1;\n    if (tolen > i)\n        memset(to + i, 0, tolen - i);\n    to += i - 1;\n    while (i--) {\n        l = a->d[i / BN_BYTES];\n        *(to--) = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff;\n    }\n    return tolen;\n}']