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 47 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:209:1: start of procedure BN_num_bits()
  207.   }
  208.   
  209. > int BN_num_bits(const BIGNUM *a)
  210.   {
  211.       int i = a->top - 1;

crypto/bn/bn_lib.c:211:5: 
  209.   int BN_num_bits(const BIGNUM *a)
  210.   {
  211. >     int i = a->top - 1;
  212.       bn_check_top(a);
  213.   

crypto/bn/bn_lib.c:214:9: 
  212.       bn_check_top(a);
  213.   
  214. >     if (BN_is_zero(a))
  215.           return 0;
  216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:966:1: start of procedure BN_is_zero()
    964.   }
    965.   
    966. > int BN_is_zero(const BIGNUM *a)
    967.   {
    968.       return a->top == 0;

crypto/bn/bn_lib.c:968:12: Condition is false
    966.   int BN_is_zero(const BIGNUM *a)
    967.   {
    968.       return a->top == 0;
                      ^
    969.   }
    970.   

crypto/bn/bn_lib.c:968:5: 
    966.   int BN_is_zero(const BIGNUM *a)
    967.   {
    968. >     return a->top == 0;
    969.   }
    970.   

crypto/bn/bn_lib.c:969:1: return from a call to BN_is_zero
    967.   {
    968.       return a->top == 0;
    969. > }
    970.   
    971.   int BN_is_one(const BIGNUM *a)

crypto/bn/bn_lib.c:214:9: Taking false branch
  212.       bn_check_top(a);
  213.   
  214.       if (BN_is_zero(a))
                 ^
  215.           return 0;
  216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:216:5: Skipping BN_num_bits_word(): empty list of specs
  214.       if (BN_is_zero(a))
  215.           return 0;
  216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
             ^
  217.   }
  218.   

crypto/bn/bn_lib.c:217:1: return from a call to BN_num_bits
  215.           return 0;
  216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
  217. > }
  218.   
  219.   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:95:1: start of procedure CRYPTO_secure_malloc()
    93.   }
    94.   
    95. > void *CRYPTO_secure_malloc(size_t num, const char *file, int line)
    96.   {
    97.   #ifdef IMPLEMENTED

crypto/mem_sec.c:101:10: Taking true branch
    99.       size_t actual_size;
    100.   
    101.       if (!secure_mem_initialized) {
                    ^
    102.           return CRYPTO_malloc(num, file, line);
    103.       }

crypto/mem_sec.c:102:9: 
    100.   
    101.       if (!secure_mem_initialized) {
    102. >         return CRYPTO_malloc(num, file, line);
    103.       }
    104.       CRYPTO_THREAD_write_lock(sec_malloc_lock);

crypto/mem.c:119:1: start of procedure CRYPTO_malloc()
      117.   }
      118.   
      119. > void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121.       void *ret = NULL;

crypto/mem.c:121:5: 
      119.   void *CRYPTO_malloc(size_t num, const char *file, int line)
      120.   {
      121. >     void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)

crypto/mem.c:123:9: Taking true branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                     ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:123:32: Taking true branch
      121.       void *ret = NULL;
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
                                            ^
      124.           return malloc_impl(num, file, line);
      125.   

crypto/mem.c:124:9: Skipping __function_pointer__(): unresolved function pointer
      122.   
      123.       if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)
      124.           return malloc_impl(num, file, line);
                     ^
      125.   
      126.       if (num <= 0)

crypto/mem.c:144:1: return from a call to CRYPTO_malloc
      142.   
      143.       return ret;
      144. > }
      145.   
      146.   void *CRYPTO_zalloc(size_t num, const char *file, int line)

crypto/mem_sec.c:113:1: return from a call to CRYPTO_secure_malloc
    111.       return CRYPTO_malloc(num, file, line);
    112.   #endif /* IMPLEMENTED */
    113. > }
    114.   
    115.   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:650:1: start of procedure BN_bn2lebinpad()
  648.   }
  649.   
  650. > int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)
  651.   {
  652.       int i;

crypto/bn/bn_lib.c:655:5: 
  653.       BN_ULONG l;
  654.       bn_check_top(a);
  655. >     i = BN_num_bytes(a);
  656.       if (tolen < i)
  657.           return -1;

crypto/bn/bn_lib.c:209:1: start of procedure BN_num_bits()
    207.   }
    208.   
    209. > int BN_num_bits(const BIGNUM *a)
    210.   {
    211.       int i = a->top - 1;

crypto/bn/bn_lib.c:211:5: 
    209.   int BN_num_bits(const BIGNUM *a)
    210.   {
    211. >     int i = a->top - 1;
    212.       bn_check_top(a);
    213.   

crypto/bn/bn_lib.c:214:9: 
    212.       bn_check_top(a);
    213.   
    214. >     if (BN_is_zero(a))
    215.           return 0;
    216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:966:1: start of procedure BN_is_zero()
      964.   }
      965.   
      966. > int BN_is_zero(const BIGNUM *a)
      967.   {
      968.       return a->top == 0;

crypto/bn/bn_lib.c:968:12: Condition is false
      966.   int BN_is_zero(const BIGNUM *a)
      967.   {
      968.       return a->top == 0;
                        ^
      969.   }
      970.   

crypto/bn/bn_lib.c:968:5: 
      966.   int BN_is_zero(const BIGNUM *a)
      967.   {
      968. >     return a->top == 0;
      969.   }
      970.   

crypto/bn/bn_lib.c:969:1: return from a call to BN_is_zero
      967.   {
      968.       return a->top == 0;
      969. > }
      970.   
      971.   int BN_is_one(const BIGNUM *a)

crypto/bn/bn_lib.c:214:9: Taking false branch
    212.       bn_check_top(a);
    213.   
    214.       if (BN_is_zero(a))
                   ^
    215.           return 0;
    216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:216:5: Skipping BN_num_bits_word(): empty list of specs
    214.       if (BN_is_zero(a))
    215.           return 0;
    216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
               ^
    217.   }
    218.   

crypto/bn/bn_lib.c:217:1: return from a call to BN_num_bits
    215.           return 0;
    216.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
    217. > }
    218.   
    219.   static void bn_free_d(BIGNUM *a)

crypto/bn/bn_lib.c:656:9: Taking true branch
  654.       bn_check_top(a);
  655.       i = BN_num_bytes(a);
  656.       if (tolen < i)
                 ^
  657.           return -1;
  658.       /* Add trailing zeroes if necessary */

crypto/bn/bn_lib.c:657:9: 
  655.       i = BN_num_bytes(a);
  656.       if (tolen < i)
  657. >         return -1;
  658.       /* Add trailing zeroes if necessary */
  659.       if (tolen > i)

crypto/bn/bn_lib.c:667:1: return from a call to BN_bn2lebinpad
  665.       }
  666.       return tolen;
  667. > }
  668.   
  669.   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        return CRYPTO_malloc(num, file, line);\n    }\n    CRYPTO_THREAD_write_lock(sec_malloc_lock);\n    ret = sh_malloc(num);\n    actual_size = ret ? sh_actual_size(ret) : 0;\n    secure_mem_used += actual_size;\n    CRYPTO_THREAD_unlock(sec_malloc_lock);\n    return ret;\n#else\n    return CRYPTO_malloc(num, file, line);\n#endif\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\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}']