crypto/ec/ec2_smpl.c:813: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_inv`.
Showing all 14 steps of the trace


crypto/ec/ec2_smpl.c:793:10: Call
791.   
792.       BN_CTX_start(ctx);
793.       t0 = BN_CTX_get(ctx);
                ^
794.       t1 = BN_CTX_get(ctx);
795.       t2 = BN_CTX_get(ctx);

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:366:15: Assignment
    364.       a->neg = 0;
    365.       a->d[0] = w;
    366.       a->top = (w ? 1 : 0);
                         ^
    367.       a->flags &= ~BN_FLG_FIXED_TOP;
    368.       bn_check_top(a);

crypto/bn/bn_lib.c:366:5: Assignment
    364.       a->neg = 0;
    365.       a->d[0] = w;
    366.       a->top = (w ? 1 : 0);
               ^
    367.       a->flags &= ~BN_FLG_FIXED_TOP;
    368.       bn_check_top(a);

crypto/ec/ec2_smpl.c:813:13: Call
811.           || !BN_GF2m_add(t1, t2, t1)
812.           || !group->meth->field_mul(group, t2, p->X, t0, ctx)
813.           || !BN_GF2m_mod_inv(t2, t2, group->field, ctx)
                   ^
814.           || !group->meth->field_mul(group, t1, t1, t2, ctx)
815.           || !group->meth->field_mul(group, r->X, r->Z, t2, ctx)

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

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

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

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

crypto/bn/bn_gf2m.c:410:1: <Offset trace>
408.    * the result in r.  r could be a or b; a could be b.
409.    */
410. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
411.                           const int p[], BN_CTX *ctx)
412.   {

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

crypto/bn/bn_gf2m.c:410:1: <Length trace>
408.    * the result in r.  r could be a or b; a could be b.
409.    */
410. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
411.                           const int p[], BN_CTX *ctx)
412.   {

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

crypto/bn/bn_gf2m.c:441:44: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_inv` 
      439.           for (i = 0; i < a->top; i += 2) {
      440.               x0 = a->d[i];
      441.               x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];
                                                        ^
      442.               bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);
      443.               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;
}
['static\nint ec_GF2m_simple_ladder_post(const EC_GROUP *group,\n                               EC_POINT *r, EC_POINT *s,\n                               EC_POINT *p, BN_CTX *ctx)\n{\n    int ret = 0;\n    BIGNUM *t0, *t1, *t2 = NULL;\n    if (BN_is_zero(r->Z))\n        return EC_POINT_set_to_infinity(group, r);\n    if (BN_is_zero(s->Z)) {\n        if (!EC_POINT_copy(r, p)\n            || !EC_POINT_invert(group, r, ctx)) {\n            ECerr(EC_F_EC_GF2M_SIMPLE_LADDER_POST, ERR_R_EC_LIB);\n            return 0;\n        }\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    t0 = BN_CTX_get(ctx);\n    t1 = BN_CTX_get(ctx);\n    t2 = BN_CTX_get(ctx);\n    if (t2 == NULL) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_LADDER_POST, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (!group->meth->field_mul(group, t0, r->Z, s->Z, ctx)\n        || !group->meth->field_mul(group, t1, p->X, r->Z, ctx)\n        || !BN_GF2m_add(t1, r->X, t1)\n        || !group->meth->field_mul(group, t2, p->X, s->Z, ctx)\n        || !group->meth->field_mul(group, r->Z, r->X, t2, ctx)\n        || !BN_GF2m_add(t2, t2, s->X)\n        || !group->meth->field_mul(group, t1, t1, t2, ctx)\n        || !group->meth->field_sqr(group, t2, p->X, ctx)\n        || !BN_GF2m_add(t2, p->Y, t2)\n        || !group->meth->field_mul(group, t2, t2, t0, ctx)\n        || !BN_GF2m_add(t1, t2, t1)\n        || !group->meth->field_mul(group, t2, p->X, t0, ctx)\n        || !BN_GF2m_mod_inv(t2, t2, group->field, ctx)\n        || !group->meth->field_mul(group, t1, t1, t2, ctx)\n        || !group->meth->field_mul(group, r->X, r->Z, t2, ctx)\n        || !BN_GF2m_add(t2, p->X, r->X)\n        || !group->meth->field_mul(group, t2, t2, t1, ctx)\n        || !BN_GF2m_add(r->Y, p->Y, t2)\n        || !BN_one(r->Z))\n        goto err;\n    r->Z_is_one = 1;\n    BN_set_negative(r->X, 0);\n    BN_set_negative(r->Y, 0);\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    a->flags &= ~BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return 1;\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}']