apps/dhparam.c:312: error: NULL_DEREFERENCE
  pointer `infile` last assigned on line 170 could be null and is dereferenced by call to `bio_open_default()` at line 312, column 14.
Showing all 53 steps of the trace


apps/dhparam.c:166:1: start of procedure dhparam_main()
164.   };
165.   
166. > int dhparam_main(int argc, char **argv)
167.   {
168.       BIO *in = NULL, *out = NULL;

apps/dhparam.c:168:5: 
166.   int dhparam_main(int argc, char **argv)
167.   {
168. >     BIO *in = NULL, *out = NULL;
169.       DH *dh = NULL;
170.       char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;

apps/dhparam.c:169:5: 
167.   {
168.       BIO *in = NULL, *out = NULL;
169. >     DH *dh = NULL;
170.       char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;
171.       int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0;

apps/dhparam.c:170:5: 
168.       BIO *in = NULL, *out = NULL;
169.       DH *dh = NULL;
170. >     char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;
171.       int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0;
172.       int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;

apps/dhparam.c:171:5: 
169.       DH *dh = NULL;
170.       char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;
171. >     int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0;
172.       int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;
173.       OPTION_CHOICE o;

apps/dhparam.c:172:5: 
170.       char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;
171.       int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0;
172. >     int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;
173.       OPTION_CHOICE o;
174.   

apps/dhparam.c:175:5: Skipping opt_init(): empty list of specs
173.       OPTION_CHOICE o;
174.   
175.       prog = opt_init(argc, argv, dhparam_options);
           ^
176.       while ((o = opt_next()) != OPT_EOF) {
177.           switch (o) {

apps/dhparam.c:176:12: Loop condition is false. Leaving loop
174.   
175.       prog = opt_init(argc, argv, dhparam_options);
176.       while ((o = opt_next()) != OPT_EOF) {
                  ^
177.           switch (o) {
178.           case OPT_EOF:

apps/dhparam.c:230:5: 
228.           }
229.       }
230. >     argc = opt_num_rest();
231.       argv = opt_rest();
232.   

apps/opt.c:717:1: start of procedure opt_num_rest()
  715.   
  716.   /* How many items in remaining args? */
  717. > int opt_num_rest(void)
  718.   {
  719.       int i = 0;

apps/opt.c:719:5: 
  717.   int opt_num_rest(void)
  718.   {
  719. >     int i = 0;
  720.       char **pp;
  721.   

apps/opt.c:722:10: 
  720.       char **pp;
  721.   
  722. >     for (pp = opt_rest(); *pp; pp++, i++)
  723.           continue;
  724.       return i;

apps/opt.c:711:1: start of procedure opt_rest()
    709.   
    710.   /* Return the rest of the arguments after parsing flags. */
    711. > char **opt_rest(void)
    712.   {
    713.       return &argv[opt_index];

apps/opt.c:713:5: 
    711.   char **opt_rest(void)
    712.   {
    713. >     return &argv[opt_index];
    714.   }
    715.   

apps/opt.c:714:1: return from a call to opt_rest
    712.   {
    713.       return &argv[opt_index];
    714. > }
    715.   
    716.   /* How many items in remaining args? */

apps/opt.c:722:27: Loop condition is false. Leaving loop
  720.       char **pp;
  721.   
  722.       for (pp = opt_rest(); *pp; pp++, i++)
                                   ^
  723.           continue;
  724.       return i;

apps/opt.c:724:5: 
  722.       for (pp = opt_rest(); *pp; pp++, i++)
  723.           continue;
  724. >     return i;
  725.   }
  726.   

apps/opt.c:725:1: return from a call to opt_num_rest
  723.           continue;
  724.       return i;
  725. > }
  726.   
  727.   /* Return a string describing the parameter type. */

apps/dhparam.c:231:5: 
229.       }
230.       argc = opt_num_rest();
231. >     argv = opt_rest();
232.   
233.       if (!app_load_modules(NULL))

apps/opt.c:711:1: start of procedure opt_rest()
  709.   
  710.   /* Return the rest of the arguments after parsing flags. */
  711. > char **opt_rest(void)
  712.   {
  713.       return &argv[opt_index];

apps/opt.c:713:5: 
  711.   char **opt_rest(void)
  712.   {
  713. >     return &argv[opt_index];
  714.   }
  715.   

apps/opt.c:714:1: return from a call to opt_rest
  712.   {
  713.       return &argv[opt_index];
  714. > }
  715.   
  716.   /* How many items in remaining args? */

apps/dhparam.c:233:10: 
231.       argv = opt_rest();
232.   
233. >     if (!app_load_modules(NULL))
234.           goto end;
235.   

apps/apps.c:539:1: start of procedure app_load_modules()
  537.   }
  538.   
  539. > int app_load_modules(const CONF *config)
  540.   {
  541.       CONF *to_free = NULL;

apps/apps.c:541:5: 
  539.   int app_load_modules(const CONF *config)
  540.   {
  541. >     CONF *to_free = NULL;
  542.   
  543.       if (config == NULL)

apps/apps.c:543:9: Taking true branch
  541.       CONF *to_free = NULL;
  542.   
  543.       if (config == NULL)
                 ^
  544.   	config = to_free = app_load_config_quiet(default_config_file);
  545.       if (config == NULL)

apps/apps.c:544:2: Skipping app_load_config_quiet(): empty list of specs
  542.   
  543.       if (config == NULL)
  544.   	config = to_free = app_load_config_quiet(default_config_file);
          ^
  545.       if (config == NULL)
  546.   	return 1;

apps/apps.c:545:9: Taking true branch
  543.       if (config == NULL)
  544.   	config = to_free = app_load_config_quiet(default_config_file);
  545.       if (config == NULL)
                 ^
  546.   	return 1;
  547.   

apps/apps.c:546:2: 
  544.   	config = to_free = app_load_config_quiet(default_config_file);
  545.       if (config == NULL)
  546. > 	return 1;
  547.   
  548.       if (CONF_modules_load(config, NULL, 0) <= 0) {

apps/apps.c:556:1: return from a call to app_load_modules
  554.       NCONF_free(to_free);
  555.       return 1;
  556. > }
  557.   
  558.   int add_oid_section(CONF *conf)

apps/dhparam.c:233:10: Taking false branch
231.       argv = opt_rest();
232.   
233.       if (!app_load_modules(NULL))
                ^
234.           goto end;
235.   

apps/dhparam.c:236:9: Taking false branch
234.           goto end;
235.   
236.       if (argv[0] && (!opt_int(argv[0], &num) || num <= 0))
               ^
237.           goto end;
238.   

apps/dhparam.c:239:9: Taking false branch
237.           goto end;
238.   
239.       if (g && !num)
               ^
240.           num = DEFBITS;
241.   

apps/dhparam.c:243:9: Taking false branch
241.   
242.   # ifndef OPENSSL_NO_DSA
243.       if (dsaparam && g) {
               ^
244.           BIO_printf(bio_err,
245.                      "generator may not be chosen for DSA parameters\n");

apps/dhparam.c:250:9: Taking false branch
248.   # endif
249.       /* DH parameters */
250.       if (num && !g)
               ^
251.           g = 2;
252.   

apps/dhparam.c:253:9: Taking false branch
251.           g = 2;
252.   
253.       if (num) {
               ^
254.   
255.           BN_GENCB *cb;

apps/dhparam.c:312:39: Condition is false
310.       } else {
311.   
312.           in = bio_open_default(infile, RB(informat));
                                             ^
313.           if (in == NULL)
314.               goto end;

apps/dhparam.c:312:9: 
310.       } else {
311.   
312. >         in = bio_open_default(infile, RB(informat));
313.           if (in == NULL)
314.               goto end;

apps/openssl.c:387:1: start of procedure bio_open_default()
  385.   }
  386.   
  387. > BIO *bio_open_default(const char *filename, const char *mode)
  388.   {
  389.       return bio_open_default_(filename, mode, 0);

apps/openssl.c:389:5: 
  387.   BIO *bio_open_default(const char *filename, const char *mode)
  388.   {
  389. >     return bio_open_default_(filename, mode, 0);
  390.   }
  391.   

apps/openssl.c:355:1: start of procedure bio_open_default_()
    353.   }
    354.   
    355. > static BIO *bio_open_default_(const char *filename, const char *mode, int quiet)
    356.   {
    357.       BIO *ret;

apps/openssl.c:359:9: Taking false branch
    357.       BIO *ret;
    358.   
    359.       if (filename == NULL || strcmp(filename, "-") == 0) {
                   ^
    360.           ret = *mode == 'r' ? dup_bio_in() : dup_bio_out();
    361.           if (quiet) {

apps/openssl.c:359:29: Taking true branch
    357.       BIO *ret;
    358.   
    359.       if (filename == NULL || strcmp(filename, "-") == 0) {
                                       ^
    360.           ret = *mode == 'r' ? dup_bio_in() : dup_bio_out();
    361.           if (quiet) {

apps/openssl.c:360:15: Condition is true
    358.   
    359.       if (filename == NULL || strcmp(filename, "-") == 0) {
    360.           ret = *mode == 'r' ? dup_bio_in() : dup_bio_out();
                         ^
    361.           if (quiet) {
    362.               ERR_clear_error();

apps/openssl.c:283:1: start of procedure dup_bio_in()
      281.   }
      282.   
      283. > BIO *dup_bio_in(void)
      284.   {
      285.       return BIO_new_fp(stdin, BIO_NOCLOSE | BIO_FP_TEXT);

apps/openssl.c:285:5: Skipping BIO_new_fp(): empty list of specs
      283.   BIO *dup_bio_in(void)
      284.   {
      285.       return BIO_new_fp(stdin, BIO_NOCLOSE | BIO_FP_TEXT);
                 ^
      286.   }
      287.   

apps/openssl.c:286:1: return from a call to dup_bio_in
      284.   {
      285.       return BIO_new_fp(stdin, BIO_NOCLOSE | BIO_FP_TEXT);
      286. > }
      287.   
      288.   BIO *dup_bio_out(void)

apps/openssl.c:360:9: 
    358.   
    359.       if (filename == NULL || strcmp(filename, "-") == 0) {
    360. >         ret = *mode == 'r' ? dup_bio_in() : dup_bio_out();
    361.           if (quiet) {
    362.               ERR_clear_error();

apps/openssl.c:361:13: Taking false branch
    359.       if (filename == NULL || strcmp(filename, "-") == 0) {
    360.           ret = *mode == 'r' ? dup_bio_in() : dup_bio_out();
    361.           if (quiet) {
                       ^
    362.               ERR_clear_error();
    363.               return ret;

apps/openssl.c:365:13: Taking true branch
    363.               return ret;
    364.           }
    365.           if (ret != NULL)
                       ^
    366.               return ret;
    367.           BIO_printf(bio_err,

apps/openssl.c:366:13: 
    364.           }
    365.           if (ret != NULL)
    366. >             return ret;
    367.           BIO_printf(bio_err,
    368.                      "Can't open %s, %s\n",

apps/openssl.c:385:1: return from a call to bio_open_default_
    383.       ERR_print_errors(bio_err);
    384.       return NULL;
    385. > }
    386.   
    387.   BIO *bio_open_default(const char *filename, const char *mode)

apps/openssl.c:390:1: return from a call to bio_open_default
  388.   {
  389.       return bio_open_default_(filename, mode, 0);
  390. > }
  391.   
  392.   BIO *bio_open_default_quiet(const char *filename, const char *mode)

int dhparam_main(int argc, char **argv)
{
    BIO *in = NULL, *out = NULL;
    DH *dh = NULL;
    char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;
    int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0;
    int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;
    OPTION_CHOICE o;
    prog = opt_init(argc, argv, dhparam_options);
    while ((o = opt_next()) != OPT_EOF) {
        switch (o) {
        case OPT_EOF:
        case OPT_ERR:
 opthelp:
            BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
            goto end;
        case OPT_HELP:
            opt_help(dhparam_options);
            ret = 0;
            goto end;
        case OPT_INFORM:
            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))
                goto opthelp;
            break;
        case OPT_OUTFORM:
            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))
                goto opthelp;
            break;
        case OPT_IN:
            infile = opt_arg();
            break;
        case OPT_OUT:
            outfile = opt_arg();
            break;
        case OPT_ENGINE:
            (void)setup_engine(opt_arg(), 0);
            break;
        case OPT_CHECK:
            check = 1;
            break;
        case OPT_TEXT:
            text = 1;
            break;
        case OPT_DSAPARAM:
            dsaparam = 1;
            break;
        case OPT_C:
            C = 1;
            break;
        case OPT_2:
            g = 2;
            break;
        case OPT_5:
            g = 5;
            break;
        case OPT_NOOUT:
            noout = 1;
            break;
        case OPT_RAND:
            inrand = opt_arg();
            break;
        }
    }
    argc = opt_num_rest();
    argv = opt_rest();
    if (!app_load_modules(NULL))
        goto end;
    if (argv[0] && (!opt_int(argv[0], &num) || num <= 0))
        goto end;
    if (g && !num)
        num = DEFBITS;
# ifndef OPENSSL_NO_DSA
    if (dsaparam && g) {
        BIO_printf(bio_err,
                   "generator may not be chosen for DSA parameters\n");
        goto end;
    }
# endif
    if (num && !g)
        g = 2;
    if (num) {
        BN_GENCB *cb;
        cb = BN_GENCB_new();
        if (!cb) {
            ERR_print_errors(bio_err);
            goto end;
        }
        BN_GENCB_set(cb, dh_cb, bio_err);
        if (!app_RAND_load_file(NULL, 1) && inrand == NULL) {
            BIO_printf(bio_err,
                       "warning, not much extra random data, consider using the -rand option\n");
        }
        if (inrand != NULL)
            BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
                       app_RAND_load_files(inrand));
# ifndef OPENSSL_NO_DSA
        if (dsaparam) {
            DSA *dsa = DSA_new();
            BIO_printf(bio_err,
                       "Generating DSA parameters, %d bit long prime\n", num);
            if (!dsa
                || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL,
                                               cb)) {
                DSA_free(dsa);
                BN_GENCB_free(cb);
                ERR_print_errors(bio_err);
                goto end;
            }
            dh = DSA_dup_DH(dsa);
            DSA_free(dsa);
            if (dh == NULL) {
                BN_GENCB_free(cb);
                ERR_print_errors(bio_err);
                goto end;
            }
        } else
# endif
        {
            dh = DH_new();
            BIO_printf(bio_err,
                       "Generating DH parameters, %d bit long safe prime, generator %d\n",
                       num, g);
            BIO_printf(bio_err, "This is going to take a long time\n");
            if (!dh || !DH_generate_parameters_ex(dh, num, g, cb)) {
                BN_GENCB_free(cb);
                ERR_print_errors(bio_err);
                goto end;
            }
        }
        BN_GENCB_free(cb);
        app_RAND_write_file(NULL);
    } else {
        in = bio_open_default(infile, RB(informat));
        if (in == NULL)
            goto end;
# ifndef OPENSSL_NO_DSA
        if (dsaparam) {
            DSA *dsa;
            if (informat == FORMAT_ASN1)
                dsa = d2i_DSAparams_bio(in, NULL);
            else
                dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);
            if (dsa == NULL) {
                BIO_printf(bio_err, "unable to load DSA parameters\n");
                ERR_print_errors(bio_err);
                goto end;
            }
            dh = DSA_dup_DH(dsa);
            DSA_free(dsa);
            if (dh == NULL) {
                ERR_print_errors(bio_err);
                goto end;
            }
        } else
# endif
        {
            if (informat == FORMAT_ASN1)
                dh = d2i_DHparams_bio(in, NULL);
            else
                dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
            if (dh == NULL) {
                BIO_printf(bio_err, "unable to load DH parameters\n");
                ERR_print_errors(bio_err);
                goto end;
            }
        }
    }
    out = bio_open_default(outfile, "w");
    if (out == NULL)
        goto end;
    if (text) {
        DHparams_print(out, dh);
    }
    if (check) {
        if (!DH_check(dh, &i)) {
            ERR_print_errors(bio_err);
            goto end;
        }
        if (i & DH_CHECK_P_NOT_PRIME)
            printf("p value is not prime\n");
        if (i & DH_CHECK_P_NOT_SAFE_PRIME)
            printf("p value is not a safe prime\n");
        if (i & DH_UNABLE_TO_CHECK_GENERATOR)
            printf("unable to check the generator value\n");
        if (i & DH_NOT_SUITABLE_GENERATOR)
            printf("the g value is not a generator\n");
        if (i == 0)
            printf("DH parameters appear to be ok.\n");
    }
    if (C) {
        unsigned char *data;
        int len, bits;
        len = BN_num_bytes(dh->p);
        bits = BN_num_bits(dh->p);
        data = app_malloc(len, "print a BN");
        BIO_printf(out, "#ifndef HEADER_DH_H\n"
                        "# include <openssl/dh.h>\n"
                        "#endif\n"
                        "\n");
        BIO_printf(out, "DH *get_dh%d()\n{\n", bits);
        print_bignum_var(out, dh->p, "dhp", bits, data);
        print_bignum_var(out, dh->g, "dhg", bits, data);
        BIO_printf(out, "    DH *dh = DN_new();\n"
                        "\n"
                        "    if (dh == NULL)\n"
                        "        return NULL;\n");
        BIO_printf(out, "    dh->p = BN_bin2bn(dhp_%d, sizeof (dhp_%d), NULL);\n",
               bits, bits);
        BIO_printf(out, "    dh->g = BN_bin2bn(dhg_%d, sizeof (dhg_%d), NULL);\n",
               bits, bits);
        BIO_printf(out, "    if (!dh->p || !dh->g) {\n"
                        "        DH_free(dh);\n"
                        "        return NULL;\n"
                        "    }\n");
        if (dh->length)
            BIO_printf(out,
                        "    dh->length = %ld;\n", dh->length);
        BIO_printf(out, "    return dh;\n}\n");
        OPENSSL_free(data);
    }
    if (!noout) {
        if (outformat == FORMAT_ASN1)
            i = i2d_DHparams_bio(out, dh);
        else if (dh->q)
            i = PEM_write_bio_DHxparams(out, dh);
        else
            i = PEM_write_bio_DHparams(out, dh);
        if (!i) {
            BIO_printf(bio_err, "unable to write DH parameters\n");
            ERR_print_errors(bio_err);
            goto end;
        }
    }
    ret = 0;
 end:
    BIO_free(in);
    BIO_free_all(out);
    DH_free(dh);
    return (ret);
}
['int dhparam_main(int argc, char **argv)\n{\n    BIO *in = NULL, *out = NULL;\n    DH *dh = NULL;\n    char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;\n    int dsaparam = 0, i, text = 0, C = 0, ret = 1, num = 0, g = 0;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM, check = 0, noout = 0;\n    OPTION_CHOICE o;\n    prog = opt_init(argc, argv, dhparam_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            opt_help(dhparam_options);\n            ret = 0;\n            goto end;\n        case OPT_INFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))\n                goto opthelp;\n            break;\n        case OPT_OUTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n                goto opthelp;\n            break;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_ENGINE:\n            (void)setup_engine(opt_arg(), 0);\n            break;\n        case OPT_CHECK:\n            check = 1;\n            break;\n        case OPT_TEXT:\n            text = 1;\n            break;\n        case OPT_DSAPARAM:\n            dsaparam = 1;\n            break;\n        case OPT_C:\n            C = 1;\n            break;\n        case OPT_2:\n            g = 2;\n            break;\n        case OPT_5:\n            g = 5;\n            break;\n        case OPT_NOOUT:\n            noout = 1;\n            break;\n        case OPT_RAND:\n            inrand = opt_arg();\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (!app_load_modules(NULL))\n        goto end;\n    if (argv[0] && (!opt_int(argv[0], &num) || num <= 0))\n        goto end;\n    if (g && !num)\n        num = DEFBITS;\n# ifndef OPENSSL_NO_DSA\n    if (dsaparam && g) {\n        BIO_printf(bio_err,\n                   "generator may not be chosen for DSA parameters\\n");\n        goto end;\n    }\n# endif\n    if (num && !g)\n        g = 2;\n    if (num) {\n        BN_GENCB *cb;\n        cb = BN_GENCB_new();\n        if (!cb) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        BN_GENCB_set(cb, dh_cb, bio_err);\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# ifndef OPENSSL_NO_DSA\n        if (dsaparam) {\n            DSA *dsa = DSA_new();\n            BIO_printf(bio_err,\n                       "Generating DSA parameters, %d bit long prime\\n", num);\n            if (!dsa\n                || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL,\n                                               cb)) {\n                DSA_free(dsa);\n                BN_GENCB_free(cb);\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n            dh = DSA_dup_DH(dsa);\n            DSA_free(dsa);\n            if (dh == NULL) {\n                BN_GENCB_free(cb);\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        } else\n# endif\n        {\n            dh = DH_new();\n            BIO_printf(bio_err,\n                       "Generating DH parameters, %d bit long safe prime, generator %d\\n",\n                       num, g);\n            BIO_printf(bio_err, "This is going to take a long time\\n");\n            if (!dh || !DH_generate_parameters_ex(dh, num, g, cb)) {\n                BN_GENCB_free(cb);\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        }\n        BN_GENCB_free(cb);\n        app_RAND_write_file(NULL);\n    } else {\n        in = bio_open_default(infile, RB(informat));\n        if (in == NULL)\n            goto end;\n# ifndef OPENSSL_NO_DSA\n        if (dsaparam) {\n            DSA *dsa;\n            if (informat == FORMAT_ASN1)\n                dsa = d2i_DSAparams_bio(in, NULL);\n            else\n                dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL);\n            if (dsa == NULL) {\n                BIO_printf(bio_err, "unable to load DSA parameters\\n");\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n            dh = DSA_dup_DH(dsa);\n            DSA_free(dsa);\n            if (dh == NULL) {\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        } else\n# endif\n        {\n            if (informat == FORMAT_ASN1)\n                dh = d2i_DHparams_bio(in, NULL);\n            else\n                dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);\n            if (dh == NULL) {\n                BIO_printf(bio_err, "unable to load DH parameters\\n");\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        }\n    }\n    out = bio_open_default(outfile, "w");\n    if (out == NULL)\n        goto end;\n    if (text) {\n        DHparams_print(out, dh);\n    }\n    if (check) {\n        if (!DH_check(dh, &i)) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (i & DH_CHECK_P_NOT_PRIME)\n            printf("p value is not prime\\n");\n        if (i & DH_CHECK_P_NOT_SAFE_PRIME)\n            printf("p value is not a safe prime\\n");\n        if (i & DH_UNABLE_TO_CHECK_GENERATOR)\n            printf("unable to check the generator value\\n");\n        if (i & DH_NOT_SUITABLE_GENERATOR)\n            printf("the g value is not a generator\\n");\n        if (i == 0)\n            printf("DH parameters appear to be ok.\\n");\n    }\n    if (C) {\n        unsigned char *data;\n        int len, bits;\n        len = BN_num_bytes(dh->p);\n        bits = BN_num_bits(dh->p);\n        data = app_malloc(len, "print a BN");\n        BIO_printf(out, "#ifndef HEADER_DH_H\\n"\n                        "# include <openssl/dh.h>\\n"\n                        "#endif\\n"\n                        "\\n");\n        BIO_printf(out, "DH *get_dh%d()\\n{\\n", bits);\n        print_bignum_var(out, dh->p, "dhp", bits, data);\n        print_bignum_var(out, dh->g, "dhg", bits, data);\n        BIO_printf(out, "    DH *dh = DN_new();\\n"\n                        "\\n"\n                        "    if (dh == NULL)\\n"\n                        "        return NULL;\\n");\n        BIO_printf(out, "    dh->p = BN_bin2bn(dhp_%d, sizeof (dhp_%d), NULL);\\n",\n               bits, bits);\n        BIO_printf(out, "    dh->g = BN_bin2bn(dhg_%d, sizeof (dhg_%d), NULL);\\n",\n               bits, bits);\n        BIO_printf(out, "    if (!dh->p || !dh->g) {\\n"\n                        "        DH_free(dh);\\n"\n                        "        return NULL;\\n"\n                        "    }\\n");\n        if (dh->length)\n            BIO_printf(out,\n                        "    dh->length = %ld;\\n", dh->length);\n        BIO_printf(out, "    return dh;\\n}\\n");\n        OPENSSL_free(data);\n    }\n    if (!noout) {\n        if (outformat == FORMAT_ASN1)\n            i = i2d_DHparams_bio(out, dh);\n        else if (dh->q)\n            i = PEM_write_bio_DHxparams(out, dh);\n        else\n            i = PEM_write_bio_DHparams(out, dh);\n        if (!i) {\n            BIO_printf(bio_err, "unable to write DH parameters\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    ret = 0;\n end:\n    BIO_free(in);\n    BIO_free_all(out);\n    DH_free(dh);\n    return (ret);\n}', 'int opt_num_rest(void)\n{\n    int i = 0;\n    char **pp;\n    for (pp = opt_rest(); *pp; pp++, i++)\n        continue;\n    return i;\n}', 'char **opt_rest(void)\n{\n    return &argv[opt_index];\n}', 'int app_load_modules(const CONF *config)\n{\n    CONF *to_free = NULL;\n    if (config == NULL)\n\tconfig = to_free = app_load_config_quiet(default_config_file);\n    if (config == NULL)\n\treturn 1;\n    if (CONF_modules_load(config, NULL, 0) <= 0) {\n        BIO_printf(bio_err, "Error configuring OpenSSL modules\\n");\n        ERR_print_errors(bio_err);\n        NCONF_free(to_free);\n        return 0;\n    }\n    NCONF_free(to_free);\n    return 1;\n}', 'BIO *bio_open_default(const char *filename, const char *mode)\n{\n    return bio_open_default_(filename, mode, 0);\n}', 'static BIO *bio_open_default_(const char *filename, const char *mode, int quiet)\n{\n    BIO *ret;\n    if (filename == NULL || strcmp(filename, "-") == 0) {\n        ret = *mode == \'r\' ? dup_bio_in() : dup_bio_out();\n        if (quiet) {\n            ERR_clear_error();\n            return ret;\n        }\n        if (ret != NULL)\n            return ret;\n        BIO_printf(bio_err,\n                   "Can\'t open %s, %s\\n",\n                   *mode == \'r\' ? "stdin" : "stdout", strerror(errno));\n    } else {\n        ret = BIO_new_file(filename, mode);\n        if (quiet) {\n            ERR_clear_error();\n            return ret;\n        }\n        if (ret != NULL)\n            return ret;\n        BIO_printf(bio_err,\n                   "Can\'t open %s for %s, %s\\n",\n                   filename,\n                   *mode == \'r\' ? "reading" : "writing", strerror(errno));\n    }\n    ERR_print_errors(bio_err);\n    return NULL;\n}', 'BIO *dup_bio_in(void)\n{\n    return BIO_new_fp(stdin, BIO_NOCLOSE | BIO_FP_TEXT);\n}']