crypto/dsa/dsa_gen.c:115: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_lshift`.
Showing all 16 steps of the trace


crypto/dsa/dsa_gen.c:103:10: Call
101.       BN_CTX_start(ctx);
102.   
103.       r0 = BN_CTX_get(ctx);
                ^
104.       g = BN_CTX_get(ctx);
105.       W = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:229:5: Call
  227.       }
  228.       /* OK, make sure the returned bignum is "zero" */
  229.       BN_zero(ret);
             ^
  230.       ctx->used++;
  231.       CTXDBG_RET(ctx, ret);

crypto/bn/bn_lib.c:365:15: Assignment
    363.       a->neg = 0;
    364.       a->d[0] = w;
    365.       a->top = (w ? 1 : 0);
                         ^
    366.       a->flags &= ~BN_FLG_FIXED_TOP;
    367.       bn_check_top(a);

crypto/bn/bn_lib.c:365:5: Assignment
    363.       a->neg = 0;
    364.       a->d[0] = w;
    365.       a->top = (w ? 1 : 0);
               ^
    366.       a->flags &= ~BN_FLG_FIXED_TOP;
    367.       bn_check_top(a);

crypto/dsa/dsa_gen.c:115:10: Call
113.           goto err;
114.   
115.       if (!BN_lshift(test, BN_value_one(), bits - 1))
                ^
116.           goto err;
117.   

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

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

crypto/bn/bn_lib.c:942:1: Parameter `*a->d`
    940.   }
    941.   
    942. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    943.   {
    944.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:944:37: Call
    942.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    943.   {
    944.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                               ^
    945.   }
    946.   

crypto/bn/bn_lib.c:244:1: Parameter `*b->d`
      242.    */
      243.   
      244. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      245.   {
      246.       if (words > b->dmax) {

crypto/bn/bn_lib.c:247:23: Call
      245.   {
      246.       if (words > b->dmax) {
      247.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      248.           if (!a)
      249.               return NULL;

crypto/bn/bn_lib.c:208:1: <Offset trace>
206.   /* This is used by bn_expand2() */
207.   /* The caller MUST check that words > b->dmax before calling this */
208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
209.   {
210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:208:1: Parameter `b->top`
        206.   /* This is used by bn_expand2() */
        207.   /* The caller MUST check that words > b->dmax before calling this */
        208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        209.   {
        210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:208:1: <Length trace>
206.   /* This is used by bn_expand2() */
207.   /* The caller MUST check that words > b->dmax before calling this */
208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
209.   {
210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:208:1: Parameter `*b->d`
        206.   /* This is used by bn_expand2() */
        207.   /* The caller MUST check that words > b->dmax before calling this */
        208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        209.   {
        210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:231:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_lshift` 
        229.       assert(b->top <= words);
        230.       if (b->top > 0)
        231.           memcpy(a, b->d, sizeof(*a) * b->top);
                       ^
        232.   
        233.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['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        if (qsize == SHA_DIGEST_LENGTH)\n            evpmd = EVP_sha1();\n        else if (qsize == SHA224_DIGEST_LENGTH)\n            evpmd = EVP_sha224();\n        else\n            evpmd = EVP_sha256();\n    } else {\n        qsize = EVP_MD_size(evpmd);\n    }\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            DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN, DSA_R_SEED_LEN_SMALL);\n            return 0;\n        }\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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\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    a->flags &= ~BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return 1;\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    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return 0;\n    r->neg = a->neg;\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}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}']