test/bntest.c:1202: error: BUFFER_OVERRUN_L3
  Offset: [31, +oo] Size: [0, 8388607] by call to `BN_exp`.
Showing all 16 steps of the trace


test/bntest.c:1196:5: Call
1194.       e = BN_new();
1195.       one = BN_new();
1196.       BN_one(one);
            ^
1197.   
1198.       for (i = 0; i < num2; i++) {

crypto/bn/bn_lib.c:530:1: Parameter `*a->d`
  528.   }
  529.   
  530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
  531.   {
  532.       bn_check_top(a);

test/bntest.c:1202:13: Call
1200.           BN_bntest_rand(b, 2 + i, 0, 0);
1201.   
1202.           if (BN_exp(d, a, b, ctx) <= 0)
                    ^
1203.               return (0);
1204.   

crypto/bn/bn_exp.c:162:9: Call
  160.           goto err;
  161.   
  162.       if (BN_copy(v, a) == NULL)
                 ^
  163.           goto err;
  164.       bits = BN_num_bits(p);

crypto/bn/bn_lib.c:429:1: Parameter `a->top`
    427.   }
    428.   
    429. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    430.   {
    431.       int i;

crypto/bn/bn_exp.c:175:14: Call
  173.   
  174.       for (i = 1; i < bits; i++) {
  175.           if (!BN_sqr(v, v, ctx))
                      ^
  176.               goto err;
  177.           if (BN_is_bit_set(p, i)) {

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:159:5: Assignment
      157.       BN_ULONG *rp;
      158.   
      159.       max = n * 2;
                 ^
      160.       ap = a;
      161.       rp = r;

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:162:13: Array access: Offset: [31, +oo] Size: [0, 8388607] by call to `BN_exp` 
      160.       ap = a;
      161.       rp = r;
      162.       rp[0] = rp[max - 1] = 0;
                         ^
      163.       rp++;
      164.       j = n;

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 test_exp(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *b, *d, *e, *one;\n    int i;\n    a = BN_new();\n    b = BN_new();\n    d = BN_new();\n    e = BN_new();\n    one = BN_new();\n    BN_one(one);\n    for (i = 0; i < num2; i++) {\n        BN_bntest_rand(a, 20 + i * 5, 0, 0);\n        BN_bntest_rand(b, 2 + i, 0, 0);\n        if (BN_exp(d, a, b, ctx) <= 0)\n            return (0);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " ^ ");\n                BN_print(bp, b);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, d);\n            BIO_puts(bp, "\\n");\n        }\n        BN_one(e);\n        for (; !BN_is_zero(b); BN_sub(b, b, one))\n            BN_mul(e, e, a, ctx);\n        BN_sub(e, e, d);\n        if (!BN_is_zero(e)) {\n            fprintf(stderr, "Exponentiation test failed!\\n");\n            return 0;\n        }\n    }\n    BN_free(a);\n    BN_free(b);\n    BN_free(d);\n    BN_free(e);\n    BN_free(one);\n    return (1);\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}', 'int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n    int i, bits, ret = 0;\n    BIGNUM *v, *rr;\n    if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n        BNerr(BN_F_BN_EXP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return -1;\n    }\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == p))\n        rr = BN_CTX_get(ctx);\n    else\n        rr = r;\n    v = BN_CTX_get(ctx);\n    if (rr == NULL || v == NULL)\n        goto err;\n    if (BN_copy(v, a) == NULL)\n        goto err;\n    bits = BN_num_bits(p);\n    if (BN_is_odd(p)) {\n        if (BN_copy(rr, a) == NULL)\n            goto err;\n    } else {\n        if (!BN_one(rr))\n            goto err;\n    }\n    for (i = 1; i < bits; i++) {\n        if (!BN_sqr(v, v, ctx))\n            goto err;\n        if (BN_is_bit_set(p, i)) {\n            if (!BN_mul(rr, rr, v, ctx))\n                goto err;\n        }\n    }\n    if (r != rr)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(r);\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}', '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}']