crypto/bn/bn_x931p.c:111: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_mod_sub`.
Showing all 27 steps of the trace


crypto/bn/bn_x931p.c:94:10: Call
92.           goto err;
93.   
94.       if (!BN_mul(p, p, p2, ctx))
               ^
95.           goto err;
96.   

crypto/bn/bn_mul.c:497:1: Parameter `r->top`
  495.   #endif                          /* BN_RECURSION */
  496.   
  497. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = 0;

crypto/bn/bn_x931p.c:103:10: Call
101.           goto err;
102.   
103.       if (!BN_sub(p, p, t))
                ^
104.           goto err;
105.   

crypto/bn/bn_add.c:45:1: Parameter `a->top`
  43.   
  44.   /* signed sub of b from a. */
  45. > int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
  46.   {
  47.       int ret, r_neg, cmp_res;

crypto/bn/bn_x931p.c:111:10: Call
109.       /* p now equals Rp */
110.   
111.       if (!BN_mod_sub(p, p, Xp, p1p2, ctx))
                ^
112.           goto err;
113.   

crypto/bn/bn_mod.c:50:1: Parameter `r->top`
  48.   }
  49.   
  50. > int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  51.                  BN_CTX *ctx)
  52.   {

crypto/bn/bn_mod.c:53:10: Call
  51.                  BN_CTX *ctx)
  52.   {
  53.       if (!BN_sub(r, a, b))
                 ^
  54.           return 0;
  55.       return BN_nnmod(r, r, m, ctx);

crypto/bn/bn_add.c:45:1: Parameter `r->top`
    43.   
    44.   /* signed sub of b from a. */
    45. > int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
    46.   {
    47.       int ret, r_neg, cmp_res;

crypto/bn/bn_add.c:62:19: Call
    60.           } else if (cmp_res < 0) {
    61.               r_neg = !b->neg;
    62.               ret = BN_usub(r, b, a);
                            ^
    63.           } else {
    64.               r_neg = 0;

crypto/bn/bn_add.c:125:1: Parameter `r->top`
      123.   
      124.   /* unsigned subtraction of b from a, a must be larger than b. */
      125. > int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
      126.   {
      127.       int max, min, dif;

crypto/bn/bn_add.c:143:9: Call
      141.       }
      142.   
      143.       if (bn_wexpand(r, max) == NULL)
                     ^
      144.           return 0;
      145.   

crypto/bn/bn_lib.c:910:1: Parameter `a->top`
        908.   }
        909.   
        910. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
        911.   {
        912.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:912:37: Call
        910.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
        911.   {
        912.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                   ^
        913.   }
        914.   

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_mod_sub` 
            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_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,\n                            const BIGNUM *Xp, const BIGNUM *Xp1,\n                            const BIGNUM *Xp2, const BIGNUM *e, BN_CTX *ctx,\n                            BN_GENCB *cb)\n{\n    int ret = 0;\n    BIGNUM *t, *p1p2, *pm1;\n    if (!BN_is_odd(e))\n        return 0;\n    BN_CTX_start(ctx);\n    if (p1 == NULL)\n        p1 = BN_CTX_get(ctx);\n    if (p2 == NULL)\n        p2 = BN_CTX_get(ctx);\n    t = BN_CTX_get(ctx);\n    p1p2 = BN_CTX_get(ctx);\n    pm1 = BN_CTX_get(ctx);\n    if (pm1 == NULL)\n        goto err;\n    if (!bn_x931_derive_pi(p1, Xp1, ctx, cb))\n        goto err;\n    if (!bn_x931_derive_pi(p2, Xp2, ctx, cb))\n        goto err;\n    if (!BN_mul(p1p2, p1, p2, ctx))\n        goto err;\n    if (!BN_mod_inverse(p, p2, p1, ctx))\n        goto err;\n    if (!BN_mul(p, p, p2, ctx))\n        goto err;\n    if (!BN_mod_inverse(t, p1, p2, ctx))\n        goto err;\n    if (!BN_mul(t, t, p1, ctx))\n        goto err;\n    if (!BN_sub(p, p, t))\n        goto err;\n    if (p->neg && !BN_add(p, p, p1p2))\n        goto err;\n    if (!BN_mod_sub(p, p, Xp, p1p2, ctx))\n        goto err;\n    if (!BN_add(p, p, Xp))\n        goto err;\n    for (;;) {\n        int i = 1;\n        BN_GENCB_call(cb, 0, i++);\n        if (!BN_copy(pm1, p))\n            goto err;\n        if (!BN_sub_word(pm1, 1))\n            goto err;\n        if (!BN_gcd(t, pm1, e, ctx))\n            goto err;\n        if (BN_is_one(t)) {\n            int r = BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb);\n            if (r < 0)\n                goto err;\n            if (r)\n                break;\n        }\n        if (!BN_add(p, p, p1p2))\n            goto err;\n    }\n    BN_GENCB_call(cb, 3, 0);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = 0;\n    int top, al, bl;\n    BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    int i;\n#endif\n#ifdef BN_RECURSION\n    BIGNUM *t = NULL;\n    int j = 0, k;\n#endif\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(r);\n    al = a->top;\n    bl = b->top;\n    if ((al == 0) || (bl == 0)) {\n        BN_zero(r);\n        return 1;\n    }\n    top = al + bl;\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == b)) {\n        if ((rr = BN_CTX_get(ctx)) == NULL)\n            goto err;\n    } else\n        rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n    if (i == 0) {\n# if 0\n        if (al == 4) {\n            if (bn_wexpand(rr, 8) == NULL)\n                goto err;\n            rr->top = 8;\n            bn_mul_comba4(rr->d, a->d, b->d);\n            goto end;\n        }\n# endif\n        if (al == 8) {\n            if (bn_wexpand(rr, 16) == NULL)\n                goto err;\n            rr->top = 16;\n            bn_mul_comba8(rr->d, a->d, b->d);\n            goto end;\n        }\n    }\n#endif\n#ifdef BN_RECURSION\n    if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n        if (i >= -1 && i <= 1) {\n            if (i >= 0) {\n                j = BN_num_bits_word((BN_ULONG)al);\n            }\n            if (i == -1) {\n                j = BN_num_bits_word((BN_ULONG)bl);\n            }\n            j = 1 << (j - 1);\n            assert(j <= al || j <= bl);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (t == NULL)\n                goto err;\n            if (al > j || bl > j) {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d,\n                                      j, al - j, bl - j, t->d);\n            } else {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n    }\n#endif\n    if (bn_wexpand(rr, top) == NULL)\n        goto err;\n    rr->top = top;\n    bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n    rr->neg = a->neg ^ b->neg;\n    bn_correct_top(rr);\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\n    ret = 1;\n err:\n    bn_check_top(r);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int ret, r_neg, cmp_res;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->neg != b->neg) {\n        r_neg = a->neg;\n        ret = BN_uadd(r, a, b);\n    } else {\n        cmp_res = BN_ucmp(a, b);\n        if (cmp_res > 0) {\n            r_neg = a->neg;\n            ret = BN_usub(r, a, b);\n        } else if (cmp_res < 0) {\n            r_neg = !b->neg;\n            ret = BN_usub(r, b, a);\n        } else {\n            r_neg = 0;\n            BN_zero(r);\n            ret = 1;\n        }\n    }\n    r->neg = r_neg;\n    bn_check_top(r);\n    return ret;\n}', 'int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    if (!BN_sub(r, a, b))\n        return 0;\n    return BN_nnmod(r, r, m, ctx);\n}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int max, min, dif;\n    BN_ULONG t1, t2, borrow, *rp;\n    const BN_ULONG *ap, *bp;\n    bn_check_top(a);\n    bn_check_top(b);\n    max = a->top;\n    min = b->top;\n    dif = max - min;\n    if (dif < 0) {\n        BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);\n        return 0;\n    }\n    if (bn_wexpand(r, max) == NULL)\n        return 0;\n    ap = a->d;\n    bp = b->d;\n    rp = r->d;\n    borrow = bn_sub_words(rp, ap, bp, min);\n    ap += min;\n    rp += min;\n    while (dif) {\n        dif--;\n        t1 = *(ap++);\n        t2 = (t1 - borrow) & BN_MASK2;\n        *(rp++) = t2;\n        borrow &= (t1 == 0);\n    }\n    while (max && *--rp == 0)\n        max--;\n    r->top = max;\n    r->neg = 0;\n    bn_pollute(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\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}']