test/bntest.c:926: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_GF2m_mod_sqr`.
Showing all 19 steps of the trace


test/bntest.c:925:24: Call
923.           for (j = 0; j < 2; j++) {
924.               if (!(TEST_true(BN_GF2m_mod(c, a, b[j]))
925.                       && TEST_true(BN_GF2m_mod_sqrt(d, a, b[j], ctx))
                              ^
926.                       && TEST_true(BN_GF2m_mod_sqr(e, d, b[j], ctx))
927.                       && TEST_true(BN_GF2m_add(f, c, e))

crypto/bn/bn_gf2m.c:958:1: Parameter `ctx->stack.depth`
  956.    * for best performance, use the BN_GF2m_mod_sqrt_arr function.
  957.    */
  958. > int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  959.   {
  960.       int ret = 0;

test/bntest.c:926:24: Call
924.               if (!(TEST_true(BN_GF2m_mod(c, a, b[j]))
925.                       && TEST_true(BN_GF2m_mod_sqrt(d, a, b[j], ctx))
926.                       && TEST_true(BN_GF2m_mod_sqr(e, d, b[j], ctx))
                              ^
927.                       && TEST_true(BN_GF2m_add(f, c, e))
928.                       /* Test that d^2 = a, where d = sqrt(a). */

crypto/bn/bn_gf2m.c:524:1: Parameter `ctx->stack.depth`
  522.    * use the BN_GF2m_mod_sqr_arr function.
  523.    */
  524. > int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  525.   {
  526.       int ret = 0;

test/bntest.c:925:24: Call
923.           for (j = 0; j < 2; j++) {
924.               if (!(TEST_true(BN_GF2m_mod(c, a, b[j]))
925.                       && TEST_true(BN_GF2m_mod_sqrt(d, a, b[j], ctx))
                              ^
926.                       && TEST_true(BN_GF2m_mod_sqr(e, d, b[j], ctx))
927.                       && TEST_true(BN_GF2m_add(f, c, e))

crypto/bn/bn_gf2m.c:958:1: Parameter `ctx->stack.depth`
  956.    * for best performance, use the BN_GF2m_mod_sqrt_arr function.
  957.    */
  958. > int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  959.   {
  960.       int ret = 0;

test/bntest.c:926:24: Call
924.               if (!(TEST_true(BN_GF2m_mod(c, a, b[j]))
925.                       && TEST_true(BN_GF2m_mod_sqrt(d, a, b[j], ctx))
926.                       && TEST_true(BN_GF2m_mod_sqr(e, d, b[j], ctx))
                              ^
927.                       && TEST_true(BN_GF2m_add(f, c, e))
928.                       /* Test that d^2 = a, where d = sqrt(a). */

crypto/bn/bn_gf2m.c:524:1: Parameter `ctx->stack.depth`
  522.    * use the BN_GF2m_mod_sqr_arr function.
  523.    */
  524. > int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  525.   {
  526.       int ret = 0;

crypto/bn/bn_gf2m.c:539:11: Call
  537.           goto err;
  538.       }
  539.       ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
                   ^
  540.       bn_check_top(r);
  541.    err:

crypto/bn/bn_gf2m.c:496:5: Call
    494.   
    495.       bn_check_top(a);
    496.       BN_CTX_start(ctx);
               ^
    497.       if ((s = BN_CTX_get(ctx)) == NULL)
    498.           goto err;

crypto/bn/bn_ctx.c:171:1: Parameter `*ctx->stack.indexes`
      169.   }
      170.   
      171. > void BN_CTX_start(BN_CTX *ctx)
      172.   {
      173.       CTXDBG("ENTER BN_CTX_start()", ctx);

crypto/bn/bn_gf2m.c:514:5: Call
    512.       ret = 1;
    513.    err:
    514.       BN_CTX_end(ctx);
               ^
    515.       return ret;
    516.   }

crypto/bn/bn_ctx.c:185:1: Parameter `*ctx->stack.indexes`
      183.   }
      184.   
      185. > void BN_CTX_end(BN_CTX *ctx)
      186.   {
      187.       CTXDBG("ENTER BN_CTX_end()", ctx);

crypto/bn/bn_ctx.c:191:27: Call
      189.           ctx->err_stack--;
      190.       else {
      191.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                       ^
      192.           /* Does this stack frame have anything to release? */
      193.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:266:1: <Offset trace>
264.   }
265.   
266. > static unsigned int BN_STACK_pop(BN_STACK *st)
267.   {
268.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:266:1: Parameter `st->depth`
        264.   }
        265.   
        266. > static unsigned int BN_STACK_pop(BN_STACK *st)
        267.   {
        268.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:266:1: <Length trace>
264.   }
265.   
266. > static unsigned int BN_STACK_pop(BN_STACK *st)
267.   {
268.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:266:1: Parameter `*st->indexes`
        264.   }
        265.   
        266. > static unsigned int BN_STACK_pop(BN_STACK *st)
        267.   {
        268.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:268:12: Array access: Offset: [-1, +oo] Size: [1, +oo] by call to `BN_GF2m_mod_sqr` 
        266.   static unsigned int BN_STACK_pop(BN_STACK *st)
        267.   {
        268.       return st->indexes[--(st->depth)];
                          ^
        269.   }
        270.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['static int test_gf2m_modsqrt(void)\n{\n    BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL;\n    BIGNUM *e = NULL, *f = NULL;\n    int i, j, st = 0;\n    if (!TEST_ptr(a = BN_new())\n            || !TEST_ptr(b[0] = BN_new())\n            || !TEST_ptr(b[1] = BN_new())\n            || !TEST_ptr(c = BN_new())\n            || !TEST_ptr(d = BN_new())\n            || !TEST_ptr(e = BN_new())\n            || !TEST_ptr(f = BN_new()))\n        goto err;\n    if (!(TEST_true(BN_GF2m_arr2poly(p0, b[0]))\n            && TEST_true(BN_GF2m_arr2poly(p1, b[1]))))\n        goto err;\n    for (i = 0; i < NUM0; i++) {\n        if (!TEST_true(BN_bntest_rand(a, 512, 0, 0)))\n            goto err;\n        for (j = 0; j < 2; j++) {\n            if (!(TEST_true(BN_GF2m_mod(c, a, b[j]))\n                    && TEST_true(BN_GF2m_mod_sqrt(d, a, b[j], ctx))\n                    && TEST_true(BN_GF2m_mod_sqr(e, d, b[j], ctx))\n                    && TEST_true(BN_GF2m_add(f, c, e))\n                    && TEST_BN_eq_zero(f)))\n                goto err;\n        }\n    }\n    st = 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 st;\n}', 'int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, 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(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_SQRT, BN_R_INVALID_LENGTH);\n        goto err;\n    }\n    ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);\n    bn_check_top(r);\n err:\n    OPENSSL_free(arr);\n    return ret;\n}', 'int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, 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(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_SQR, BN_R_INVALID_LENGTH);\n        goto err;\n    }\n    ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);\n    bn_check_top(r);\n err:\n    OPENSSL_free(arr);\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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG("ENTER BN_CTX_start()", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    CTXDBG("ENTER BN_CTX_end()", ctx);\n    if (ctx->err_stack)\n        ctx->err_stack--;\n    else {\n        unsigned int fp = BN_STACK_pop(&ctx->stack);\n        if (fp < ctx->used)\n            BN_POOL_release(&ctx->pool, ctx->used - fp);\n        ctx->used = fp;\n        ctx->too_many = 0;\n    }\n    CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']