crypto/rsa/rsa_ossl.c:739: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_MONT_CTX_set_locked`.
Showing all 10 steps of the trace


crypto/rsa/rsa_ossl.c:700:1: Parameter `rsa->q->d`
698.   }
699.   
700. > static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
701.   {
702.       BIGNUM *r1, *m1, *vrfy;

crypto/rsa/rsa_ossl.c:739:21: Call
737.               if (!BN_MONT_CTX_set_locked
738.                   (&rsa->_method_mod_p, rsa->lock, p, ctx)
739.                   || !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,
                           ^
740.                                              rsa->lock, q, ctx)) {
741.                   BN_free(local_p);

crypto/bn/bn_mont.c:499:1: Parameter `*mod->d`
  497.   }
  498.   
  499. > BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,
  500.                                       const BIGNUM *mod, BN_CTX *ctx)
  501.   {

crypto/bn/bn_mont.c:521:10: Call
  519.       if (ret == NULL)
  520.           return NULL;
  521.       if (!BN_MONT_CTX_set(ret, mod, ctx)) {
                  ^
  522.           BN_MONT_CTX_free(ret);
  523.           return NULL;

crypto/bn/bn_mont.c:348:1: Parameter `*mod->d`
    346.   }
    347.   
    348. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
    349.   {
    350.       int ret = 0;

crypto/bn/bn_mont.c:360:10: Call
    358.           goto err;
    359.       R = &(mont->RR);            /* grab RR as a temp */
    360.       if (!BN_copy(&(mont->N), mod))
                    ^
    361.           goto err;               /* Set N */
    362.       mont->N.neg = 0;

crypto/bn/bn_lib.c:419:1: <Length trace>
417.   }
418.   
419. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
420.   {
421.       int i;

crypto/bn/bn_lib.c:419:1: Parameter `*b->d`
      417.   }
      418.   
      419. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      420.   {
      421.       int i;

crypto/bn/bn_lib.c:434:5: Assignment
      432.   #if 1
      433.       A = a->d;
      434.       B = b->d;
                 ^
      435.       for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
      436.           BN_ULONG a0, a1, a2, a3;

crypto/bn/bn_lib.c:440:14: Array access: Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_MONT_CTX_set_locked` 
      438.           a1 = B[1];
      439.           a2 = B[2];
      440.           a3 = B[3];
                          ^
      441.           A[0] = a0;
      442.           A[1] = a1;

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    int i;
    BN_ULONG *A;
    const BN_ULONG *B;
    bn_check_top(b);
    if (a == b)
        return (a);
    if (bn_wexpand(a, b->top) == NULL)
        return (NULL);
#if 1
    A = a->d;
    B = b->d;
    for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
        BN_ULONG a0, a1, a2, a3;
        a0 = B[0];
        a1 = B[1];
        a2 = B[2];
        a3 = B[3];
        A[0] = a0;
        A[1] = a1;
        A[2] = a2;
        A[3] = a3;
    }
    switch (b->top & 3) {
    case 3:
        A[2] = B[2];
    case 2:
        A[1] = B[1];
    case 1:
        A[0] = B[0];
    case 0:;
    }
#else
    memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
#endif
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return (a);
}
['static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)\n{\n    BIGNUM *r1, *m1, *vrfy;\n    int ret = 0;\n    BN_CTX_start(ctx);\n    r1 = BN_CTX_get(ctx);\n    m1 = BN_CTX_get(ctx);\n    vrfy = BN_CTX_get(ctx);\n    {\n        BIGNUM *local_p = NULL, *local_q = NULL;\n        BIGNUM *p = NULL, *q = NULL;\n        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n            local_p = p = BN_new();\n            if (p == NULL)\n                goto err;\n            BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n            local_q = q = BN_new();\n            if (q == NULL) {\n                BN_free(local_p);\n                goto err;\n            }\n            BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME);\n        } else {\n            p = rsa->p;\n            q = rsa->q;\n        }\n        if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) {\n            if (!BN_MONT_CTX_set_locked\n                (&rsa->_method_mod_p, rsa->lock, p, ctx)\n                || !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,\n                                           rsa->lock, q, ctx)) {\n                BN_free(local_p);\n                BN_free(local_q);\n                goto err;\n            }\n        }\n        BN_free(local_p);\n        BN_free(local_q);\n    }\n    if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n        if (!BN_MONT_CTX_set_locked\n            (&rsa->_method_mod_n, rsa->lock, rsa->n, ctx))\n            goto err;\n    {\n        BIGNUM *local_c = NULL;\n        const BIGNUM *c;\n        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n            local_c = BN_new();\n            if (local_c == NULL)\n                goto err;\n            BN_with_flags(local_c, I, BN_FLG_CONSTTIME);\n            c = local_c;\n        } else {\n            c = I;\n        }\n        if (!BN_mod(r1, c, rsa->q, ctx)) {\n            BN_free(local_c);\n            goto err;\n        }\n        {\n            BIGNUM *local_dmq1 = NULL, *dmq1;\n            if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n                dmq1 = local_dmq1 = BN_new();\n                if (local_dmq1 == NULL) {\n                    BN_free(local_c);\n                    goto err;\n                }\n                BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);\n            } else {\n                dmq1 = rsa->dmq1;\n            }\n            if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,\n                rsa->_method_mod_q)) {\n                BN_free(local_c);\n                BN_free(local_dmq1);\n                goto err;\n            }\n            BN_free(local_dmq1);\n        }\n        if (!BN_mod(r1, c, rsa->p, ctx)) {\n            BN_free(local_c);\n            goto err;\n        }\n        BN_free(local_c);\n    }\n    {\n        BIGNUM *local_dmp1 = NULL, *dmp1;\n        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n            dmp1 = local_dmp1 = BN_new();\n            if (local_dmp1 == NULL)\n                goto err;\n            BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);\n        } else {\n            dmp1 = rsa->dmp1;\n        }\n        if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,\n                                   rsa->_method_mod_p)) {\n            BN_free(local_dmp1);\n            goto err;\n        }\n        BN_free(local_dmp1);\n    }\n    if (!BN_sub(r0, r0, m1))\n        goto err;\n    if (BN_is_negative(r0))\n        if (!BN_add(r0, r0, rsa->p))\n            goto err;\n    if (!BN_mul(r1, r0, rsa->iqmp, ctx))\n        goto err;\n    {\n        BIGNUM *local_r1 = NULL, *pr1;\n        if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n            pr1 = local_r1 = BN_new();\n            if (local_r1 == NULL)\n                goto err;\n            BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);\n        } else {\n            pr1 = r1;\n        }\n        if (!BN_mod(r0, pr1, rsa->p, ctx)) {\n            BN_free(local_r1);\n            goto err;\n        }\n        BN_free(local_r1);\n    }\n    if (BN_is_negative(r0))\n        if (!BN_add(r0, r0, rsa->p))\n            goto err;\n    if (!BN_mul(r1, r0, rsa->q, ctx))\n        goto err;\n    if (!BN_add(r0, r1, m1))\n        goto err;\n    if (rsa->e && rsa->n) {\n        if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,\n                                   rsa->_method_mod_n))\n            goto err;\n        if (!BN_sub(vrfy, vrfy, I))\n            goto err;\n        if (!BN_mod(vrfy, vrfy, rsa->n, ctx))\n            goto err;\n        if (BN_is_negative(vrfy))\n            if (!BN_add(vrfy, vrfy, rsa->n))\n                goto err;\n        if (!BN_is_zero(vrfy)) {\n            BIGNUM *local_d = NULL;\n            BIGNUM *d = NULL;\n            if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n                local_d = d = BN_new();\n                if (d == NULL)\n                    goto err;\n                BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n            } else {\n                d = rsa->d;\n            }\n            if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,\n                                       rsa->_method_mod_n)) {\n                BN_free(local_d);\n                goto err;\n            }\n            BN_free(local_d);\n        }\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\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    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        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}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    int i;\n    BN_ULONG *A;\n    const BN_ULONG *B;\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 1\n    A = a->d;\n    B = b->d;\n    for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n        BN_ULONG a0, a1, a2, a3;\n        a0 = B[0];\n        a1 = B[1];\n        a2 = B[2];\n        a3 = B[3];\n        A[0] = a0;\n        A[1] = a1;\n        A[2] = a2;\n        A[3] = a3;\n    }\n    switch (b->top & 3) {\n    case 3:\n        A[2] = B[2];\n    case 2:\n        A[1] = B[1];\n    case 1:\n        A[0] = B[0];\n    case 0:;\n    }\n#else\n    memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return (a);\n}']