test/ectest.c:181: error: BUFFER_OVERRUN_L3
  Offset: [4, +oo] (⇐ [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul`.
Showing all 10 steps of the trace


test/ectest.c:130:10: Call
128.       fprintf(stdout, "verify group order ...");
129.       fflush(stdout);
130.       if (!EC_GROUP_get_order(group, order, ctx))
                ^
131.           ABORT;
132.       if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx))

crypto/ec/ec_lib.c:350:1: Parameter `order->d`
  348.   }
  349.   
  350. > int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
  351.   {
  352.       if (group->order == NULL)

test/ectest.c:181:14: Call
179.   
180.           /* n2 = (1 - order) * (1 + order) = 1 - order^2 */
181.           if (!BN_mul(n2, n1, n2, ctx))
                    ^
182.               ABORT;
183.           if (!EC_POINT_mul(group, Q, NULL, P, n2, ctx))

crypto/bn/bn_mul.c:882:1: Parameter `*b->d`
  880.   #endif                          /* BN_RECURSION */
  881.   
  882. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  883.   {
  884.       int ret = 0;

crypto/bn/bn_mul.c:963:17: Call
  961.                   if (bn_wexpand(rr, k * 4) == NULL)
  962.                       goto err;
  963.                   bn_mul_part_recursive(rr->d, a->d, b->d,
                         ^
  964.                                         j, al - j, bl - j, t->d);
  965.               } else {            /* al <= j || bl <= j */

crypto/bn/bn_mul.c:533:1: Parameter `*b`
    531.    */
    532.   /* tnX may not be negative but less than n */
    533. > void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
    534.                              int tna, int tnb, BN_ULONG *t)
    535.   {

crypto/bn/bn_mul.c:541:9: Call
    539.   
    540.       if (n < 8) {
    541.           bn_mul_normal(r, a, n + tna, b, n + tnb);
                   ^
    542.           return;
    543.       }

crypto/bn/bn_mul.c:1036:1: <Length trace>
1034.   }
1035.   
1036. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
1037.   {
1038.       BN_ULONG *rr;

crypto/bn/bn_mul.c:1036:1: Parameter `*b`
      1034.   }
      1035.   
      1036. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
      1037.   {
      1038.       BN_ULONG *rr;

crypto/bn/bn_mul.c:1071:50: Array access: Offset: [4, +oo] (⇐ [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul` 
      1069.           if (--nb <= 0)
      1070.               return;
      1071.           rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
                                                               ^
      1072.           rr += 4;
      1073.           r += 4;

void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
{
    BN_ULONG *rr;
    if (na < nb) {
        int itmp;
        BN_ULONG *ltmp;
        itmp = na;
        na = nb;
        nb = itmp;
        ltmp = a;
        a = b;
        b = ltmp;
    }
    rr = &(r[na]);
    if (nb <= 0) {
        (void)bn_mul_words(r, a, na, 0);
        return;
    } else
        rr[0] = bn_mul_words(r, a, na, b[0]);
    for (;;) {
        if (--nb <= 0)
            return;
        rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);
        if (--nb <= 0)
            return;
        rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);
        if (--nb <= 0)
            return;
        rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);
        if (--nb <= 0)
            return;
        rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
        rr += 4;
        r += 4;
        b += 4;
    }
}
['static void group_order_tests(EC_GROUP *group)\n{\n    BIGNUM *n1, *n2, *order;\n    EC_POINT *P = EC_POINT_new(group);\n    EC_POINT *Q = EC_POINT_new(group);\n    BN_CTX *ctx = BN_CTX_new();\n    int i;\n    n1 = BN_new();\n    n2 = BN_new();\n    order = BN_new();\n    fprintf(stdout, "verify group order ...");\n    fflush(stdout);\n    if (!EC_GROUP_get_order(group, order, ctx))\n        ABORT;\n    if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx))\n        ABORT;\n    if (!EC_POINT_is_at_infinity(group, Q))\n        ABORT;\n    fprintf(stdout, ".");\n    fflush(stdout);\n    if (!EC_GROUP_precompute_mult(group, ctx))\n        ABORT;\n    if (!EC_POINT_mul(group, Q, order, NULL, NULL, ctx))\n        ABORT;\n    if (!EC_POINT_is_at_infinity(group, Q))\n        ABORT;\n    fprintf(stdout, " ok\\n");\n    fprintf(stdout, "long/negative scalar tests ");\n    for (i = 1; i <= 2; i++) {\n        const BIGNUM *scalars[6];\n        const EC_POINT *points[6];\n        fprintf(stdout, i == 1 ?\n                "allowing precomputation ... " :\n                "without precomputation ... ");\n        if (!BN_set_word(n1, i))\n            ABORT;\n        if (!EC_POINT_mul(group, P, n1, NULL, NULL, ctx))\n            ABORT;\n        if (!BN_one(n1))\n            ABORT;\n        if (!BN_sub(n1, n1, order))\n            ABORT;\n        if (!EC_POINT_mul(group, Q, NULL, P, n1, ctx))\n            ABORT;\n        if (0 != EC_POINT_cmp(group, Q, P, ctx))\n            ABORT;\n        if (!BN_add(n2, order, BN_value_one()))\n            ABORT;\n        if (!EC_POINT_mul(group, Q, NULL, P, n2, ctx))\n            ABORT;\n        if (0 != EC_POINT_cmp(group, Q, P, ctx))\n            ABORT;\n        if (!BN_mul(n2, n1, n2, ctx))\n            ABORT;\n        if (!EC_POINT_mul(group, Q, NULL, P, n2, ctx))\n            ABORT;\n        if (0 != EC_POINT_cmp(group, Q, P, ctx))\n            ABORT;\n        BN_set_negative(n2, 0);\n        if (!EC_POINT_mul(group, Q, NULL, P, n2, ctx))\n            ABORT;\n        if (!EC_POINT_add(group, Q, Q, P, ctx))\n            ABORT;\n        if (!EC_POINT_is_at_infinity(group, Q))\n            ABORT;\n        if (EC_POINT_is_at_infinity(group, P))\n            ABORT;\n        scalars[0] = n1;\n        points[0] = Q;\n        scalars[1] = n2;\n        points[1] = P;\n        scalars[2] = n1;\n        points[2] = Q;\n        scalars[3] = n2;\n        points[3] = Q;\n        scalars[4] = n1;\n        points[4] = P;\n        scalars[5] = n2;\n        points[5] = Q;\n        if (!EC_POINTs_mul(group, P, NULL, 6, points, scalars, ctx))\n            ABORT;\n        if (!EC_POINT_is_at_infinity(group, P))\n            ABORT;\n    }\n    fprintf(stdout, "ok\\n");\n    EC_POINT_free(P);\n    EC_POINT_free(Q);\n    BN_free(n1);\n    BN_free(n2);\n    BN_free(order);\n    BN_CTX_free(ctx);\n}', 'int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)\n{\n    if (group->order == NULL)\n        return 0;\n    if (!BN_copy(order, group->order))\n        return 0;\n    return !BN_is_zero(order);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = 0;\n    int top, al, bl;\n    BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    int i;\n#endif\n#ifdef BN_RECURSION\n    BIGNUM *t = NULL;\n    int j = 0, k;\n#endif\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(r);\n    al = a->top;\n    bl = b->top;\n    if ((al == 0) || (bl == 0)) {\n        BN_zero(r);\n        return (1);\n    }\n    top = al + bl;\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == b)) {\n        if ((rr = BN_CTX_get(ctx)) == NULL)\n            goto err;\n    } else\n        rr = r;\n    rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n    if (i == 0) {\n# if 0\n        if (al == 4) {\n            if (bn_wexpand(rr, 8) == NULL)\n                goto err;\n            rr->top = 8;\n            bn_mul_comba4(rr->d, a->d, b->d);\n            goto end;\n        }\n# endif\n        if (al == 8) {\n            if (bn_wexpand(rr, 16) == NULL)\n                goto err;\n            rr->top = 16;\n            bn_mul_comba8(rr->d, a->d, b->d);\n            goto end;\n        }\n    }\n#endif\n#ifdef BN_RECURSION\n    if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n        if (i >= -1 && i <= 1) {\n            if (i >= 0) {\n                j = BN_num_bits_word((BN_ULONG)al);\n            }\n            if (i == -1) {\n                j = BN_num_bits_word((BN_ULONG)bl);\n            }\n            j = 1 << (j - 1);\n            assert(j <= al || j <= bl);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (t == NULL)\n                goto err;\n            if (al > j || bl > j) {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d,\n                                      j, al - j, bl - j, t->d);\n            } else {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n# if 0\n        if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n            BIGNUM *tmp_bn = (BIGNUM *)b;\n            if (bn_wexpand(tmp_bn, al) == NULL)\n                goto err;\n            tmp_bn->d[bl] = 0;\n            bl++;\n            i--;\n        } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n            BIGNUM *tmp_bn = (BIGNUM *)a;\n            if (bn_wexpand(tmp_bn, bl) == NULL)\n                goto err;\n            tmp_bn->d[al] = 0;\n            al++;\n            i++;\n        }\n        if (i == 0) {\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (al == j) {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n            } else {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n# endif\n    }\n#endif\n    if (bn_wexpand(rr, top) == NULL)\n        goto err;\n    rr->top = top;\n    bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n    bn_correct_top(rr);\n    if (r != rr)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    bn_check_top(r);\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n                           int tna, int tnb, BN_ULONG *t)\n{\n    int i, j, n2 = n * 2;\n    int c1, c2, neg;\n    BN_ULONG ln, lo, *p;\n    if (n < 8) {\n        bn_mul_normal(r, a, n + tna, b, n + tnb);\n        return;\n    }\n    c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n    c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n    neg = 0;\n    switch (c1 * 3 + c2) {\n    case -4:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        break;\n    case -3:\n    case -2:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        neg = 1;\n        break;\n    case -1:\n    case 0:\n    case 1:\n    case 2:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        neg = 1;\n        break;\n    case 3:\n    case 4:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        break;\n    }\n# if 0\n    if (n == 4) {\n        bn_mul_comba4(&(t[n2]), t, &(t[n]));\n        bn_mul_comba4(r, a, b);\n        bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n        memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n    } else\n# endif\n    if (n == 8) {\n        bn_mul_comba8(&(t[n2]), t, &(t[n]));\n        bn_mul_comba8(r, a, b);\n        bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n        memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n    } else {\n        p = &(t[n2 * 2]);\n        bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n        bn_mul_recursive(r, a, b, n, 0, 0, p);\n        i = n / 2;\n        if (tna > tnb)\n            j = tna - i;\n        else\n            j = tnb - i;\n        if (j == 0) {\n            bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n                             i, tna - i, tnb - i, p);\n            memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n        } else if (j > 0) {\n            bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n                                  i, tna - i, tnb - i, p);\n            memset(&(r[n2 + tna + tnb]), 0,\n                   sizeof(BN_ULONG) * (n2 - tna - tnb));\n        } else {\n            memset(&r[n2], 0, sizeof(*r) * n2);\n            if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n                && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n                bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n            } else {\n                for (;;) {\n                    i /= 2;\n                    if (i < tna || i < tnb) {\n                        bn_mul_part_recursive(&(r[n2]),\n                                              &(a[n]), &(b[n]),\n                                              i, tna - i, tnb - i, p);\n                        break;\n                    } else if (i == tna || i == tnb) {\n                        bn_mul_recursive(&(r[n2]),\n                                         &(a[n]), &(b[n]),\n                                         i, tna - i, tnb - i, p);\n                        break;\n                    }\n                }\n            }\n        }\n    }\n    c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n    if (neg) {\n        c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n    } else {\n        c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n    }\n    c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n    if (c1) {\n        p = &(r[n + n2]);\n        lo = *p;\n        ln = (lo + c1) & BN_MASK2;\n        *p = ln;\n        if (ln < (BN_ULONG)c1) {\n            do {\n                p++;\n                lo = *p;\n                ln = (lo + 1) & BN_MASK2;\n                *p = ln;\n            } while (ln == 0);\n        }\n    }\n}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n{\n    BN_ULONG *rr;\n    if (na < nb) {\n        int itmp;\n        BN_ULONG *ltmp;\n        itmp = na;\n        na = nb;\n        nb = itmp;\n        ltmp = a;\n        a = b;\n        b = ltmp;\n    }\n    rr = &(r[na]);\n    if (nb <= 0) {\n        (void)bn_mul_words(r, a, na, 0);\n        return;\n    } else\n        rr[0] = bn_mul_words(r, a, na, b[0]);\n    for (;;) {\n        if (--nb <= 0)\n            return;\n        rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);\n        if (--nb <= 0)\n            return;\n        rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);\n        if (--nb <= 0)\n            return;\n        rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);\n        if (--nb <= 0)\n            return;\n        rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);\n        rr += 4;\n        r += 4;\n        b += 4;\n    }\n}']