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


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

crypto/bn/bn_lib.c:166:9: Call
  164.       bn_check_top(a);
  165.   
  166.       if (BN_is_zero(a))
                 ^
  167.           return 0;
  168.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:852:1: Parameter `a->top`
    850.   }
    851.   
    852. > int BN_is_zero(const BIGNUM *a)
    853.   {
    854.       return a->top == 0;

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

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:91:1: Parameter `m->top`
      89.   }
      90.   
      91. > int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
      92.                  BN_CTX *ctx)
      93.   {

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

crypto/bn/bn_lib.c:867:1: Parameter `a->top`
        865.   }
        866.   
        867. > int BN_is_odd(const BIGNUM *a)
        868.   {
        869.       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:198:14: Call
        196.       if (m->neg) {
        197.           /* ignore sign of 'm' */
        198.           if (!BN_copy(aa, m))
                            ^
        199.               goto err;
        200.           aa->neg = 0;

crypto/bn/bn_lib.c:323:1: <Offset trace>
321.   }
322.   
323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
324.   {
325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: Parameter `b->top`
          321.   }
          322.   
          323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
          324.   {
          325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: <Length trace>
321.   }
322.   
323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
324.   {
325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: Parameter `*a->d`
          321.   }
          322.   
          323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
          324.   {
          325.       bn_check_top(b);

crypto/bn/bn_lib.c:329:9: Call
          327.       if (a == b)
          328.           return a;
          329.       if (bn_wexpand(a, b->top) == NULL)
                         ^
          330.           return NULL;
          331.   

crypto/bn/bn_lib.c:948:1: Parameter `*a->d`
            946.   }
            947.   
            948. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
            949.   {
            950.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:333:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `DSA_generate_key` 
          331.   
          332.       if (b->top > 0)
          333.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                         ^
          334.   
          335.       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 *inrand = NULL, *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_RAND:\n            inrand = opt_arg();\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    if (!app_RAND_load_file(NULL, 1) && inrand == NULL) {\n        BIO_printf(bio_err,\n                   "warning, not much extra random data, consider using the -rand option\\n");\n    }\n    if (inrand != NULL)\n        BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n                   app_RAND_load_files(inrand));\n    DSA_get0_pqg(dsa, &p, NULL, NULL);\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    app_RAND_write_file(NULL);\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_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_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        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_is_one(m)) {\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 (!aa || !val[0])\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}']