crypto/bn/bn_gf2m.c:747: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_GF2m_mod_mul`.
Showing all 31 steps of the trace


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->top`
  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:743:10: Call
741.   
742.       /* r := 1/(a * b) */
743.       if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx))
                ^
744.           goto err;
745.   

crypto/bn/bn_gf2m.c:550:1: Parameter `a->top`
  548.    * Curve Cryptography Over Binary Fields".
  549.    */
  550. > static int BN_GF2m_mod_inv_vartime(BIGNUM *r, const BIGNUM *a,
  551.                                      const BIGNUM *p, BN_CTX *ctx)
  552.   {

crypto/bn/bn_gf2m.c:747:10: Call
745.   
746.       /* r := b/(a * b) = 1/a */
747.       if (!BN_GF2m_mod_mul(r, r, b, p, ctx))
                ^
748.           goto err;
749.   

crypto/bn/bn_gf2m.c:463:1: Parameter `r->top`
  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->top`
    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->top`
      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: Parameter `r->top`
        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:300:9: Call
        298.       if (!p[0]) {
        299.           /* reduction mod 1 => return 0 */
        300.           BN_zero(r);
                       ^
        301.           return 1;
        302.       }

crypto/bn/bn_lib.c:360:1: Parameter `a->top`
          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->top`
            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_lcl.h:659:12: Call
            657.           return a;
            658.   
            659.       return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);
                              ^
            660.   }
            661.   

crypto/bn/bn_lib.c:246:1: Parameter `b->top`
              244.    */
              245.   
              246. > BIGNUM *bn_expand2(BIGNUM *b, int words)
              247.   {
              248.       bn_check_top(b);

crypto/bn/bn_lib.c:251:23: Call
              249.   
              250.       if (words > b->dmax) {
              251.           BN_ULONG *a = bn_expand_internal(b, words);
                                           ^
              252.           if (!a)
              253.               return NULL;

crypto/bn/bn_lib.c:208:1: <Offset trace>
206.   /* This is used by bn_expand2() */
207.   /* The caller MUST check that words > b->dmax before calling this */
208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
209.   {
210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:208:1: Parameter `b->top`
                206.   /* This is used by bn_expand2() */
                207.   /* The caller MUST check that words > b->dmax before calling this */
                208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
                209.   {
                210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:208:1: <Length trace>
206.   /* This is used by bn_expand2() */
207.   /* The caller MUST check that words > b->dmax before calling this */
208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
209.   {
210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:208:1: Parameter `words`
                206.   /* This is used by bn_expand2() */
                207.   /* The caller MUST check that words > b->dmax before calling this */
                208. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
                209.   {
                210.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:225:13: Call
                223.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
                224.       else
                225.           a = OPENSSL_zalloc(words * sizeof(*a));
                                   ^
                226.       if (a == NULL) {
                227.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:228:1: Parameter `num`
                  226.   }
                  227.   
                  228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
                  229.   {
                  230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:17: Call
                  228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
                  229.   {
                  230.       void *ret = CRYPTO_malloc(num, file, line);
                                         ^
                  231.   
                  232.       FAILTEST();

crypto/mem.c:201:9: Assignment
                    199.   
                    200.       if (num == 0)
                    201.           return NULL;
                                   ^
                    202.   
                    203.       FAILTEST();

crypto/mem.c:230:5: Assignment
                  228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
                  229.   {
                  230.       void *ret = CRYPTO_malloc(num, file, line);
                             ^
                  231.   
                  232.       FAILTEST();

crypto/mem.c:235:5: Assignment
                  233.       if (ret != NULL)
                  234.           memset(ret, 0, num);
                  235.       return ret;
                             ^
                  236.   }
                  237.   

crypto/bn/bn_lib.c:225:9: Assignment
                223.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
                224.       else
                225.           a = OPENSSL_zalloc(words * sizeof(*a));
                               ^
                226.       if (a == NULL) {
                227.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:233:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_GF2m_mod_mul` 
                231.       assert(b->top <= words);
                232.       if (b->top > 0)
                233.           memcpy(a, b->d, sizeof(*a) * b->top);
                               ^
                234.   
                235.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['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}', 'static int BN_GF2m_mod_inv_vartime(BIGNUM *r, const BIGNUM *a,\n                                   const BIGNUM *p, BN_CTX *ctx)\n{\n    BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(p);\n    BN_CTX_start(ctx);\n    b = BN_CTX_get(ctx);\n    c = BN_CTX_get(ctx);\n    u = BN_CTX_get(ctx);\n    v = BN_CTX_get(ctx);\n    if (v == NULL)\n        goto err;\n    if (!BN_GF2m_mod(u, a, p))\n        goto err;\n    if (BN_is_zero(u))\n        goto err;\n    if (!BN_copy(v, p))\n        goto err;\n# if 0\n    if (!BN_one(b))\n        goto err;\n    while (1) {\n        while (!BN_is_odd(u)) {\n            if (BN_is_zero(u))\n                goto err;\n            if (!BN_rshift1(u, u))\n                goto err;\n            if (BN_is_odd(b)) {\n                if (!BN_GF2m_add(b, b, p))\n                    goto err;\n            }\n            if (!BN_rshift1(b, b))\n                goto err;\n        }\n        if (BN_abs_is_word(u, 1))\n            break;\n        if (BN_num_bits(u) < BN_num_bits(v)) {\n            tmp = u;\n            u = v;\n            v = tmp;\n            tmp = b;\n            b = c;\n            c = tmp;\n        }\n        if (!BN_GF2m_add(u, u, v))\n            goto err;\n        if (!BN_GF2m_add(b, b, c))\n            goto err;\n    }\n# else\n    {\n        int i;\n        int ubits = BN_num_bits(u);\n        int vbits = BN_num_bits(v);\n        int top = p->top;\n        BN_ULONG *udp, *bdp, *vdp, *cdp;\n        if (!bn_wexpand(u, top))\n            goto err;\n        udp = u->d;\n        for (i = u->top; i < top; i++)\n            udp[i] = 0;\n        u->top = top;\n        if (!bn_wexpand(b, top))\n          goto err;\n        bdp = b->d;\n        bdp[0] = 1;\n        for (i = 1; i < top; i++)\n            bdp[i] = 0;\n        b->top = top;\n        if (!bn_wexpand(c, top))\n          goto err;\n        cdp = c->d;\n        for (i = 0; i < top; i++)\n            cdp[i] = 0;\n        c->top = top;\n        vdp = v->d;\n        while (1) {\n            while (ubits && !(udp[0] & 1)) {\n                BN_ULONG u0, u1, b0, b1, mask;\n                u0 = udp[0];\n                b0 = bdp[0];\n                mask = (BN_ULONG)0 - (b0 & 1);\n                b0 ^= p->d[0] & mask;\n                for (i = 0; i < top - 1; i++) {\n                    u1 = udp[i + 1];\n                    udp[i] = ((u0 >> 1) | (u1 << (BN_BITS2 - 1))) & BN_MASK2;\n                    u0 = u1;\n                    b1 = bdp[i + 1] ^ (p->d[i + 1] & mask);\n                    bdp[i] = ((b0 >> 1) | (b1 << (BN_BITS2 - 1))) & BN_MASK2;\n                    b0 = b1;\n                }\n                udp[i] = u0 >> 1;\n                bdp[i] = b0 >> 1;\n                ubits--;\n            }\n            if (ubits <= BN_BITS2) {\n                if (udp[0] == 0)\n                    goto err;\n                if (udp[0] == 1)\n                    break;\n            }\n            if (ubits < vbits) {\n                i = ubits;\n                ubits = vbits;\n                vbits = i;\n                tmp = u;\n                u = v;\n                v = tmp;\n                tmp = b;\n                b = c;\n                c = tmp;\n                udp = vdp;\n                vdp = v->d;\n                bdp = cdp;\n                cdp = c->d;\n            }\n            for (i = 0; i < top; i++) {\n                udp[i] ^= vdp[i];\n                bdp[i] ^= cdp[i];\n            }\n            if (ubits == vbits) {\n                BN_ULONG ul;\n                int utop = (ubits - 1) / BN_BITS2;\n                while ((ul = udp[utop]) == 0 && utop)\n                    utop--;\n                ubits = utop * BN_BITS2 + BN_num_bits_word(ul);\n            }\n        }\n        bn_correct_top(b);\n    }\n# endif\n    if (!BN_copy(r, b))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n# ifdef BN_DEBUG\n    bn_correct_top(c);\n    bn_correct_top(u);\n    bn_correct_top(v);\n# endif\n    BN_CTX_end(ctx);\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}', '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}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']