test/bntest.c:1463: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_div`.
Showing all 12 steps of the trace


test/bntest.c:1463:13: Call
1461.           BN_bntest_rand(c, 512, 0, 0);
1462.           for (j = 0; j < 2; j++) {
1463.               BN_GF2m_mod_div(d, a, c, b[j], ctx);
                    ^
1464.               BN_GF2m_mod_mul(e, d, c, b[j], ctx);
1465.               BN_GF2m_mod_div(f, a, e, b[j], ctx);

crypto/bn/bn_gf2m.c:831:1: Parameter `r->top`
  829.    * or y, x could equal y.
  830.    */
  831. > int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,
  832.                       const BIGNUM *p, BN_CTX *ctx)
  833.   {

test/bntest.c:1463:13: Call
1461.           BN_bntest_rand(c, 512, 0, 0);
1462.           for (j = 0; j < 2; j++) {
1463.               BN_GF2m_mod_div(d, a, c, b[j], ctx);
                    ^
1464.               BN_GF2m_mod_mul(e, d, c, b[j], ctx);
1465.               BN_GF2m_mod_div(f, a, e, b[j], ctx);

crypto/bn/bn_gf2m.c:831:1: Parameter `*y->d`
  829.    * or y, x could equal y.
  830.    */
  831. > int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,
  832.                       const BIGNUM *p, BN_CTX *ctx)
  833.   {

crypto/bn/bn_gf2m.c:848:10: Call
  846.       if (!BN_GF2m_mod_inv(xinv, x, p, ctx))
  847.           goto err;
  848.       if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))
                  ^
  849.           goto err;
  850.       bn_check_top(r);

crypto/bn/bn_gf2m.c:544:1: Parameter `*a->d`
    542.    * BN_GF2m_mod_mul_arr function.
    543.    */
    544. > int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
    545.                       const BIGNUM *p, BN_CTX *ctx)
    546.   {

crypto/bn/bn_gf2m.c:560:11: Call
    558.           goto err;
    559.       }
    560.       ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
                     ^
    561.       bn_check_top(r);
    562.    err:

crypto/bn/bn_gf2m.c:489:1: <Offset trace>
487.    * the result in r.  r could be a or b; a could be b.
488.    */
489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
490.                           const int p[], BN_CTX *ctx)
491.   {

crypto/bn/bn_gf2m.c:489:1: Parameter `a->top`
      487.    * the result in r.  r could be a or b; a could be b.
      488.    */
      489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
      490.                           const int p[], BN_CTX *ctx)
      491.   {

crypto/bn/bn_gf2m.c:489:1: <Length trace>
487.    * the result in r.  r could be a or b; a could be b.
488.    */
489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
490.                           const int p[], BN_CTX *ctx)
491.   {

crypto/bn/bn_gf2m.c:489:1: Parameter `*a->d`
      487.    * the result in r.  r could be a or b; a could be b.
      488.    */
      489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
      490.                           const int p[], BN_CTX *ctx)
      491.   {

crypto/bn/bn_gf2m.c:520:44: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_div` 
      518.           for (i = 0; i < a->top; i += 2) {
      519.               x0 = a->d[i];
      520.               x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];
                                                        ^
      521.               bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);
      522.               for (k = 0; k < 4; k++)

int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                        const int p[], BN_CTX *ctx)
{
    int zlen, i, j, k, ret = 0;
    BIGNUM *s;
    BN_ULONG x1, x0, y1, y0, zz[4];
    bn_check_top(a);
    bn_check_top(b);
    if (a == b) {
        return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
    }
    BN_CTX_start(ctx);
    if ((s = BN_CTX_get(ctx)) == NULL)
        goto err;
    zlen = a->top + b->top + 4;
    if (!bn_wexpand(s, zlen))
        goto err;
    s->top = zlen;
    for (i = 0; i < zlen; i++)
        s->d[i] = 0;
    for (j = 0; j < b->top; j += 2) {
        y0 = b->d[j];
        y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];
        for (i = 0; i < a->top; i += 2) {
            x0 = a->d[i];
            x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];
            bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);
            for (k = 0; k < 4; k++)
                s->d[i + j + k] ^= zz[k];
        }
    }
    bn_correct_top(s);
    if (BN_GF2m_mod_arr(r, s, p))
        ret = 1;
    bn_check_top(r);
 err:
    BN_CTX_end(ctx);
    return ret;
}
['int test_gf2m_mod_div(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *b[2], *c, *d, *e, *f;\n    int i, j, ret = 0;\n    int p0[] = { 163, 7, 6, 3, 0, -1 };\n    int p1[] = { 193, 15, 0, -1 };\n    a = BN_new();\n    b[0] = BN_new();\n    b[1] = BN_new();\n    c = BN_new();\n    d = BN_new();\n    e = BN_new();\n    f = BN_new();\n    BN_GF2m_arr2poly(p0, b[0]);\n    BN_GF2m_arr2poly(p1, b[1]);\n    for (i = 0; i < num0; i++) {\n        BN_bntest_rand(a, 512, 0, 0);\n        BN_bntest_rand(c, 512, 0, 0);\n        for (j = 0; j < 2; j++) {\n            BN_GF2m_mod_div(d, a, c, b[j], ctx);\n            BN_GF2m_mod_mul(e, d, c, b[j], ctx);\n            BN_GF2m_mod_div(f, a, e, b[j], ctx);\n            if (!BN_is_one(f)) {\n                fprintf(stderr, "GF(2^m) modular division test failed!\\n");\n                goto err;\n            }\n        }\n    }\n    ret = 1;\n err:\n    BN_free(a);\n    BN_free(b[0]);\n    BN_free(b[1]);\n    BN_free(c);\n    BN_free(d);\n    BN_free(e);\n    BN_free(f);\n    return ret;\n}', 'int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,\n                    const BIGNUM *p, BN_CTX *ctx)\n{\n    BIGNUM *xinv = NULL;\n    int ret = 0;\n    bn_check_top(y);\n    bn_check_top(x);\n    bn_check_top(p);\n    BN_CTX_start(ctx);\n    xinv = BN_CTX_get(ctx);\n    if (xinv == NULL)\n        goto err;\n    if (!BN_GF2m_mod_inv(xinv, x, p, ctx))\n        goto err;\n    if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                    const BIGNUM *p, BN_CTX *ctx)\n{\n    int ret = 0;\n    const int max = BN_num_bits(p) + 1;\n    int *arr = NULL;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(p);\n    if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)\n        goto err;\n    ret = BN_GF2m_poly2arr(p, arr, max);\n    if (!ret || ret > max) {\n        BNerr(BN_F_BN_GF2M_MOD_MUL, BN_R_INVALID_LENGTH);\n        goto err;\n    }\n    ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);\n    bn_check_top(r);\n err:\n    OPENSSL_free(arr);\n    return ret;\n}', 'int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                        const int p[], BN_CTX *ctx)\n{\n    int zlen, i, j, k, ret = 0;\n    BIGNUM *s;\n    BN_ULONG x1, x0, y1, y0, zz[4];\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a == b) {\n        return BN_GF2m_mod_sqr_arr(r, a, p, ctx);\n    }\n    BN_CTX_start(ctx);\n    if ((s = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    zlen = a->top + b->top + 4;\n    if (!bn_wexpand(s, zlen))\n        goto err;\n    s->top = zlen;\n    for (i = 0; i < zlen; i++)\n        s->d[i] = 0;\n    for (j = 0; j < b->top; j += 2) {\n        y0 = b->d[j];\n        y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];\n        for (i = 0; i < a->top; i += 2) {\n            x0 = a->d[i];\n            x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];\n            bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);\n            for (k = 0; k < 4; k++)\n                s->d[i + j + k] ^= zz[k];\n        }\n    }\n    bn_correct_top(s);\n    if (BN_GF2m_mod_arr(r, s, p))\n        ret = 1;\n    bn_check_top(r);\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}']