crypto/bn/bn_mont.c:155: error: BUFFER_OVERRUN_S2
  Offset: [max(16, `a->top`), `a->top`] (⇐ 1 + [-1+max(16, `a->top`), `a->top` - 1]) Size: [0, 8388607] by call to `BN_sqr`.
Showing all 14 steps of the trace


crypto/bn/bn_mont.c:128:1: Parameter `a->top`
126.   #endif
127.   
128. > int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
129.                             BN_MONT_CTX *mont, BN_CTX *ctx)
130.   {

crypto/bn/bn_mont.c:155:14: Call
153.       bn_check_top(tmp);
154.       if (a == b) {
155.           if (!BN_sqr(tmp, a, ctx))
                    ^
156.               goto err;
157.       } else {

crypto/bn/bn_sqr.c:66:1: Parameter `a->top`
  64.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
  65.    */
  66. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
  67.   {
  68.       int max, al;

crypto/bn/bn_sqr.c:74:5: Assignment
  72.       bn_check_top(a);
  73.   
  74.       al = a->top;
            ^
  75.       if (al <= 0) {
  76.           r->top = 0;

crypto/bn/bn_sqr.c:123:17: Call
  121.                   if (bn_wexpand(tmp, max) == NULL)
  122.                       goto err;
  123.                   bn_sqr_normal(rr->d, a->d, al, tmp->d);
                         ^
  124.               }
  125.           }

crypto/bn/bn_sqr.c:153:1: <Offset trace>
151.   
152.   /* tmp must have 2*n words */
153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
154.   {
155.       int i, j, max;

crypto/bn/bn_sqr.c:153:1: Parameter `n`
    151.   
    152.   /* tmp must have 2*n words */
    153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
    154.   {
    155.       int i, j, max;

crypto/bn/bn_sqr.c:164:5: Assignment
    162.       rp[0] = rp[max - 1] = 0;
    163.       rp++;
    164.       j = n;
               ^
    165.   
    166.       if (--j > 0) {

crypto/bn/bn_sqr.c:166:9: Assignment
    164.       j = n;
    165.   
    166.       if (--j > 0) {
                   ^
    167.           ap++;
    168.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);

crypto/bn/bn_sqr.c:153:1: <Length trace>
151.   
152.   /* tmp must have 2*n words */
153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
154.   {
155.       int i, j, max;

crypto/bn/bn_sqr.c:153:1: Parameter `*r`
    151.   
    152.   /* tmp must have 2*n words */
    153. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
    154.   {
    155.       int i, j, max;

crypto/bn/bn_sqr.c:161:5: Assignment
    159.       max = n * 2;
    160.       ap = a;
    161.       rp = r;
               ^
    162.       rp[0] = rp[max - 1] = 0;
    163.       rp++;

crypto/bn/bn_sqr.c:163:5: Assignment
    161.       rp = r;
    162.       rp[0] = rp[max - 1] = 0;
    163.       rp++;
               ^
    164.       j = n;
    165.   

crypto/bn/bn_sqr.c:168:9: Array access: Offset: [max(16, a->top), a->top] (⇐ 1 + [-1+max(16, a->top), a->top - 1]) Size: [0, 8388607] by call to `BN_sqr` 
    166.       if (--j > 0) {
    167.           ap++;
    168.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
                   ^
    169.           rp += 2;
    170.       }

void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
    int i, j, max;
    const BN_ULONG *ap;
    BN_ULONG *rp;
    max = n * 2;
    ap = a;
    rp = r;
    rp[0] = rp[max - 1] = 0;
    rp++;
    j = n;
    if (--j > 0) {
        ap++;
        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    for (i = n - 2; i > 0; i--) {
        j--;
        ap++;
        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    bn_add_words(r, r, r, max);
    bn_sqr_words(tmp, a, n);
    bn_add_words(r, r, tmp, max);
}
['int BN_mod_mul_montgomery(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#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n    int num = mont->N.top;\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            bn_correct_top(r);\n            return (1);\n        }\n    }\n#endif\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(tmp, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(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    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (!rr || !tmp)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n        rr->top = max - 1;\n    else\n        rr->top = max;\n    if (rr != r)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    bn_check_top(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n    int i, j, max;\n    const BN_ULONG *ap;\n    BN_ULONG *rp;\n    max = n * 2;\n    ap = a;\n    rp = r;\n    rp[0] = rp[max - 1] = 0;\n    rp++;\n    j = n;\n    if (--j > 0) {\n        ap++;\n        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    for (i = n - 2; i > 0; i--) {\n        j--;\n        ap++;\n        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    bn_add_words(r, r, r, max);\n    bn_sqr_words(tmp, a, n);\n    bn_add_words(r, r, tmp, max);\n}']