crypto/bn/bn_gf2m.c:803: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_GF2m_mod_inv`.
Showing all 18 steps of the trace


crypto/bn/bn_gf2m.c:799:12: Call
797.   
798.       BN_CTX_start(ctx);
799.       xinv = BN_CTX_get(ctx);
                  ^
800.       if (xinv == NULL)
801.           goto err;

crypto/bn/bn_ctx.c:229:5: Call
  227.       }
  228.       /* OK, make sure the returned bignum is "zero" */
  229.       BN_zero(ret);
             ^
  230.       ctx->used++;
  231.       CTXDBG_RET(ctx, ret);

crypto/bn/bn_lib.c:360:1: Parameter `*a->d`
    358.   }
    359.   
    360. > int BN_set_word(BIGNUM *a, BN_ULONG w)
    361.   {
    362.       bn_check_top(a);

crypto/bn/bn_lib.c:363:9: Call
    361.   {
    362.       bn_check_top(a);
    363.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                   ^
    364.           return 0;
    365.       a->neg = 0;

crypto/bn/bn_lcl.h:651:1: Parameter `*a->d`
      649.                            const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
      650.   
      651. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
      652.   {
      653.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/bn/bn_gf2m.c:803:10: Call
801.           goto err;
802.   
803.       if (!BN_GF2m_mod_inv(xinv, x, p, ctx))
                ^
804.           goto err;
805.       if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))

crypto/bn/bn_gf2m.c:722:1: Parameter `*r->d`
  720.    * But it does eliminate first order deduction on the input.
  721.    */
  722. > int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  723.   {
  724.       BIGNUM *b = NULL;

crypto/bn/bn_gf2m.c:739:10: Call
  737.   
  738.       /* r := a * b */
  739.       if (!BN_GF2m_mod_mul(r, a, b, p, ctx))
                  ^
  740.           goto err;
  741.   

crypto/bn/bn_gf2m.c:463:1: Parameter `*r->d`
    461.    * BN_GF2m_mod_mul_arr function.
    462.    */
    463. > int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
    464.                       const BIGNUM *p, BN_CTX *ctx)
    465.   {

crypto/bn/bn_gf2m.c:479:11: Call
    477.           goto err;
    478.       }
    479.       ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
                     ^
    480.       bn_check_top(r);
    481.    err:

crypto/bn/bn_gf2m.c:408:1: Parameter `*r->d`
      406.    * the result in r.  r could be a or b; a could be b.
      407.    */
      408. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
      409.                           const int p[], BN_CTX *ctx)
      410.   {

crypto/bn/bn_gf2m.c:419:16: Call
      417.   
      418.       if (a == b) {
      419.           return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
                            ^
      420.       }
      421.   

crypto/bn/bn_gf2m.c:487:1: Parameter `*r->d`
        485.   
        486.   /* Square a, reduce the result mod p, and store it in a.  r could be a. */
        487. > int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
        488.                           BN_CTX *ctx)
        489.   {

crypto/bn/bn_gf2m.c:507:10: Call
        505.       s->top = 2 * a->top;
        506.       bn_correct_top(s);
        507.       if (!BN_GF2m_mod_arr(r, s, p))
                        ^
        508.           goto err;
        509.       bn_check_top(r);

crypto/bn/bn_gf2m.c:290:1: <Length trace>
288.   
289.   /* Performs modular reduction of a and store result in r.  r could be a. */
290. > int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
291.   {
292.       int j, k;

crypto/bn/bn_gf2m.c:290:1: Parameter `*r->d`
          288.   
          289.   /* Performs modular reduction of a and store result in r.  r could be a. */
          290. > int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
          291.   {
          292.       int j, k;

crypto/bn/bn_gf2m.c:316:5: Assignment
          314.           r->top = a->top;
          315.       }
          316.       z = r->d;
                     ^
          317.   
          318.       /* start reduction */

crypto/bn/bn_gf2m.c:362:9: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_GF2m_mod_inv` 
          360.           else
          361.               z[dN] = 0;
          362.           z[0] ^= zz;             /* reduction t^0 component */
                         ^
          363.   
          364.           for (k = 1; p[k] != 0; k++) {

int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
{
    int j, k;
    int n, dN, d0, d1;
    BN_ULONG zz, *z;
    bn_check_top(a);
    if (!p[0]) {
        BN_zero(r);
        return 1;
    }
    if (a != r) {
        if (!bn_wexpand(r, a->top))
            return 0;
        for (j = 0; j < a->top; j++) {
            r->d[j] = a->d[j];
        }
        r->top = a->top;
    }
    z = r->d;
    dN = p[0] / BN_BITS2;
    for (j = r->top - 1; j > dN;) {
        zz = z[j];
        if (z[j] == 0) {
            j--;
            continue;
        }
        z[j] = 0;
        for (k = 1; p[k] != 0; k++) {
            n = p[0] - p[k];
            d0 = n % BN_BITS2;
            d1 = BN_BITS2 - d0;
            n /= BN_BITS2;
            z[j - n] ^= (zz >> d0);
            if (d0)
                z[j - n - 1] ^= (zz << d1);
        }
        n = dN;
        d0 = p[0] % BN_BITS2;
        d1 = BN_BITS2 - d0;
        z[j - n] ^= (zz >> d0);
        if (d0)
            z[j - n - 1] ^= (zz << d1);
    }
    while (j == dN) {
        d0 = p[0] % BN_BITS2;
        zz = z[dN] >> d0;
        if (zz == 0)
            break;
        d1 = BN_BITS2 - d0;
        if (d0)
            z[dN] = (z[dN] << d1) >> d1;
        else
            z[dN] = 0;
        z[0] ^= zz;
        for (k = 1; p[k] != 0; k++) {
            BN_ULONG tmp_ulong;
            n = p[k] / BN_BITS2;
            d0 = p[k] % BN_BITS2;
            d1 = BN_BITS2 - d0;
            z[n] ^= (zz << d0);
            if (d0 && (tmp_ulong = zz >> d1))
                z[n + 1] ^= tmp_ulong;
        }
    }
    bn_correct_top(r);
    return 1;
}
['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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\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}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n    BIGNUM *b = NULL;\n    int ret = 0;\n    BN_CTX_start(ctx);\n    if ((b = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    do {\n        if (!BN_priv_rand(b, BN_num_bits(p) - 1,\n                          BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n            goto err;\n    } while (BN_is_zero(b));\n    if (!BN_GF2m_mod_mul(r, a, b, p, ctx))\n        goto err;\n    if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx))\n        goto err;\n    if (!BN_GF2m_mod_mul(r, r, b, p, ctx))\n        goto err;\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}', 'int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n                        BN_CTX *ctx)\n{\n    int i, ret = 0;\n    BIGNUM *s;\n    bn_check_top(a);\n    BN_CTX_start(ctx);\n    if ((s = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (!bn_wexpand(s, 2 * a->top))\n        goto err;\n    for (i = a->top - 1; i >= 0; i--) {\n        s->d[2 * i + 1] = SQR1(a->d[i]);\n        s->d[2 * i] = SQR0(a->d[i]);\n    }\n    s->top = 2 * a->top;\n    bn_correct_top(s);\n    if (!BN_GF2m_mod_arr(r, s, p))\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_arr(BIGNUM *r, const BIGNUM *a, const int p[])\n{\n    int j, k;\n    int n, dN, d0, d1;\n    BN_ULONG zz, *z;\n    bn_check_top(a);\n    if (!p[0]) {\n        BN_zero(r);\n        return 1;\n    }\n    if (a != r) {\n        if (!bn_wexpand(r, a->top))\n            return 0;\n        for (j = 0; j < a->top; j++) {\n            r->d[j] = a->d[j];\n        }\n        r->top = a->top;\n    }\n    z = r->d;\n    dN = p[0] / BN_BITS2;\n    for (j = r->top - 1; j > dN;) {\n        zz = z[j];\n        if (z[j] == 0) {\n            j--;\n            continue;\n        }\n        z[j] = 0;\n        for (k = 1; p[k] != 0; k++) {\n            n = p[0] - p[k];\n            d0 = n % BN_BITS2;\n            d1 = BN_BITS2 - d0;\n            n /= BN_BITS2;\n            z[j - n] ^= (zz >> d0);\n            if (d0)\n                z[j - n - 1] ^= (zz << d1);\n        }\n        n = dN;\n        d0 = p[0] % BN_BITS2;\n        d1 = BN_BITS2 - d0;\n        z[j - n] ^= (zz >> d0);\n        if (d0)\n            z[j - n - 1] ^= (zz << d1);\n    }\n    while (j == dN) {\n        d0 = p[0] % BN_BITS2;\n        zz = z[dN] >> d0;\n        if (zz == 0)\n            break;\n        d1 = BN_BITS2 - d0;\n        if (d0)\n            z[dN] = (z[dN] << d1) >> d1;\n        else\n            z[dN] = 0;\n        z[0] ^= zz;\n        for (k = 1; p[k] != 0; k++) {\n            BN_ULONG tmp_ulong;\n            n = p[k] / BN_BITS2;\n            d0 = p[k] % BN_BITS2;\n            d1 = BN_BITS2 - d0;\n            z[n] ^= (zz << d0);\n            if (d0 && (tmp_ulong = zz >> d1))\n                z[n + 1] ^= tmp_ulong;\n        }\n    }\n    bn_correct_top(r);\n    return 1;\n}']