crypto/dsa/dsa_gen.c:221: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_sub`.
Showing all 10 steps of the trace


crypto/dsa/dsa_gen.c:221:32: Call
219.               if (!BN_mod(c, X, r0, ctx))
220.                   goto err;
221.               if (!BN_sub(r0, c, BN_value_one()))
                                      ^
222.                   goto err;
223.               if (!BN_sub(p, X, r0))

crypto/bn/bn_lib.c:84:9: Assignment
  82.       static const BN_ULONG data_one = 1L;
  83.       static const BIGNUM const_one =
  84.           { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };
                ^
  85.   
  86.       return &const_one;

crypto/dsa/dsa_gen.c:221:18: Call
219.               if (!BN_mod(c, X, r0, ctx))
220.                   goto err;
221.               if (!BN_sub(r0, c, BN_value_one()))
                        ^
222.                   goto err;
223.               if (!BN_sub(p, X, r0))

crypto/bn/bn_add.c:45:1: Parameter `b->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:59:19: Call
  57.           if (cmp_res > 0) {
  58.               r_neg = a->neg;
  59.               ret = BN_usub(r, a, b);
                          ^
  60.           } else if (cmp_res < 0) {
  61.               r_neg = !b->neg;

crypto/bn/bn_add.c:125:1: <Length trace>
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:125:1: Parameter `b->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:135:5: Assignment
    133.   
    134.       max = a->top;
    135.       min = b->top;
               ^
    136.       dif = max - min;
    137.   

crypto/bn/bn_add.c:152:5: Assignment
    150.       borrow = bn_sub_words(rp, ap, bp, min);
    151.       ap += min;
    152.       rp += min;
               ^
    153.   
    154.       while (dif) {

crypto/bn/bn_add.c:158:9: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_sub` 
    156.           t1 = *(ap++);
    157.           t2 = (t1 - borrow) & BN_MASK2;
    158.           *(rp++) = t2;
                   ^
    159.           borrow &= (t1 == 0);
    160.       }

int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
    int max, min, dif;
    BN_ULONG t1, t2, borrow, *rp;
    const BN_ULONG *ap, *bp;
    bn_check_top(a);
    bn_check_top(b);
    max = a->top;
    min = b->top;
    dif = max - min;
    if (dif < 0) {
        BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);
        return 0;
    }
    if (bn_wexpand(r, max) == NULL)
        return 0;
    ap = a->d;
    bp = b->d;
    rp = r->d;
    borrow = bn_sub_words(rp, ap, bp, min);
    ap += min;
    rp += min;
    while (dif) {
        dif--;
        t1 = *(ap++);
        t2 = (t1 - borrow) & BN_MASK2;
        *(rp++) = t2;
        borrow &= (t1 == 0);
    }
    while (max && *--rp == 0)
        max--;
    r->top = max;
    r->neg = 0;
    bn_pollute(r);
    return 1;
}
['int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,\n                         const EVP_MD *evpmd, const unsigned char *seed_in,\n                         size_t seed_len, unsigned char *seed_out,\n                         int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)\n{\n    int ok = 0;\n    unsigned char seed[SHA256_DIGEST_LENGTH];\n    unsigned char md[SHA256_DIGEST_LENGTH];\n    unsigned char buf[SHA256_DIGEST_LENGTH], buf2[SHA256_DIGEST_LENGTH];\n    BIGNUM *r0, *W, *X, *c, *test;\n    BIGNUM *g = NULL, *q = NULL, *p = NULL;\n    BN_MONT_CTX *mont = NULL;\n    int i, k, n = 0, m = 0, qsize = qbits >> 3;\n    int counter = 0;\n    int r = 0;\n    BN_CTX *ctx = NULL;\n    unsigned int h = 2;\n    if (qsize != SHA_DIGEST_LENGTH && qsize != SHA224_DIGEST_LENGTH &&\n        qsize != SHA256_DIGEST_LENGTH)\n        return 0;\n    if (evpmd == NULL) {\n        if (qsize == SHA_DIGEST_LENGTH)\n            evpmd = EVP_sha1();\n        else if (qsize == SHA224_DIGEST_LENGTH)\n            evpmd = EVP_sha224();\n        else\n            evpmd = EVP_sha256();\n    } else {\n        qsize = EVP_MD_size(evpmd);\n    }\n    if (bits < 512)\n        bits = 512;\n    bits = (bits + 63) / 64 * 64;\n    if (seed_in != NULL) {\n        if (seed_len < (size_t)qsize) {\n            DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN, DSA_R_SEED_LEN_SMALL);\n            return 0;\n        }\n        if (seed_len > (size_t)qsize) {\n            seed_len = qsize;\n        }\n        memcpy(seed, seed_in, seed_len);\n    }\n    if ((mont = BN_MONT_CTX_new()) == NULL)\n        goto err;\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    r0 = BN_CTX_get(ctx);\n    g = BN_CTX_get(ctx);\n    W = BN_CTX_get(ctx);\n    q = BN_CTX_get(ctx);\n    X = BN_CTX_get(ctx);\n    c = BN_CTX_get(ctx);\n    p = BN_CTX_get(ctx);\n    test = BN_CTX_get(ctx);\n    if (test == NULL)\n        goto err;\n    if (!BN_lshift(test, BN_value_one(), bits - 1))\n        goto err;\n    for (;;) {\n        for (;;) {\n            int use_random_seed = (seed_in == NULL);\n            if (!BN_GENCB_call(cb, 0, m++))\n                goto err;\n            if (use_random_seed) {\n                if (RAND_bytes(seed, qsize) <= 0)\n                    goto err;\n            } else {\n                seed_in = NULL;\n            }\n            memcpy(buf, seed, qsize);\n            memcpy(buf2, seed, qsize);\n            for (i = qsize - 1; i >= 0; i--) {\n                buf[i]++;\n                if (buf[i] != 0)\n                    break;\n            }\n            if (!EVP_Digest(seed, qsize, md, NULL, evpmd, NULL))\n                goto err;\n            if (!EVP_Digest(buf, qsize, buf2, NULL, evpmd, NULL))\n                goto err;\n            for (i = 0; i < qsize; i++)\n                md[i] ^= buf2[i];\n            md[0] |= 0x80;\n            md[qsize - 1] |= 0x01;\n            if (!BN_bin2bn(md, qsize, q))\n                goto err;\n            r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n                                        use_random_seed, cb);\n            if (r > 0)\n                break;\n            if (r != 0)\n                goto err;\n        }\n        if (!BN_GENCB_call(cb, 2, 0))\n            goto err;\n        if (!BN_GENCB_call(cb, 3, 0))\n            goto err;\n        counter = 0;\n        n = (bits - 1) / 160;\n        for (;;) {\n            if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))\n                goto err;\n            BN_zero(W);\n            for (k = 0; k <= n; k++) {\n                for (i = qsize - 1; i >= 0; i--) {\n                    buf[i]++;\n                    if (buf[i] != 0)\n                        break;\n                }\n                if (!EVP_Digest(buf, qsize, md, NULL, evpmd, NULL))\n                    goto err;\n                if (!BN_bin2bn(md, qsize, r0))\n                    goto err;\n                if (!BN_lshift(r0, r0, (qsize << 3) * k))\n                    goto err;\n                if (!BN_add(W, W, r0))\n                    goto err;\n            }\n            if (!BN_mask_bits(W, bits - 1))\n                goto err;\n            if (!BN_copy(X, W))\n                goto err;\n            if (!BN_add(X, X, test))\n                goto err;\n            if (!BN_lshift1(r0, q))\n                goto err;\n            if (!BN_mod(c, X, r0, ctx))\n                goto err;\n            if (!BN_sub(r0, c, BN_value_one()))\n                goto err;\n            if (!BN_sub(p, X, r0))\n                goto err;\n            if (BN_cmp(p, test) >= 0) {\n                r = BN_is_prime_fasttest_ex(p, DSS_prime_checks, ctx, 1, cb);\n                if (r > 0)\n                    goto end;\n                if (r != 0)\n                    goto err;\n            }\n            counter++;\n            if (counter >= 4096)\n                break;\n        }\n    }\n end:\n    if (!BN_GENCB_call(cb, 2, 1))\n        goto err;\n    if (!BN_sub(test, p, BN_value_one()))\n        goto err;\n    if (!BN_div(r0, NULL, test, q, ctx))\n        goto err;\n    if (!BN_set_word(test, h))\n        goto err;\n    if (!BN_MONT_CTX_set(mont, p, ctx))\n        goto err;\n    for (;;) {\n        if (!BN_mod_exp_mont(g, test, r0, p, ctx, mont))\n            goto err;\n        if (!BN_is_one(g))\n            break;\n        if (!BN_add(test, test, BN_value_one()))\n            goto err;\n        h++;\n    }\n    if (!BN_GENCB_call(cb, 3, 1))\n        goto err;\n    ok = 1;\n err:\n    if (ok) {\n        BN_free(ret->p);\n        BN_free(ret->q);\n        BN_free(ret->g);\n        ret->p = BN_dup(p);\n        ret->q = BN_dup(q);\n        ret->g = BN_dup(g);\n        if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {\n            ok = 0;\n            goto err;\n        }\n        if (counter_ret != NULL)\n            *counter_ret = counter;\n        if (h_ret != NULL)\n            *h_ret = h;\n        if (seed_out)\n            memcpy(seed_out, seed, qsize);\n    }\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    BN_MONT_CTX_free(mont);\n    return ok;\n}', 'const BIGNUM *BN_value_one(void)\n{\n    static const BN_ULONG data_one = 1L;\n    static const BIGNUM const_one =\n        { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n    return &const_one;\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_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}']