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


crypto/dsa/dsa_ossl.c:280:1: Parameter `dsa->p->top`
278.   }
279.   
280. > static int dsa_do_verify(const unsigned char *dgst, int dgst_len,
281.                            DSA_SIG *sig, DSA *dsa)
282.   {

crypto/dsa/dsa_ossl.c:300:9: Call
298.       }
299.   
300.       if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
               ^
301.           DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE);
302.           return -1;

crypto/bn/bn_lib.c:140:9: Call
  138.       bn_check_top(a);
  139.   
  140.       if (BN_is_zero(a))
                 ^
  141.           return 0;
  142.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:853:1: Parameter `a->top`
    851.   }
    852.   
    853. > int BN_is_zero(const BIGNUM *a)
    854.   {
    855.       return a->top == 0;

crypto/dsa/dsa_ossl.c:350:16: Call
348.   
349.       if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {
350.           mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,
                      ^
351.                                         dsa->lock, dsa->p, ctx);
352.           if (!mont)

crypto/bn/bn_mont.c:416:1: Parameter `mod->top`
  414.   }
  415.   
  416. > BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,
  417.                                       const BIGNUM *mod, BN_CTX *ctx)
  418.   {

crypto/bn/bn_mont.c:438:10: Call
  436.       if (ret == NULL)
  437.           return NULL;
  438.       if (!BN_MONT_CTX_set(ret, mod, ctx)) {
                  ^
  439.           BN_MONT_CTX_free(ret);
  440.           return NULL;

crypto/bn/bn_mont.c:251:1: Parameter `mod->top`
    249.   }
    250.   
    251. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
    252.   {
    253.       int i, ret = 0;

crypto/bn/bn_mont.c:256:9: Call
    254.       BIGNUM *Ri, *R;
    255.   
    256.       if (BN_is_zero(mod))
                   ^
    257.           return 0;
    258.   

crypto/bn/bn_lib.c:853:1: Parameter `a->top`
      851.   }
      852.   
      853. > int BN_is_zero(const BIGNUM *a)
      854.   {
      855.       return a->top == 0;

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

crypto/bn/bn_lib.c:281:1: <Offset trace>
279.   }
280.   
281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
282.   {
283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: Parameter `b->top`
      279.   }
      280.   
      281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      282.   {
      283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: <Length trace>
279.   }
280.   
281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
282.   {
283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: Parameter `*a->d`
      279.   }
      280.   
      281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      282.   {
      283.       bn_check_top(b);

crypto/bn/bn_lib.c:287:9: Call
      285.       if (a == b)
      286.           return a;
      287.       if (bn_wexpand(a, b->top) == NULL)
                     ^
      288.           return NULL;
      289.   

crypto/bn/bn_lib.c:949:1: Parameter `*a->d`
        947.   }
        948.   
        949. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
        950.   {
        951.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:291:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_MONT_CTX_set_locked` 
      289.   
      290.       if (b->top > 0)
      291.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                     ^
      292.   
      293.       a->neg = b->neg;

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->neg = b->neg;
    a->top = b->top;
    a->flags |= b->flags & BN_FLG_FIXED_TOP;
    bn_check_top(a);
    return a;
}
['static int dsa_do_verify(const unsigned char *dgst, int dgst_len,\n                         DSA_SIG *sig, DSA *dsa)\n{\n    BN_CTX *ctx;\n    BIGNUM *u1, *u2, *t1;\n    BN_MONT_CTX *mont = NULL;\n    const BIGNUM *r, *s;\n    int ret = -1, i;\n    if (!dsa->p || !dsa->q || !dsa->g) {\n        DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS);\n        return -1;\n    }\n    i = BN_num_bits(dsa->q);\n    if (i != 160 && i != 224 && i != 256) {\n        DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE);\n        return -1;\n    }\n    if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {\n        DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE);\n        return -1;\n    }\n    u1 = BN_new();\n    u2 = BN_new();\n    t1 = BN_new();\n    ctx = BN_CTX_new();\n    if (u1 == NULL || u2 == NULL || t1 == NULL || ctx == NULL)\n        goto err;\n    DSA_SIG_get0(sig, &r, &s);\n    if (BN_is_zero(r) || BN_is_negative(r) ||\n        BN_ucmp(r, dsa->q) >= 0) {\n        ret = 0;\n        goto err;\n    }\n    if (BN_is_zero(s) || BN_is_negative(s) ||\n        BN_ucmp(s, dsa->q) >= 0) {\n        ret = 0;\n        goto err;\n    }\n    if ((BN_mod_inverse(u2, s, dsa->q, ctx)) == NULL)\n        goto err;\n    if (dgst_len > (i >> 3))\n        dgst_len = (i >> 3);\n    if (BN_bin2bn(dgst, dgst_len, u1) == NULL)\n        goto err;\n    if (!BN_mod_mul(u1, u1, u2, dsa->q, ctx))\n        goto err;\n    if (!BN_mod_mul(u2, r, u2, dsa->q, ctx))\n        goto err;\n    if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n        mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n                                      dsa->lock, dsa->p, ctx);\n        if (!mont)\n            goto err;\n    }\n    if (dsa->meth->dsa_mod_exp != NULL) {\n        if (!dsa->meth->dsa_mod_exp(dsa, t1, dsa->g, u1, dsa->pub_key, u2,\n                                    dsa->p, ctx, mont))\n            goto err;\n    } else {\n        if (!BN_mod_exp2_mont(t1, dsa->g, u1, dsa->pub_key, u2, dsa->p, ctx,\n                              mont))\n            goto err;\n    }\n    if (!BN_mod(u1, t1, dsa->q, ctx))\n        goto err;\n    ret = (BN_ucmp(u1, r) == 0);\n err:\n    if (ret < 0)\n        DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB);\n    BN_CTX_free(ctx);\n    BN_free(u1);\n    BN_free(u2);\n    BN_free(t1);\n    return ret;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\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 i, 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_is_one(&tmod))\n            BN_zero(Ri);\n        else 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_is_one(&tmod))\n            BN_zero(Ri);\n        else 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    for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n        mont->RR.d[i] = 0;\n    mont->RR.top = ret;\n    mont->RR.flags |= BN_FLG_FIXED_TOP;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\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->neg = b->neg;\n    a->top = b->top;\n    a->flags |= b->flags & BN_FLG_FIXED_TOP;\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}']