crypto/dsa/dsa_ossl.c:91: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `dsa_sign_setup`.
Showing all 17 steps of the trace


crypto/dsa/dsa_ossl.c:59:1: Parameter `dsa->p->top`
57.   }
58.   
59. > static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
60.   {
61.       BIGNUM *kinv = NULL;

crypto/dsa/dsa_ossl.c:91:10: Call
89.           goto err;
90.    redo:
91.       if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))
               ^
92.           goto err;
93.   

crypto/dsa/dsa_ossl.c:143:1: Parameter `dsa->p->top`
  141.   }
  142.   
  143. > static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,
  144.                             BIGNUM **kinvp, BIGNUM **rp,
  145.                             const unsigned char *dgst, int dlen)

crypto/dsa/dsa_ossl.c:194:14: Call
  192.   
  193.       if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {
  194.           if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,
                      ^
  195.                                       dsa->lock, dsa->p, ctx))
  196.               goto err;

crypto/bn/bn_mont.c:403:1: Parameter `mod->top`
    401.   }
    402.   
    403. > BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,
    404.                                       const BIGNUM *mod, BN_CTX *ctx)
    405.   {

crypto/bn/bn_mont.c:425:10: Call
    423.       if (ret == NULL)
    424.           return NULL;
    425.       if (!BN_MONT_CTX_set(ret, mod, ctx)) {
                    ^
    426.           BN_MONT_CTX_free(ret);
    427.           return NULL;

crypto/bn/bn_mont.c:247:1: Parameter `mod->top`
      245.   }
      246.   
      247. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
      248.   {
      249.       int ret = 0;

crypto/bn/bn_mont.c:252:9: Call
      250.       BIGNUM *Ri, *R;
      251.   
      252.       if (BN_is_zero(mod))
                     ^
      253.           return 0;
      254.   

crypto/bn/bn_lib.c:841:1: Parameter `a->top`
        839.   }
        840.   
        841. > int BN_is_zero(const BIGNUM *a)
        842.   {
        843.       return a->top == 0;

crypto/bn/bn_mont.c:259:10: Call
      257.           goto err;
      258.       R = &(mont->RR);            /* grab RR as a temp */
      259.       if (!BN_copy(&(mont->N), mod))
                      ^
      260.           goto err;               /* Set N */
      261.       if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)

crypto/bn/bn_lib.c:312:1: <Offset trace>
310.   }
311.   
312. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
313.   {
314.       bn_check_top(b);

crypto/bn/bn_lib.c:312:1: Parameter `b->top`
        310.   }
        311.   
        312. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
        313.   {
        314.       bn_check_top(b);

crypto/bn/bn_lib.c:312:1: <Length trace>
310.   }
311.   
312. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
313.   {
314.       bn_check_top(b);

crypto/bn/bn_lib.c:312:1: Parameter `*a->d`
        310.   }
        311.   
        312. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
        313.   {
        314.       bn_check_top(b);

crypto/bn/bn_lib.c:318:9: Call
        316.       if (a == b)
        317.           return a;
        318.       if (bn_wexpand(a, b->top) == NULL)
                       ^
        319.           return NULL;
        320.   

crypto/bn/bn_lib.c:937:1: Parameter `*a->d`
          935.   }
          936.   
          937. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
          938.   {
          939.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:322:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `dsa_sign_setup` 
        320.   
        321.       if (b->top > 0)
        322.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                       ^
        323.   
        324.       a->top = b->top;

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return a;
}
['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n    BIGNUM *kinv = NULL;\n    BIGNUM *m;\n    BIGNUM *xr;\n    BN_CTX *ctx = NULL;\n    int reason = ERR_R_BN_LIB;\n    DSA_SIG *ret = NULL;\n    int rv = 0;\n    m = BN_new();\n    xr = BN_new();\n    if (m == NULL || xr == NULL)\n        goto err;\n    if (!dsa->p || !dsa->q || !dsa->g) {\n        reason = DSA_R_MISSING_PARAMETERS;\n        goto err;\n    }\n    ret = DSA_SIG_new();\n    if (ret == NULL)\n        goto err;\n    ret->r = BN_new();\n    ret->s = BN_new();\n    if (ret->r == NULL || ret->s == NULL)\n        goto err;\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        goto err;\n redo:\n    if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n        goto err;\n    if (dlen > BN_num_bytes(dsa->q))\n        dlen = BN_num_bytes(dsa->q);\n    if (BN_bin2bn(dgst, dlen, m) == NULL)\n        goto err;\n    if (!BN_mod_mul(xr, dsa->priv_key, ret->r, dsa->q, ctx))\n        goto err;\n    if (!BN_add(ret->s, xr, m))\n        goto err;\n    if (BN_cmp(ret->s, dsa->q) > 0)\n        if (!BN_sub(ret->s, ret->s, dsa->q))\n            goto err;\n    if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n        goto err;\n    if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n        goto redo;\n    rv = 1;\n err:\n    if (rv == 0) {\n        DSAerr(DSA_F_DSA_DO_SIGN, reason);\n        DSA_SIG_free(ret);\n        ret = NULL;\n    }\n    BN_CTX_free(ctx);\n    BN_clear_free(m);\n    BN_clear_free(xr);\n    BN_clear_free(kinv);\n    return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n                          BIGNUM **kinvp, BIGNUM **rp,\n                          const unsigned char *dgst, int dlen)\n{\n    BN_CTX *ctx = NULL;\n    BIGNUM *k, *kinv = NULL, *r = *rp;\n    BIGNUM *l, *m;\n    int ret = 0;\n    int q_bits;\n    if (!dsa->p || !dsa->q || !dsa->g) {\n        DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n        return 0;\n    }\n    k = BN_new();\n    l = BN_new();\n    m = BN_new();\n    if (k == NULL || l == NULL || m == NULL)\n        goto err;\n    if (ctx_in == NULL) {\n        if ((ctx = BN_CTX_new()) == NULL)\n            goto err;\n    } else\n        ctx = ctx_in;\n    q_bits = BN_num_bits(dsa->q);\n    if (!BN_set_bit(k, q_bits)\n        || !BN_set_bit(l, q_bits)\n        || !BN_set_bit(m, q_bits))\n        goto err;\n    do {\n        if (dgst != NULL) {\n            if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n                                       dlen, ctx))\n                goto err;\n        } else if (!BN_priv_rand_range(k, dsa->q))\n            goto err;\n    } while (BN_is_zero(k));\n    BN_set_flags(k, BN_FLG_CONSTTIME);\n    if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n        if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n                                    dsa->lock, dsa->p, ctx))\n            goto err;\n    }\n    if (!BN_add(l, k, dsa->q)\n        || !BN_add(m, l, dsa->q)\n        || !BN_copy(k, BN_num_bits(l) > q_bits ? l : m))\n        goto err;\n    if ((dsa)->meth->bn_mod_exp != NULL) {\n            if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n                                       dsa->method_mont_p))\n                goto err;\n    } else {\n            if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n                goto err;\n    }\n    if (!BN_mod(r, r, dsa->q, ctx))\n        goto err;\n    if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n        goto err;\n    BN_clear_free(*kinvp);\n    *kinvp = kinv;\n    kinv = NULL;\n    ret = 1;\n err:\n    if (!ret)\n        DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n    if (ctx != ctx_in)\n        BN_CTX_free(ctx);\n    BN_clear_free(k);\n    BN_clear_free(l);\n    BN_clear_free(m);\n    return ret;\n}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,\n                                    const BIGNUM *mod, BN_CTX *ctx)\n{\n    BN_MONT_CTX *ret;\n    CRYPTO_THREAD_read_lock(lock);\n    ret = *pmont;\n    CRYPTO_THREAD_unlock(lock);\n    if (ret)\n        return ret;\n    ret = BN_MONT_CTX_new();\n    if (ret == NULL)\n        return NULL;\n    if (!BN_MONT_CTX_set(ret, mod, ctx)) {\n        BN_MONT_CTX_free(ret);\n        return NULL;\n    }\n    CRYPTO_THREAD_write_lock(lock);\n    if (*pmont) {\n        BN_MONT_CTX_free(ret);\n        ret = *pmont;\n    } else\n        *pmont = ret;\n    CRYPTO_THREAD_unlock(lock);\n    return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n    int ret = 0;\n    BIGNUM *Ri, *R;\n    if (BN_is_zero(mod))\n        return 0;\n    BN_CTX_start(ctx);\n    if ((Ri = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    R = &(mont->RR);\n    if (!BN_copy(&(mont->N), mod))\n        goto err;\n    if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n        BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n    mont->N.neg = 0;\n#ifdef MONT_WORD\n    {\n        BIGNUM tmod;\n        BN_ULONG buf[2];\n        bn_init(&tmod);\n        tmod.d = buf;\n        tmod.dmax = 2;\n        tmod.neg = 0;\n        if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n            BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n        mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n        BN_zero(R);\n        if (!(BN_set_bit(R, 2 * BN_BITS2)))\n            goto err;\n        tmod.top = 0;\n        if ((buf[0] = mod->d[0]))\n            tmod.top = 1;\n        if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n            tmod.top = 2;\n        if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n            goto err;\n        if (!BN_is_zero(Ri)) {\n            if (!BN_sub_word(Ri, 1))\n                goto err;\n        } else {\n            if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n                goto err;\n            Ri->neg = 0;\n            Ri->d[0] = BN_MASK2;\n            Ri->d[1] = BN_MASK2;\n            Ri->top = 2;\n        }\n        if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n            goto err;\n        mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n        mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n        BN_zero(R);\n        if (!(BN_set_bit(R, BN_BITS2)))\n            goto err;\n        buf[0] = mod->d[0];\n        buf[1] = 0;\n        tmod.top = buf[0] != 0 ? 1 : 0;\n        if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, BN_BITS2))\n            goto err;\n        if (!BN_is_zero(Ri)) {\n            if (!BN_sub_word(Ri, 1))\n                goto err;\n        } else {\n            if (!BN_set_word(Ri, BN_MASK2))\n                goto err;\n        }\n        if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n            goto err;\n        mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n        mont->n0[1] = 0;\n# endif\n    }\n#else\n    {\n        mont->ri = BN_num_bits(&mont->N);\n        BN_zero(R);\n        if (!BN_set_bit(R, mont->ri))\n            goto err;\n        if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, mont->ri))\n            goto err;\n        if (!BN_sub_word(Ri, 1))\n            goto err;\n        if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n            goto err;\n    }\n#endif\n    BN_zero(&(mont->RR));\n    if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n        goto err;\n    if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\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 (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']