apps/gendsa.c:128: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `DSA_generate_key`.
Showing all 24 steps of the trace


apps/gendsa.c:121:9: Call
119.       DSA_get0_pqg(dsa, &p, NULL, NULL);
120.   
121.       if (BN_num_bits(p) > OPENSSL_DSA_MAX_MODULUS_BITS)
               ^
122.           BIO_printf(bio_err,
123.                      "Warning: It is not recommended to use more than %d bit for DSA keys.\n"

crypto/bn/bn_lib.c:139:9: Call
  137.       bn_check_top(a);
  138.   
  139.       if (BN_is_zero(a))
                 ^
  140.           return 0;
  141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:845:1: Parameter `a->top`
    843.   }
    844.   
    845. > int BN_is_zero(const BIGNUM *a)
    846.   {
    847.       return a->top == 0;

apps/gendsa.c:127:58: Call
125.                      OPENSSL_DSA_MAX_MODULUS_BITS, BN_num_bits(p));
126.   
127.       BIO_printf(bio_err, "Generating DSA key, %d bits\n", BN_num_bits(p));
                                                                ^
128.       if (!DSA_generate_key(dsa))
129.           goto end;

crypto/bn/bn_lib.c:139:9: Call
  137.       bn_check_top(a);
  138.   
  139.       if (BN_is_zero(a))
                 ^
  140.           return 0;
  141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:845:1: Parameter `a->top`
    843.   }
    844.   
    845. > int BN_is_zero(const BIGNUM *a)
    846.   {
    847.       return a->top == 0;

apps/gendsa.c:128:10: Call
126.   
127.       BIO_printf(bio_err, "Generating DSA key, %d bits\n", BN_num_bits(p));
128.       if (!DSA_generate_key(dsa))
                ^
129.           goto end;
130.   

crypto/dsa/dsa_key.c:18:1: Parameter `dsa->p->top`
  16.   static int dsa_builtin_keygen(DSA *dsa);
  17.   
  18. > int DSA_generate_key(DSA *dsa)
  19.   {
  20.       if (dsa->meth->dsa_keygen)

crypto/dsa/dsa_key.c:22:12: Call
  20.       if (dsa->meth->dsa_keygen)
  21.           return dsa->meth->dsa_keygen(dsa);
  22.       return dsa_builtin_keygen(dsa);
                   ^
  23.   }
  24.   

crypto/dsa/dsa_key.c:25:1: Parameter `dsa->p->top`
    23.   }
    24.   
    25. > static int dsa_builtin_keygen(DSA *dsa)
    26.   {
    27.       int ok = 0;

crypto/dsa/dsa_key.c:58:14: Call
    56.           BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
    57.   
    58.           if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {
                       ^
    59.               BN_free(prk);
    60.               goto err;

crypto/bn/bn_exp.c:89:1: Parameter `m->top`
      87.   }
      88.   
      89. > int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
      90.                  BN_CTX *ctx)
      91.   {

crypto/bn/bn_exp.c:134:9: Call
      132.   
      133.   #ifdef MONT_MUL_MOD
      134.       if (BN_is_odd(m)) {
                     ^
      135.   # ifdef MONT_EXP_WORD
      136.           if (a->top == 1 && !a->neg

crypto/bn/bn_lib.c:860:1: Parameter `a->top`
        858.   }
        859.   
        860. > int BN_is_odd(const BIGNUM *a)
        861.   {
        862.       return (a->top > 0) && (a->d[0] & 1);

crypto/bn/bn_exp.c:149:15: Call
      147.   #ifdef RECP_MUL_MOD
      148.       {
      149.           ret = BN_mod_exp_recp(r, a, p, m, ctx);
                           ^
      150.       }
      151.   #else

crypto/bn/bn_exp.c:161:1: Parameter `m->top`
        159.   }
        160.   
        161. > int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
        162.                       const BIGNUM *m, BN_CTX *ctx)
        163.   {

crypto/bn/bn_exp.c:200:14: Call
        198.       if (m->neg) {
        199.           /* ignore sign of 'm' */
        200.           if (!BN_copy(aa, m))
                            ^
        201.               goto err;
        202.           aa->neg = 0;

crypto/bn/bn_lib.c:285:1: <Offset trace>
283.   }
284.   
285. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
286.   {
287.       bn_check_top(b);

crypto/bn/bn_lib.c:285:1: Parameter `b->top`
          283.   }
          284.   
          285. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
          286.   {
          287.       bn_check_top(b);

crypto/bn/bn_lib.c:285:1: <Length trace>
283.   }
284.   
285. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
286.   {
287.       bn_check_top(b);

crypto/bn/bn_lib.c:285:1: Parameter `*a->d`
          283.   }
          284.   
          285. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
          286.   {
          287.       bn_check_top(b);

crypto/bn/bn_lib.c:291:9: Call
          289.       if (a == b)
          290.           return a;
          291.       if (bn_wexpand(a, b->top) == NULL)
                         ^
          292.           return NULL;
          293.   

crypto/bn/bn_lib.c:941:1: Parameter `*a->d`
            939.   }
            940.   
            941. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
            942.   {
            943.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:295:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `DSA_generate_key` 
          293.   
          294.       if (b->top > 0)
          295.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                         ^
          296.   
          297.       a->top = b->top;

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return a;
}
['int gendsa_main(int argc, char **argv)\n{\n    ENGINE *e = NULL;\n    BIO *out = NULL, *in = NULL;\n    DSA *dsa = NULL;\n    const EVP_CIPHER *enc = NULL;\n    char *dsaparams = NULL;\n    char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;\n    OPTION_CHOICE o;\n    int ret = 1, private = 0;\n    const BIGNUM *p = NULL;\n    prog = opt_init(argc, argv, gendsa_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            ret = 0;\n            opt_help(gendsa_options);\n            goto end;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_PASSOUT:\n            passoutarg = opt_arg();\n            break;\n        case OPT_ENGINE:\n            e = setup_engine(opt_arg(), 0);\n            break;\n        case OPT_R_CASES:\n            if (!opt_rand(o))\n                goto end;\n            break;\n        case OPT_CIPHER:\n            if (!opt_cipher(opt_unknown(), &enc))\n                goto end;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    private = 1;\n    if (argc != 1)\n        goto opthelp;\n    dsaparams = *argv;\n    if (!app_passwd(NULL, passoutarg, NULL, &passout)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    in = bio_open_default(dsaparams, \'r\', FORMAT_PEM);\n    if (in == NULL)\n        goto end2;\n    if ((dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL)) == NULL) {\n        BIO_printf(bio_err, "unable to load DSA parameter file\\n");\n        goto end;\n    }\n    BIO_free(in);\n    in = NULL;\n    out = bio_open_owner(outfile, FORMAT_PEM, private);\n    if (out == NULL)\n        goto end2;\n    DSA_get0_pqg(dsa, &p, NULL, NULL);\n    if (BN_num_bits(p) > OPENSSL_DSA_MAX_MODULUS_BITS)\n        BIO_printf(bio_err,\n                   "Warning: It is not recommended to use more than %d bit for DSA keys.\\n"\n                   "         Your key size is %d! Larger key size may behave not as expected.\\n",\n                   OPENSSL_DSA_MAX_MODULUS_BITS, BN_num_bits(p));\n    BIO_printf(bio_err, "Generating DSA key, %d bits\\n", BN_num_bits(p));\n    if (!DSA_generate_key(dsa))\n        goto end;\n    assert(private);\n    if (!PEM_write_bio_DSAPrivateKey(out, dsa, enc, NULL, 0, NULL, passout))\n        goto end;\n    ret = 0;\n end:\n    if (ret != 0)\n        ERR_print_errors(bio_err);\n end2:\n    BIO_free(in);\n    BIO_free_all(out);\n    DSA_free(dsa);\n    release_engine(e);\n    OPENSSL_free(passout);\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}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'int DSA_generate_key(DSA *dsa)\n{\n    if (dsa->meth->dsa_keygen)\n        return dsa->meth->dsa_keygen(dsa);\n    return dsa_builtin_keygen(dsa);\n}', 'static int dsa_builtin_keygen(DSA *dsa)\n{\n    int ok = 0;\n    BN_CTX *ctx = NULL;\n    BIGNUM *pub_key = NULL, *priv_key = NULL;\n    if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    if (dsa->priv_key == NULL) {\n        if ((priv_key = BN_secure_new()) == NULL)\n            goto err;\n    } else\n        priv_key = dsa->priv_key;\n    do\n        if (!BN_priv_rand_range(priv_key, dsa->q))\n            goto err;\n    while (BN_is_zero(priv_key)) ;\n    if (dsa->pub_key == NULL) {\n        if ((pub_key = BN_new()) == NULL)\n            goto err;\n    } else\n        pub_key = dsa->pub_key;\n    {\n        BIGNUM *prk = BN_new();\n        if (prk == NULL)\n            goto err;\n        BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n        if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {\n            BN_free(prk);\n            goto err;\n        }\n        BN_free(prk);\n    }\n    dsa->priv_key = priv_key;\n    dsa->pub_key = pub_key;\n    ok = 1;\n err:\n    if (pub_key != dsa->pub_key)\n        BN_free(pub_key);\n    if (priv_key != dsa->priv_key)\n        BN_free(priv_key);\n    BN_CTX_free(ctx);\n    return ok;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    int ret;\n    bn_check_top(a);\n    bn_check_top(p);\n    bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n    if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n        if (a->top == 1 && !a->neg\n            && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n            && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n            && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n            BN_ULONG A = a->d[0];\n            ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n        } else\n# endif\n            ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n    } else\n#endif\n#ifdef RECP_MUL_MOD\n    {\n        ret = BN_mod_exp_recp(r, a, p, m, ctx);\n    }\n#else\n    {\n        ret = BN_mod_exp_simple(r, a, p, m, ctx);\n    }\n#endif\n    bn_check_top(r);\n    return ret;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n    return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n                    const BIGNUM *m, BN_CTX *ctx)\n{\n    int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n    int start = 1;\n    BIGNUM *aa;\n    BIGNUM *val[TABLE_SIZE];\n    BN_RECP_CTX recp;\n    if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n            || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n            || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n        BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    bits = BN_num_bits(p);\n    if (bits == 0) {\n        if (BN_abs_is_word(m, 1)) {\n            ret = 1;\n            BN_zero(r);\n        } else {\n            ret = BN_one(r);\n        }\n        return ret;\n    }\n    BN_CTX_start(ctx);\n    aa = BN_CTX_get(ctx);\n    val[0] = BN_CTX_get(ctx);\n    if (val[0] == NULL)\n        goto err;\n    BN_RECP_CTX_init(&recp);\n    if (m->neg) {\n        if (!BN_copy(aa, m))\n            goto err;\n        aa->neg = 0;\n        if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n            goto err;\n    } else {\n        if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n            goto err;\n    }\n    if (!BN_nnmod(val[0], a, m, ctx))\n        goto err;\n    if (BN_is_zero(val[0])) {\n        BN_zero(r);\n        ret = 1;\n        goto err;\n    }\n    window = BN_window_bits_for_exponent_size(bits);\n    if (window > 1) {\n        if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n            goto err;\n        j = 1 << (window - 1);\n        for (i = 1; i < j; i++) {\n            if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n                !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n                goto err;\n        }\n    }\n    start = 1;\n    wvalue = 0;\n    wstart = bits - 1;\n    wend = 0;\n    if (!BN_one(r))\n        goto err;\n    for (;;) {\n        if (BN_is_bit_set(p, wstart) == 0) {\n            if (!start)\n                if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n                    goto err;\n            if (wstart == 0)\n                break;\n            wstart--;\n            continue;\n        }\n        j = wstart;\n        wvalue = 1;\n        wend = 0;\n        for (i = 1; i < window; i++) {\n            if (wstart - i < 0)\n                break;\n            if (BN_is_bit_set(p, wstart - i)) {\n                wvalue <<= (i - wend);\n                wvalue |= 1;\n                wend = i;\n            }\n        }\n        j = wend + 1;\n        if (!start)\n            for (i = 0; i < j; i++) {\n                if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n                    goto err;\n            }\n        if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n            goto err;\n        wstart -= wend + 1;\n        wvalue = 0;\n        start = 0;\n        if (wstart < 0)\n            break;\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    BN_RECP_CTX_free(&recp);\n    bn_check_top(r);\n    return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']