crypto/dh/dh_key.c:152: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_rand_range`.
Showing all 9 steps of the trace


crypto/dh/dh_key.c:114:1: Parameter `dh->priv_key->d`
112.   }
113.   
114. > static int generate_key(DH *dh)
115.   {
116.       int ok = 0;

crypto/dh/dh_key.c:152:22: Call
150.           if (dh->q) {
151.               do {
152.                   if (!BN_rand_range(priv_key, dh->q))
                            ^
153.                       goto err;
154.               }

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);
}
['static int generate_key(DH *dh)\n{\n    int ok = 0;\n    int generate_new_key = 0;\n    unsigned l;\n    BN_CTX *ctx;\n    BN_MONT_CTX *mont = NULL;\n    BIGNUM *pub_key = NULL, *priv_key = NULL;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n    if (dh->priv_key == NULL) {\n        priv_key = BN_secure_new();\n        if (priv_key == NULL)\n            goto err;\n        generate_new_key = 1;\n    } else\n        priv_key = dh->priv_key;\n    if (dh->pub_key == NULL) {\n        pub_key = BN_new();\n        if (pub_key == NULL)\n            goto err;\n    } else\n        pub_key = dh->pub_key;\n    if (dh->flags & DH_FLAG_CACHE_MONT_P) {\n        mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,\n                                      CRYPTO_LOCK_DH, dh->p, ctx);\n        if (!mont)\n            goto err;\n    }\n    if (generate_new_key) {\n        if (dh->q) {\n            do {\n                if (!BN_rand_range(priv_key, dh->q))\n                    goto err;\n            }\n            while (BN_is_zero(priv_key) || BN_is_one(priv_key));\n        } else {\n            l = dh->length ? dh->length : BN_num_bits(dh->p) - 1;\n            if (!BN_rand(priv_key, l, 0, 0))\n                goto err;\n        }\n    }\n    {\n        BIGNUM *local_prk = NULL;\n        BIGNUM *prk;\n        if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) {\n            local_prk = prk = BN_new();\n            if (local_prk == NULL)\n                goto err;\n            BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n        } else {\n            prk = priv_key;\n        }\n        if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) {\n            BN_free(local_prk);\n            goto err;\n        }\n        BN_free(local_prk);\n    }\n    dh->pub_key = pub_key;\n    dh->priv_key = priv_key;\n    ok = 1;\n err:\n    if (ok != 1)\n        DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB);\n    if (pub_key != dh->pub_key)\n        BN_free(pub_key);\n    if (priv_key != dh->priv_key)\n        BN_free(priv_key);\n    BN_CTX_free(ctx);\n    return (ok);\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}']