crypto/bn/bn_mont.c:160: error: BUFFER_OVERRUN_S2
  Offset: [max(1, `mont->N.top`), +oo] (⇐ [0, +oo] + [max(1, `mont->N.top`), `mont->N.top`]) Size: [0, 8388607] by call to `BN_from_montgomery_word`.
Showing all 10 steps of the trace


crypto/bn/bn_mont.c:151:1: Parameter `mont->N.top`
149.   #endif                          /* MONT_WORD */
150.   
151. > int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
152.                          BN_CTX *ctx)
153.   {

crypto/bn/bn_mont.c:160:16: Call
158.       BN_CTX_start(ctx);
159.       if ((t = BN_CTX_get(ctx)) && BN_copy(t, a))
160.           retn = BN_from_montgomery_word(ret, t, mont);
                      ^
161.       BN_CTX_end(ctx);
162.   #else                           /* !MONT_WORD */

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

crypto/bn/bn_mont.c:112:21: Assignment
  110.        * includes |carry| which is stored separately.
  111.        */
  112.       for (carry = 0, i = 0; i < nl; i++, rp++) {
                             ^
  113.           v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
  114.           v = (v + carry + rp[nl]) & BN_MASK2;

crypto/bn/bn_mont.c:78:1: <Length trace>
76.   
77.   #ifdef MONT_WORD
78. > static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
79.   {
80.       BIGNUM *n;

crypto/bn/bn_mont.c:78:1: Parameter `*r->d`
  76.   
  77.   #ifdef MONT_WORD
  78. > static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
  79.   {
  80.       BIGNUM *n;

crypto/bn/bn_mont.c:92:9: Call
  90.   
  91.       max = (2 * nl);             /* carry is stored separately */
  92.       if (bn_wexpand(r, max) == NULL)
                ^
  93.           return 0;
  94.   

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_mont.c:97:5: Assignment
  95.       r->neg ^= n->neg;
  96.       np = n->d;
  97.       rp = r->d;
             ^
  98.   
  99.       /* clear the top words of T */

crypto/bn/bn_mont.c:114:26: Array access: Offset: [max(1, mont->N.top), +oo] (⇐ [0, +oo] + [max(1, mont->N.top), mont->N.top]) Size: [0, 8388607] by call to `BN_from_montgomery_word` 
  112.       for (carry = 0, i = 0; i < nl; i++, rp++) {
  113.           v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
  114.           v = (v + carry + rp[nl]) & BN_MASK2;
                                  ^
  115.           carry |= (v != rp[nl]);
  116.           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;
    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;
    i = max - r->top;
    if (i)
        memset(&rp[r->top], 0, sizeof(*rp) * i);
    r->top = max;
    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->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;
    }
    bn_correct_top(r);
    bn_correct_top(ret);
    bn_check_top(ret);
    return 1;
}
['int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n                       BN_CTX *ctx)\n{\n    int retn = 0;\n#ifdef MONT_WORD\n    BIGNUM *t;\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) && BN_copy(t, a))\n        retn = BN_from_montgomery_word(ret, t, mont);\n    BN_CTX_end(ctx);\n#else\n    BIGNUM *t1, *t2;\n    BN_CTX_start(ctx);\n    t1 = BN_CTX_get(ctx);\n    t2 = BN_CTX_get(ctx);\n    if (t2 == NULL)\n        goto err;\n    if (!BN_copy(t1, a))\n        goto err;\n    BN_mask_bits(t1, mont->ri);\n    if (!BN_mul(t2, t1, &mont->Ni, ctx))\n        goto err;\n    BN_mask_bits(t2, mont->ri);\n    if (!BN_mul(t1, t2, &mont->N, ctx))\n        goto err;\n    if (!BN_add(t2, a, t1))\n        goto err;\n    if (!BN_rshift(ret, t2, mont->ri))\n        goto err;\n    if (BN_ucmp(ret, &(mont->N)) >= 0) {\n        if (!BN_usub(ret, ret, &(mont->N)))\n            goto err;\n    }\n    retn = 1;\n    bn_check_top(ret);\n err:\n    BN_CTX_end(ctx);\n#endif\n    return retn;\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    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    i = max - r->top;\n    if (i)\n        memset(&rp[r->top], 0, sizeof(*rp) * i);\n    r->top = max;\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->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    bn_correct_top(r);\n    bn_correct_top(ret);\n    bn_check_top(ret);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']