crypto/bn/bn_gf2m.c:618: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, +oo] by call to `BN_GF2m_mod_sqr_arr`.
Showing all 14 steps of the trace


crypto/bn/bn_gf2m.c:606:21: Call
604.   {
605.       int ret = 0;
606.       const int max = BN_num_bits(p) + 1;
                           ^
607.       int *arr = NULL;
608.   

crypto/bn/bn_lib.c:221:9: Assignment
  219.   
  220.       if (BN_is_zero(a))
  221.           return 0;
                 ^
  222.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
  223.   }

crypto/bn/bn_gf2m.c:606:5: Assignment
604.   {
605.       int ret = 0;
606.       const int max = BN_num_bits(p) + 1;
           ^
607.       int *arr = NULL;
608.   

crypto/bn/bn_gf2m.c:611:16: Call
609.       bn_check_top(a);
610.       bn_check_top(p);
611.       if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
                      ^
612.           goto err;
613.       ret = BN_GF2m_poly2arr(p, arr, max);

crypto/mem.c:125:9: Assignment
  123.   
  124.       if (num <= 0)
  125.           return NULL;
                 ^
  126.   
  127.       allow_customize = 0;

crypto/bn/bn_gf2m.c:611:10: Assignment
609.       bn_check_top(a);
610.       bn_check_top(p);
611.       if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)
                ^
612.           goto err;
613.       ret = BN_GF2m_poly2arr(p, arr, max);

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: Parameter `*p`
  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:588:10: Call
  586.       s->top = 2 * a->top;
  587.       bn_correct_top(s);
  588.       if (!BN_GF2m_mod_arr(r, s, p))
                  ^
  589.           goto err;
  590.       bn_check_top(r);

crypto/bn/bn_gf2m.c:409:14: <Offset trace>
407.           z[j] = 0;
408.   
409.           for (k = 1; p[k] != 0; k++) {
                    ^
410.               /* reducing component t^p[k] */
411.               n = p[0] - p[k];

crypto/bn/bn_gf2m.c:409:14: Assignment
    407.           z[j] = 0;
    408.   
    409.           for (k = 1; p[k] != 0; k++) {
                        ^
    410.               /* reducing component t^p[k] */
    411.               n = p[0] - p[k];

crypto/bn/bn_gf2m.c:371:1: <Length trace>
369.   
370.   /* Performs modular reduction of a and store result in r.  r could be a. */
371. > int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
372.   {
373.       int j, k;

crypto/bn/bn_gf2m.c:371:1: Parameter `*p`
    369.   
    370.   /* Performs modular reduction of a and store result in r.  r could be a. */
    371. > int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])
    372.   {
    373.       int j, k;

crypto/bn/bn_gf2m.c:409:21: Array access: Offset: [1, +oo] Size: [0, +oo] by call to `BN_GF2m_mod_sqr_arr` 
    407.           z[j] = 0;
    408.   
    409.           for (k = 1; p[k] != 0; k++) {
                               ^
    410.               /* reducing component t^p[k] */
    411.               n = p[0] - p[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_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_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifdef 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;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\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}']