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


test/bntest.c:1382:13: Call
1380.           BN_bntest_rand(a, 1024, 0, 0);
1381.           for (j = 0; j < 2; j++) {
1382.               BN_GF2m_mod_sqr(c, a, b[j], ctx);
                    ^
1383.               BN_copy(d, a);
1384.               BN_GF2m_mod_mul(d, a, d, b[j], ctx);

crypto/bn/bn_gf2m.c:603:1: Parameter `r->top`
  601.    * use the BN_GF2m_mod_sqr_arr function.
  602.    */
  603. > int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  604.   {
  605.       int ret = 0;

test/bntest.c:1382:13: Call
1380.           BN_bntest_rand(a, 1024, 0, 0);
1381.           for (j = 0; j < 2; j++) {
1382.               BN_GF2m_mod_sqr(c, a, b[j], ctx);
                    ^
1383.               BN_copy(d, a);
1384.               BN_GF2m_mod_mul(d, a, d, b[j], ctx);

crypto/bn/bn_gf2m.c:603:1: Parameter `a->top`
  601.    * use the BN_GF2m_mod_sqr_arr function.
  602.    */
  603. > int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  604.   {
  605.       int ret = 0;

crypto/bn/bn_gf2m.c:618:11: Call
  616.           goto err;
  617.       }
  618.       ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
                   ^
  619.       bn_check_top(r);
  620.    err:

crypto/bn/bn_gf2m.c:568:1: <Offset trace>
566.   
567.   /* Square a, reduce the result mod p, and store it in a.  r could be a. */
568. > int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
569.                           BN_CTX *ctx)
570.   {

crypto/bn/bn_gf2m.c:568:1: Parameter `a->top`
    566.   
    567.   /* Square a, reduce the result mod p, and store it in a.  r could be a. */
    568. > int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
    569.                           BN_CTX *ctx)
    570.   {

crypto/bn/bn_gf2m.c:581:10: Assignment
    579.           goto err;
    580.   
    581.       for (i = a->top - 1; i >= 0; i--) {
                    ^
    582.           s->d[2 * i + 1] = SQR1(a->d[i]);
    583.           s->d[2 * i] = SQR0(a->d[i]);

crypto/bn/bn_gf2m.c:576:14: <Length trace>
574.       bn_check_top(a);
575.       BN_CTX_start(ctx);
576.       if ((s = BN_CTX_get(ctx)) == NULL)
                    ^
577.           goto err;
578.       if (!bn_wexpand(s, 2 * a->top))

crypto/bn/bn_gf2m.c:576:14: Call
    574.       bn_check_top(a);
    575.       BN_CTX_start(ctx);
    576.       if ((s = BN_CTX_get(ctx)) == NULL)
                        ^
    577.           goto err;
    578.       if (!bn_wexpand(s, 2 * a->top))

crypto/bn/bn_ctx.c:284:5: Call
      282.       }
      283.       /* OK, make sure the returned bignum is "zero" */
      284.       BN_zero(ret);
                 ^
      285.       ctx->used++;
      286.       CTXDBG_RET(ctx, ret);

crypto/bn/bn_lib.c:530:1: Parameter `*a->d`
        528.   }
        529.   
        530. > int BN_set_word(BIGNUM *a, BN_ULONG w)
        531.   {
        532.       bn_check_top(a);

crypto/bn/bn_gf2m.c:582:9: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_sqr` 
    580.   
    581.       for (i = a->top - 1; i >= 0; i--) {
    582.           s->d[2 * i + 1] = SQR1(a->d[i]);
                   ^
    583.           s->d[2 * i] = SQR0(a->d[i]);
    584.       }

int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
                        BN_CTX *ctx)
{
    int i, ret = 0;
    BIGNUM *s;
    bn_check_top(a);
    BN_CTX_start(ctx);
    if ((s = BN_CTX_get(ctx)) == NULL)
        goto err;
    if (!bn_wexpand(s, 2 * a->top))
        goto err;
    for (i = a->top - 1; i >= 0; i--) {
        s->d[2 * i + 1] = SQR1(a->d[i]);
        s->d[2 * i] = SQR0(a->d[i]);
    }
    s->top = 2 * a->top;
    bn_correct_top(s);
    if (!BN_GF2m_mod_arr(r, s, p))
        goto err;
    bn_check_top(r);
    ret = 1;
 err:
    BN_CTX_end(ctx);
    return ret;
}
['int test_gf2m_mod_sqr(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *b[2], *c, *d;\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    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, 1024, 0, 0);\n        for (j = 0; j < 2; j++) {\n            BN_GF2m_mod_sqr(c, a, b[j], ctx);\n            BN_copy(d, a);\n            BN_GF2m_mod_mul(d, a, d, b[j], ctx);\n            BN_GF2m_add(d, c, d);\n            if (!BN_is_zero(d)) {\n                fprintf(stderr, "GF(2^m) modular squaring 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    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}', '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}']