crypto/dsa/dsa_gen.c:481: error: INTEGER_OVERFLOW_L2
  ([0, `N`] - 1):unsigned32 by call to `BN_bin2bn`.
Showing all 7 steps of the trace


crypto/dsa/dsa_gen.c:375:1: Parameter `N`
373.    */
374.   
375. > int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,
376.                             const EVP_MD *evpmd, const unsigned char *seed_in,
377.                             size_t seed_len, int idx, unsigned char *seed_out,

crypto/dsa/dsa_gen.c:388:5: Assignment
386.       BIGNUM *g = NULL, *q = NULL, *p = NULL;
387.       BN_MONT_CTX *mont = NULL;
388.       int i, k, n = 0, m = 0, qsize = N >> 3;
           ^
389.       int counter = 0;
390.       int r = 0;

crypto/dsa/dsa_gen.c:481:18: Call
479.               pmd[0] |= 0x80;
480.               pmd[qsize - 1] |= 0x01;
481.               if (!BN_bin2bn(pmd, qsize, q))
                        ^
482.                   goto err;
483.   

crypto/bn/bn_lib.c:546:1: <LHS trace>
544.   }
545.   
546. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
547.   {
548.       unsigned int i, m;

crypto/bn/bn_lib.c:546:1: Parameter `len`
  544.   }
  545.   
  546. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  547.   {
  548.       unsigned int i, m;

crypto/bn/bn_lib.c:559:5: Assignment
  557.       bn_check_top(ret);
  558.       l = 0;
  559.       n = len;
             ^
  560.       if (n == 0) {
  561.           ret->top = 0;

crypto/bn/bn_lib.c:564:5: Binary operation: ([0, N] - 1):unsigned32 by call to `BN_bin2bn` 
  562.           return (ret);
  563.       }
  564.       i = ((n - 1) / BN_BYTES) + 1;
             ^
  565.       m = ((n - 1) % (BN_BYTES));
  566.       if (bn_wexpand(ret, (int)i) == NULL) {

BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
{
    unsigned int i, m;
    unsigned int n;
    BN_ULONG l;
    BIGNUM *bn = NULL;
    if (ret == NULL)
        ret = bn = BN_new();
    if (ret == NULL)
        return (NULL);
    bn_check_top(ret);
    l = 0;
    n = len;
    if (n == 0) {
        ret->top = 0;
        return (ret);
    }
    i = ((n - 1) / BN_BYTES) + 1;
    m = ((n - 1) % (BN_BYTES));
    if (bn_wexpand(ret, (int)i) == NULL) {
        if (bn)
            BN_free(bn);
        return NULL;
    }
    ret->top = i;
    ret->neg = 0;
    while (n--) {
        l = (l << 8L) | *(s++);
        if (m-- == 0) {
            ret->d[--i] = l;
            l = 0;
            m = BN_BYTES - 1;
        }
    }
    bn_correct_top(ret);
    return (ret);
}
['int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,\n                          const EVP_MD *evpmd, const unsigned char *seed_in,\n                          size_t seed_len, int idx, unsigned char *seed_out,\n                          int *counter_ret, unsigned long *h_ret,\n                          BN_GENCB *cb)\n{\n    int ok = -1;\n    unsigned char *seed = NULL, *seed_tmp = NULL;\n    unsigned char md[EVP_MAX_MD_SIZE];\n    int mdsize;\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 = N >> 3;\n    int counter = 0;\n    int r = 0;\n    BN_CTX *ctx = NULL;\n    EVP_MD_CTX mctx;\n    unsigned int h = 2;\n    EVP_MD_CTX_init(&mctx);\n    if (evpmd == NULL) {\n        if (N == 160)\n            evpmd = EVP_sha1();\n        else if (N == 224)\n            evpmd = EVP_sha224();\n        else\n            evpmd = EVP_sha256();\n    }\n    mdsize = M_EVP_MD_size(evpmd);\n    if (!ret->p || !ret->q || idx >= 0) {\n        if (seed_len == 0)\n            seed_len = mdsize;\n        seed = OPENSSL_malloc(seed_len);\n        if (seed_out)\n            seed_tmp = seed_out;\n        else\n            seed_tmp = OPENSSL_malloc(seed_len);\n        if (!seed || !seed_tmp)\n            goto err;\n        if (seed_in)\n            memcpy(seed, seed_in, seed_len);\n    }\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    if ((mont = BN_MONT_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    X = BN_CTX_get(ctx);\n    c = BN_CTX_get(ctx);\n    test = BN_CTX_get(ctx);\n    if (ret->p && ret->q) {\n        p = ret->p;\n        q = ret->q;\n        if (idx >= 0)\n            memcpy(seed_tmp, seed, seed_len);\n        goto g_only;\n    } else {\n        p = BN_CTX_get(ctx);\n        q = BN_CTX_get(ctx);\n    }\n    if (!BN_lshift(test, BN_value_one(), L - 1))\n        goto err;\n    for (;;) {\n        for (;;) {\n            unsigned char *pmd;\n            if (!BN_GENCB_call(cb, 0, m++))\n                goto err;\n            if (!seed_in) {\n                if (RAND_pseudo_bytes(seed, seed_len) < 0)\n                    goto err;\n            }\n            if (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n                goto err;\n            if (mdsize > qsize)\n                pmd = md + mdsize - qsize;\n            else\n                pmd = md;\n            if (mdsize < qsize)\n                memset(md + mdsize, 0, qsize - mdsize);\n            pmd[0] |= 0x80;\n            pmd[qsize - 1] |= 0x01;\n            if (!BN_bin2bn(pmd, qsize, q))\n                goto err;\n            r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n                                        seed_in ? 1 : 0, cb);\n            if (r > 0)\n                break;\n            if (r != 0)\n                goto err;\n            if (seed_in) {\n                ok = 0;\n                DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_Q_NOT_PRIME);\n                goto err;\n            }\n        }\n        if (seed_out)\n            memcpy(seed_out, seed, seed_len);\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 = (L - 1) / (mdsize << 3);\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 = seed_len - 1; i >= 0; i--) {\n                    seed[i]++;\n                    if (seed[i] != 0)\n                        break;\n                }\n                if (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n                    goto err;\n                if (!BN_bin2bn(md, mdsize, r0))\n                    goto err;\n                if (!BN_lshift(r0, r0, (mdsize << 3) * k))\n                    goto err;\n                if (!BN_add(W, W, r0))\n                    goto err;\n            }\n            if (!BN_mask_bits(W, L - 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 >= (int)(4 * L))\n                break;\n        }\n        if (seed_in) {\n            ok = 0;\n            DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_INVALID_PARAMETERS);\n            goto err;\n        }\n    }\n end:\n    if (!BN_GENCB_call(cb, 2, 1))\n        goto err;\n g_only:\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 (idx < 0) {\n        if (!BN_set_word(test, h))\n            goto err;\n    } else\n        h = 1;\n    if (!BN_MONT_CTX_set(mont, p, ctx))\n        goto err;\n    for (;;) {\n        static const unsigned char ggen[4] = { 0x67, 0x67, 0x65, 0x6e };\n        if (idx >= 0) {\n            md[0] = idx & 0xff;\n            md[1] = (h >> 8) & 0xff;\n            md[2] = h & 0xff;\n            if (!EVP_DigestInit_ex(&mctx, evpmd, NULL))\n                goto err;\n            if (!EVP_DigestUpdate(&mctx, seed_tmp, seed_len))\n                goto err;\n            if (!EVP_DigestUpdate(&mctx, ggen, sizeof(ggen)))\n                goto err;\n            if (!EVP_DigestUpdate(&mctx, md, 3))\n                goto err;\n            if (!EVP_DigestFinal_ex(&mctx, md, NULL))\n                goto err;\n            if (!BN_bin2bn(md, mdsize, test))\n                goto err;\n        }\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 (idx < 0 && !BN_add(test, test, BN_value_one()))\n            goto err;\n        h++;\n        if (idx >= 0 && h > 0xffff)\n            goto err;\n    }\n    if (!BN_GENCB_call(cb, 3, 1))\n        goto err;\n    ok = 1;\n err:\n    if (ok == 1) {\n        if (p != ret->p) {\n            if (ret->p)\n                BN_free(ret->p);\n            ret->p = BN_dup(p);\n        }\n        if (q != ret->q) {\n            if (ret->q)\n                BN_free(ret->q);\n            ret->q = BN_dup(q);\n        }\n        if (ret->g)\n            BN_free(ret->g);\n        ret->g = BN_dup(g);\n        if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {\n            ok = -1;\n            goto err;\n        }\n        if (counter_ret != NULL)\n            *counter_ret = counter;\n        if (h_ret != NULL)\n            *h_ret = h;\n    }\n    if (seed)\n        OPENSSL_free(seed);\n    if (seed_out != seed_tmp)\n        OPENSSL_free(seed_tmp);\n    if (ctx) {\n        BN_CTX_end(ctx);\n        BN_CTX_free(ctx);\n    }\n    if (mont != NULL)\n        BN_MONT_CTX_free(mont);\n    EVP_MD_CTX_cleanup(&mctx);\n    return ok;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return (NULL);\n    bn_check_top(ret);\n    l = 0;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return (ret);\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        if (bn)\n            BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return (ret);\n}']