crypto/dsa/dsa_gen.c:106: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_lshift`.
Showing all 11 steps of the trace


crypto/dsa/dsa_gen.c:44:1: Parameter `bits`
42.   }
43.   
44. > int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
45.                            const EVP_MD *evpmd, const unsigned char *seed_in,
46.                            size_t seed_len, unsigned char *seed_out,

crypto/dsa/dsa_gen.c:74:5: Assignment
72.           bits = 512;
73.   
74.       bits = (bits + 63) / 64 * 64;
          ^
75.   
76.       if (seed_in != NULL) {

crypto/dsa/dsa_gen.c:106:10: Call
104.           goto err;
105.   
106.       if (!BN_lshift(test, BN_value_one(), bits - 1))
                ^
107.           goto err;
108.   

crypto/bn/bn_shift.c:81:1: <Offset trace>
79.   }
80.   
81. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
82.   {
83.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:81:1: Parameter `a->top`
  79.   }
  80.   
  81. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
  82.   {
  83.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:81:1: <Length trace>
79.   }
80.   
81. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
82.   {
83.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:81:1: Parameter `*r->d`
  79.   }
  80.   
  81. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
  82.   {
  83.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:97:9: Call
  95.       r->neg = a->neg;
  96.       nw = n / BN_BITS2;
  97.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
                 ^
  98.           return (0);
  99.       lb = n % BN_BITS2;

crypto/bn/bn_lib.c:1016:1: Parameter `*a->d`
    1014.   }
    1015.   
    1016. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    1017.   {
    1018.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_shift.c:102:5: Assignment
  100.       rb = BN_BITS2 - lb;
  101.       f = a->d;
  102.       t = r->d;
             ^
  103.       t[a->top + nw] = 0;
  104.       if (lb == 0)

crypto/bn/bn_shift.c:103:5: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_lshift` 
  101.       f = a->d;
  102.       t = r->d;
  103.       t[a->top + nw] = 0;
             ^
  104.       if (lb == 0)
  105.           for (i = a->top - 1; i >= 0; i--)

int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
    int i, nw, lb, rb;
    BN_ULONG *t, *f;
    BN_ULONG l;
    bn_check_top(r);
    bn_check_top(a);
    if (n < 0) {
        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
        return 0;
    }
    r->neg = a->neg;
    nw = n / BN_BITS2;
    if (bn_wexpand(r, a->top + nw + 1) == NULL)
        return (0);
    lb = n % BN_BITS2;
    rb = BN_BITS2 - lb;
    f = a->d;
    t = r->d;
    t[a->top + nw] = 0;
    if (lb == 0)
        for (i = a->top - 1; i >= 0; i--)
            t[nw + i] = f[i];
    else
        for (i = a->top - 1; i >= 0; i--) {
            l = f[i];
            t[nw + i + 1] |= (l >> rb) & BN_MASK2;
            t[nw + i] = (l << lb) & BN_MASK2;
        }
    memset(t, 0, sizeof(*t) * nw);
    r->top = a->top + nw + 1;
    bn_correct_top(r);
    bn_check_top(r);
    return (1);
}
['int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,\n                         const EVP_MD *evpmd, const unsigned char *seed_in,\n                         size_t seed_len, unsigned char *seed_out,\n                         int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)\n{\n    int ok = 0;\n    unsigned char seed[SHA256_DIGEST_LENGTH];\n    unsigned char md[SHA256_DIGEST_LENGTH];\n    unsigned char buf[SHA256_DIGEST_LENGTH], buf2[SHA256_DIGEST_LENGTH];\n    BIGNUM *r0, *W, *X, *c, *test;\n    BIGNUM *g = NULL, *q = NULL, *p = NULL;\n    BN_MONT_CTX *mont = NULL;\n    int i, k, n = 0, m = 0, qsize = qbits >> 3;\n    int counter = 0;\n    int r = 0;\n    BN_CTX *ctx = NULL;\n    unsigned int h = 2;\n    if (qsize != SHA_DIGEST_LENGTH && qsize != SHA224_DIGEST_LENGTH &&\n        qsize != SHA256_DIGEST_LENGTH)\n        return 0;\n    if (evpmd == NULL)\n        evpmd = EVP_sha1();\n    if (bits < 512)\n        bits = 512;\n    bits = (bits + 63) / 64 * 64;\n    if (seed_in != NULL) {\n        if (seed_len < (size_t)qsize)\n            return 0;\n        if (seed_len > (size_t)qsize) {\n            seed_len = qsize;\n        }\n        memcpy(seed, seed_in, seed_len);\n    }\n    if ((mont = BN_MONT_CTX_new()) == NULL)\n        goto err;\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    r0 = BN_CTX_get(ctx);\n    g = BN_CTX_get(ctx);\n    W = BN_CTX_get(ctx);\n    q = BN_CTX_get(ctx);\n    X = BN_CTX_get(ctx);\n    c = BN_CTX_get(ctx);\n    p = BN_CTX_get(ctx);\n    test = BN_CTX_get(ctx);\n    if (test == NULL)\n        goto err;\n    if (!BN_lshift(test, BN_value_one(), bits - 1))\n        goto err;\n    for (;;) {\n        for (;;) {\n            int use_random_seed = (seed_in == NULL);\n            if (!BN_GENCB_call(cb, 0, m++))\n                goto err;\n            if (use_random_seed) {\n                if (RAND_bytes(seed, qsize) <= 0)\n                    goto err;\n            } else {\n                seed_in = NULL;\n            }\n            memcpy(buf, seed, qsize);\n            memcpy(buf2, seed, qsize);\n            for (i = qsize - 1; i >= 0; i--) {\n                buf[i]++;\n                if (buf[i] != 0)\n                    break;\n            }\n            if (!EVP_Digest(seed, qsize, md, NULL, evpmd, NULL))\n                goto err;\n            if (!EVP_Digest(buf, qsize, buf2, NULL, evpmd, NULL))\n                goto err;\n            for (i = 0; i < qsize; i++)\n                md[i] ^= buf2[i];\n            md[0] |= 0x80;\n            md[qsize - 1] |= 0x01;\n            if (!BN_bin2bn(md, qsize, q))\n                goto err;\n            r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n                                        use_random_seed, cb);\n            if (r > 0)\n                break;\n            if (r != 0)\n                goto err;\n        }\n        if (!BN_GENCB_call(cb, 2, 0))\n            goto err;\n        if (!BN_GENCB_call(cb, 3, 0))\n            goto err;\n        counter = 0;\n        n = (bits - 1) / 160;\n        for (;;) {\n            if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))\n                goto err;\n            BN_zero(W);\n            for (k = 0; k <= n; k++) {\n                for (i = qsize - 1; i >= 0; i--) {\n                    buf[i]++;\n                    if (buf[i] != 0)\n                        break;\n                }\n                if (!EVP_Digest(buf, qsize, md, NULL, evpmd, NULL))\n                    goto err;\n                if (!BN_bin2bn(md, qsize, r0))\n                    goto err;\n                if (!BN_lshift(r0, r0, (qsize << 3) * k))\n                    goto err;\n                if (!BN_add(W, W, r0))\n                    goto err;\n            }\n            if (!BN_mask_bits(W, bits - 1))\n                goto err;\n            if (!BN_copy(X, W))\n                goto err;\n            if (!BN_add(X, X, test))\n                goto err;\n            if (!BN_lshift1(r0, q))\n                goto err;\n            if (!BN_mod(c, X, r0, ctx))\n                goto err;\n            if (!BN_sub(r0, c, BN_value_one()))\n                goto err;\n            if (!BN_sub(p, X, r0))\n                goto err;\n            if (BN_cmp(p, test) >= 0) {\n                r = BN_is_prime_fasttest_ex(p, DSS_prime_checks, ctx, 1, cb);\n                if (r > 0)\n                    goto end;\n                if (r != 0)\n                    goto err;\n            }\n            counter++;\n            if (counter >= 4096)\n                break;\n        }\n    }\n end:\n    if (!BN_GENCB_call(cb, 2, 1))\n        goto err;\n    if (!BN_sub(test, p, BN_value_one()))\n        goto err;\n    if (!BN_div(r0, NULL, test, q, ctx))\n        goto err;\n    if (!BN_set_word(test, h))\n        goto err;\n    if (!BN_MONT_CTX_set(mont, p, ctx))\n        goto err;\n    for (;;) {\n        if (!BN_mod_exp_mont(g, test, r0, p, ctx, mont))\n            goto err;\n        if (!BN_is_one(g))\n            break;\n        if (!BN_add(test, test, BN_value_one()))\n            goto err;\n        h++;\n    }\n    if (!BN_GENCB_call(cb, 3, 1))\n        goto err;\n    ok = 1;\n err:\n    if (ok) {\n        BN_free(ret->p);\n        BN_free(ret->q);\n        BN_free(ret->g);\n        ret->p = BN_dup(p);\n        ret->q = BN_dup(q);\n        ret->g = BN_dup(g);\n        if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {\n            ok = 0;\n            goto err;\n        }\n        if (counter_ret != NULL)\n            *counter_ret = counter;\n        if (h_ret != NULL)\n            *h_ret = h;\n        if (seed_out)\n            memcpy(seed_out, seed, qsize);\n    }\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    BN_MONT_CTX_free(mont);\n    return ok;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int i, nw, lb, rb;\n    BN_ULONG *t, *f;\n    BN_ULONG l;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (n < 0) {\n        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n        return 0;\n    }\n    r->neg = a->neg;\n    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return (0);\n    lb = n % BN_BITS2;\n    rb = BN_BITS2 - lb;\n    f = a->d;\n    t = r->d;\n    t[a->top + nw] = 0;\n    if (lb == 0)\n        for (i = a->top - 1; i >= 0; i--)\n            t[nw + i] = f[i];\n    else\n        for (i = a->top - 1; i >= 0; i--) {\n            l = f[i];\n            t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n            t[nw + i] = (l << lb) & BN_MASK2;\n        }\n    memset(t, 0, sizeof(*t) * nw);\n    r->top = a->top + nw + 1;\n    bn_correct_top(r);\n    bn_check_top(r);\n    return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']