crypto/bn/bn_blind.c:299: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] (⇐ [0, +oo] + [1, +oo]) Size: [0, 8388607] by call to `bn_to_mont_fixed_top`.
Showing all 14 steps of the trace


crypto/bn/bn_blind.c:233:1: Parameter `m_ctx->N.top`
231.   }
232.   
233. > BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
234.                                         const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
235.                                         int (*bn_mod_exp) (BIGNUM *r,

crypto/bn/bn_blind.c:299:14: Call
297.   
298.       if (ret->m_ctx != NULL) {
299.           if (!bn_to_mont_fixed_top(ret->Ai, ret->Ai, ret->m_ctx, ctx)
                    ^
300.               || !bn_to_mont_fixed_top(ret->A, ret->A, ret->m_ctx, ctx))
301.               goto err;

crypto/bn/bn_mont.c:222:1: Parameter `mont->N.top`
  220.   }
  221.   
  222. > int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,
  223.                            BN_CTX *ctx)
  224.   {

crypto/bn/bn_mont.c:225:12: Call
  223.                            BN_CTX *ctx)
  224.   {
  225.       return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);
                    ^
  226.   }
  227.   

crypto/bn/bn_mont.c:37:1: Parameter `mont->N.top`
    35.   }
    36.   
    37. > int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
    38.                             BN_MONT_CTX *mont, BN_CTX *ctx)
    39.   {

crypto/bn/bn_mont.c:75:10: Call
    73.       /* reduce from aRR to aR */
    74.   #ifdef MONT_WORD
    75.       if (!bn_from_montgomery_word(r, tmp, mont))
                   ^
    76.           goto err;
    77.   #else

crypto/bn/bn_mont.c:125:21: <Offset trace>
123.        * includes |carry| which is stored separately.
124.        */
125.       for (carry = 0, i = 0; i < nl; i++, rp++) {
                           ^
126.           v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
127.           v = (v + carry + rp[nl]) & BN_MASK2;

crypto/bn/bn_mont.c:125:21: Assignment
      123.        * includes |carry| which is stored separately.
      124.        */
      125.       for (carry = 0, i = 0; i < nl; i++, rp++) {
                                 ^
      126.           v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
      127.           v = (v + carry + rp[nl]) & BN_MASK2;

crypto/bn/bn_mont.c:88:1: <Length trace>
86.   
87.   #ifdef MONT_WORD
88. > static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
89.   {
90.       BIGNUM *n;

crypto/bn/bn_mont.c:88:1: Parameter `*r->d`
      86.   
      87.   #ifdef MONT_WORD
      88. > static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
      89.   {
      90.       BIGNUM *n;

crypto/bn/bn_mont.c:103:9: Call
      101.   
      102.       max = (2 * nl);             /* carry is stored separately */
      103.       if (bn_wexpand(r, max) == NULL)
                     ^
      104.           return 0;
      105.   

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

crypto/bn/bn_mont.c:108:5: Assignment
      106.       r->neg ^= n->neg;
      107.       np = n->d;
      108.       rp = r->d;
                 ^
      109.   
      110.       /* clear the top words of T */

crypto/bn/bn_mont.c:127:26: Array access: Offset: [1, +oo] (⇐ [0, +oo] + [1, +oo]) Size: [0, 8388607] by call to `bn_to_mont_fixed_top` 
      125.       for (carry = 0, i = 0; i < nl; i++, rp++) {
      126.           v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
      127.           v = (v + carry + rp[nl]) & BN_MASK2;
                                      ^
      128.           carry |= (v != rp[nl]);
      129.           carry &= (v <= rp[nl]);

static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
{
    BIGNUM *n;
    BN_ULONG *ap, *np, *rp, n0, v, carry;
    int nl, max, i;
    unsigned int rtop;
    n = &(mont->N);
    nl = n->top;
    if (nl == 0) {
        ret->top = 0;
        return 1;
    }
    max = (2 * nl);
    if (bn_wexpand(r, max) == NULL)
        return 0;
    r->neg ^= n->neg;
    np = n->d;
    rp = r->d;
    for (rtop = r->top, i = 0; i < max; i++) {
        v = (BN_ULONG)0 - ((i - rtop) >> (8 * sizeof(rtop) - 1));
        rp[i] &= v;
    }
    r->top = max;
    r->flags |= BN_FLG_FIXED_TOP;
    n0 = mont->n0[0];
    for (carry = 0, i = 0; i < nl; i++, rp++) {
        v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
        v = (v + carry + rp[nl]) & BN_MASK2;
        carry |= (v != rp[nl]);
        carry &= (v <= rp[nl]);
        rp[nl] = v;
    }
    if (bn_wexpand(ret, nl) == NULL)
        return 0;
    ret->top = nl;
    ret->flags |= BN_FLG_FIXED_TOP;
    ret->neg = r->neg;
    rp = ret->d;
    ap = &(r->d[nl]);
    carry -= bn_sub_words(rp, ap, np, nl);
    for (i = 0; i < nl; i++) {
        rp[i] = (carry & ap[i]) | (~carry & rp[i]);
        ap[i] = 0;
    }
    return 1;
}
['BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,\n                                      const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,\n                                      int (*bn_mod_exp) (BIGNUM *r,\n                                                         const BIGNUM *a,\n                                                         const BIGNUM *p,\n                                                         const BIGNUM *m,\n                                                         BN_CTX *ctx,\n                                                         BN_MONT_CTX *m_ctx),\n                                      BN_MONT_CTX *m_ctx)\n{\n    int retry_counter = 32;\n    BN_BLINDING *ret = NULL;\n    if (b == NULL)\n        ret = BN_BLINDING_new(NULL, NULL, m);\n    else\n        ret = b;\n    if (ret == NULL)\n        goto err;\n    if (ret->A == NULL && (ret->A = BN_new()) == NULL)\n        goto err;\n    if (ret->Ai == NULL && (ret->Ai = BN_new()) == NULL)\n        goto err;\n    if (e != NULL) {\n        BN_free(ret->e);\n        ret->e = BN_dup(e);\n    }\n    if (ret->e == NULL)\n        goto err;\n    if (bn_mod_exp != NULL)\n        ret->bn_mod_exp = bn_mod_exp;\n    if (m_ctx != NULL)\n        ret->m_ctx = m_ctx;\n    do {\n        int rv;\n        if (!BN_priv_rand_range(ret->A, ret->mod))\n            goto err;\n        if (int_bn_mod_inverse(ret->Ai, ret->A, ret->mod, ctx, &rv))\n            break;\n        if (!rv)\n            goto err;\n        if (retry_counter-- == 0) {\n            BNerr(BN_F_BN_BLINDING_CREATE_PARAM, BN_R_TOO_MANY_ITERATIONS);\n            goto err;\n        }\n    } while (1);\n    if (ret->bn_mod_exp != NULL && ret->m_ctx != NULL) {\n        if (!ret->bn_mod_exp(ret->A, ret->A, ret->e, ret->mod, ctx, ret->m_ctx))\n            goto err;\n    } else {\n        if (!BN_mod_exp(ret->A, ret->A, ret->e, ret->mod, ctx))\n            goto err;\n    }\n    if (ret->m_ctx != NULL) {\n        if (!bn_to_mont_fixed_top(ret->Ai, ret->Ai, ret->m_ctx, ctx)\n            || !bn_to_mont_fixed_top(ret->A, ret->A, ret->m_ctx, ctx))\n            goto err;\n    }\n    return ret;\n err:\n    if (b == NULL) {\n        BN_BLINDING_free(ret);\n        ret = NULL;\n    }\n    return ret;\n}', 'int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n                         BN_CTX *ctx)\n{\n    return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                          BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n    BIGNUM *tmp;\n    int ret = 0;\n    int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n    if (num > 1 && a->top == num && b->top == num) {\n        if (bn_wexpand(r, num) == NULL)\n            return 0;\n        if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n            r->neg = a->neg ^ b->neg;\n            r->top = num;\n            r->flags |= BN_FLG_FIXED_TOP;\n            return 1;\n        }\n    }\n#endif\n    if ((a->top + b->top) > 2 * num)\n        return 0;\n    BN_CTX_start(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (tmp == NULL)\n        goto err;\n    bn_check_top(tmp);\n    if (a == b) {\n        if (!bn_sqr_fixed_top(tmp, a, ctx))\n            goto err;\n    } else {\n        if (!bn_mul_fixed_top(tmp, a, b, ctx))\n            goto err;\n    }\n#ifdef MONT_WORD\n    if (!bn_from_montgomery_word(r, tmp, mont))\n        goto err;\n#else\n    if (!BN_from_montgomery(r, tmp, mont, ctx))\n        goto err;\n#endif\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n    BIGNUM *n;\n    BN_ULONG *ap, *np, *rp, n0, v, carry;\n    int nl, max, i;\n    unsigned int rtop;\n    n = &(mont->N);\n    nl = n->top;\n    if (nl == 0) {\n        ret->top = 0;\n        return 1;\n    }\n    max = (2 * nl);\n    if (bn_wexpand(r, max) == NULL)\n        return 0;\n    r->neg ^= n->neg;\n    np = n->d;\n    rp = r->d;\n    for (rtop = r->top, i = 0; i < max; i++) {\n        v = (BN_ULONG)0 - ((i - rtop) >> (8 * sizeof(rtop) - 1));\n        rp[i] &= v;\n    }\n    r->top = max;\n    r->flags |= BN_FLG_FIXED_TOP;\n    n0 = mont->n0[0];\n    for (carry = 0, i = 0; i < nl; i++, rp++) {\n        v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n        v = (v + carry + rp[nl]) & BN_MASK2;\n        carry |= (v != rp[nl]);\n        carry &= (v <= rp[nl]);\n        rp[nl] = v;\n    }\n    if (bn_wexpand(ret, nl) == NULL)\n        return 0;\n    ret->top = nl;\n    ret->flags |= BN_FLG_FIXED_TOP;\n    ret->neg = r->neg;\n    rp = ret->d;\n    ap = &(r->d[nl]);\n    carry -= bn_sub_words(rp, ap, np, nl);\n    for (i = 0; i < nl; i++) {\n        rp[i] = (carry & ap[i]) | (~carry & rp[i]);\n        ap[i] = 0;\n    }\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']