engines/ccgost/gost2001.c:441: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_rand_range`.
Showing all 11 steps of the trace


engines/ccgost/gost2001.c:433:20: Call
431.       const EC_GROUP *group = EC_KEY_get0_group(ec);
432.   
433.       if (!group || !EC_GROUP_get_order(group, order, NULL)) {
                          ^
434.           GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);
435.           BN_free(d);

crypto/ec/ec_lib.c:315:10: Call
  313.   int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
  314.   {
  315.       if (!BN_copy(order, group->order))
                  ^
  316.           return 0;
  317.   

crypto/bn/bn_lib.c:429:1: Parameter `*a->d`
    427.   }
    428.   
    429. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    430.   {
    431.       int i;

engines/ccgost/gost2001.c:441:14: Call
439.   
440.       do {
441.           if (!BN_rand_range(d, order)) {
                    ^
442.               GOSTerr(GOST_F_GOST2001_KEYGEN,
443.                       GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);

crypto/bn/bn_rand.c:281:1: Parameter `*r->d`
  279.   }
  280.   
  281. > int BN_rand_range(BIGNUM *r, const BIGNUM *range)
  282.   {
  283.       return bn_rand_range(0, r, range);

crypto/bn/bn_rand.c:283:12: Call
  281.   int BN_rand_range(BIGNUM *r, const BIGNUM *range)
  282.   {
  283.       return bn_rand_range(0, r, range);
                    ^
  284.   }
  285.   

crypto/bn/bn_rand.c:216:1: Parameter `*r->d`
    214.   
    215.   /* random number r:  0 <= r < range */
    216. > static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)
    217.   {
    218.       int (*bn_rand) (BIGNUM *, int, int, int) =

crypto/bn/bn_rand.c:233:9: Call
    231.   
    232.       if (n == 1)
    233.           BN_zero(r);
                   ^
    234.       else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {
    235.           /*

crypto/bn/bn_lib.c:530:1: <Length trace>
528.   }
529.   
530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
531.   {
532.       bn_check_top(a);

crypto/bn/bn_lib.c:530:1: Parameter `*a->d`
      528.   }
      529.   
      530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
      531.   {
      532.       bn_check_top(a);

crypto/bn/bn_lib.c:536:5: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_rand_range` 
      534.           return (0);
      535.       a->neg = 0;
      536.       a->d[0] = w;
                 ^
      537.       a->top = (w ? 1 : 0);
      538.       bn_check_top(a);

int BN_set_word(BIGNUM *a, BN_ULONG w)
{
    bn_check_top(a);
    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
        return (0);
    a->neg = 0;
    a->d[0] = w;
    a->top = (w ? 1 : 0);
    bn_check_top(a);
    return (1);
}
['int gost2001_keygen(EC_KEY *ec)\n{\n    BIGNUM *order = BN_new(), *d = BN_new();\n    const EC_GROUP *group = EC_KEY_get0_group(ec);\n    if (!group || !EC_GROUP_get_order(group, order, NULL)) {\n        GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);\n        BN_free(d);\n        BN_free(order);\n        return 0;\n    }\n    do {\n        if (!BN_rand_range(d, order)) {\n            GOSTerr(GOST_F_GOST2001_KEYGEN,\n                    GOST_R_RANDOM_NUMBER_GENERATOR_FAILED);\n            BN_free(d);\n            BN_free(order);\n            return 0;\n        }\n    }\n    while (BN_is_zero(d));\n    if (!EC_KEY_set_private_key(ec, d)) {\n        GOSTerr(GOST_F_GOST2001_KEYGEN, ERR_R_INTERNAL_ERROR);\n        BN_free(d);\n        BN_free(order);\n        return 0;\n    }\n    BN_free(d);\n    BN_free(order);\n    return gost2001_compute_public(ec);\n}', 'int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)\n{\n    if (!BN_copy(order, group->order))\n        return 0;\n    return !BN_is_zero(order);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    int i;\n    BN_ULONG *A;\n    const BN_ULONG *B;\n    bn_check_top(b);\n    if (a == b)\n        return (a);\n    if (bn_wexpand(a, b->top) == NULL)\n        return (NULL);\n#if 1\n    A = a->d;\n    B = b->d;\n    for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n        BN_ULONG a0, a1, a2, a3;\n        a0 = B[0];\n        a1 = B[1];\n        a2 = B[2];\n        a3 = B[3];\n        A[0] = a0;\n        A[1] = a1;\n        A[2] = a2;\n        A[3] = a3;\n    }\n    switch (b->top & 3) {\n    case 3:\n        A[2] = B[2];\n    case 2:\n        A[1] = B[1];\n    case 1:\n        A[0] = B[0];\n    case 0:;\n    }\n#else\n    memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return (a);\n}', 'int BN_rand_range(BIGNUM *r, const BIGNUM *range)\n{\n    return bn_rand_range(0, r, range);\n}', 'static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)\n{\n    int (*bn_rand) (BIGNUM *, int, int, int) =\n        pseudo ? BN_pseudo_rand : BN_rand;\n    int n;\n    int count = 100;\n    if (range->neg || BN_is_zero(range)) {\n        BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);\n        return 0;\n    }\n    n = BN_num_bits(range);\n    if (n == 1)\n        BN_zero(r);\n    else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {\n        do {\n            if (!bn_rand(r, n + 1, -1, 0))\n                return 0;\n            if (BN_cmp(r, range) >= 0) {\n                if (!BN_sub(r, r, range))\n                    return 0;\n                if (BN_cmp(r, range) >= 0)\n                    if (!BN_sub(r, r, range))\n                        return 0;\n            }\n            if (!--count) {\n                BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n                return 0;\n            }\n        }\n        while (BN_cmp(r, range) >= 0);\n    } else {\n        do {\n            if (!bn_rand(r, n, -1, 0))\n                return 0;\n            if (!--count) {\n                BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n                return 0;\n            }\n        }\n        while (BN_cmp(r, range) >= 0);\n    }\n    bn_check_top(r);\n    return 1;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}']