apps/pkey.c:175: error: NULL_DEREFERENCE
  pointer `outfile` last assigned on line 99 could be null and is dereferenced by call to `bio_open_owner()` at line 175, column 11.
Showing all 79 steps of the trace


apps/pkey.c:93:1: start of procedure pkey_main()
91.   };
92.   
93. > int pkey_main(int argc, char **argv)
94.   {
95.       BIO *in = NULL, *out = NULL;

apps/pkey.c:95:5: 
93.   int pkey_main(int argc, char **argv)
94.   {
95. >     BIO *in = NULL, *out = NULL;
96.       ENGINE *e = NULL;
97.       EVP_PKEY *pkey = NULL;

apps/pkey.c:96:5: 
94.   {
95.       BIO *in = NULL, *out = NULL;
96. >     ENGINE *e = NULL;
97.       EVP_PKEY *pkey = NULL;
98.       const EVP_CIPHER *cipher = NULL;

apps/pkey.c:97:5: 
95.       BIO *in = NULL, *out = NULL;
96.       ENGINE *e = NULL;
97. >     EVP_PKEY *pkey = NULL;
98.       const EVP_CIPHER *cipher = NULL;
99.       char *infile = NULL, *outfile = NULL, *passin = NULL, *passout = NULL;

apps/pkey.c:98:5: 
96.       ENGINE *e = NULL;
97.       EVP_PKEY *pkey = NULL;
98. >     const EVP_CIPHER *cipher = NULL;
99.       char *infile = NULL, *outfile = NULL, *passin = NULL, *passout = NULL;
100.       char *passinarg = NULL, *passoutarg = NULL, *prog;

apps/pkey.c:99:5: 
97.       EVP_PKEY *pkey = NULL;
98.       const EVP_CIPHER *cipher = NULL;
99. >     char *infile = NULL, *outfile = NULL, *passin = NULL, *passout = NULL;
100.       char *passinarg = NULL, *passoutarg = NULL, *prog;
101.       OPTION_CHOICE o;

apps/pkey.c:100:5: 
98.       const EVP_CIPHER *cipher = NULL;
99.       char *infile = NULL, *outfile = NULL, *passin = NULL, *passout = NULL;
100. >     char *passinarg = NULL, *passoutarg = NULL, *prog;
101.       OPTION_CHOICE o;
102.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;

apps/pkey.c:102:5: 
100.       char *passinarg = NULL, *passoutarg = NULL, *prog;
101.       OPTION_CHOICE o;
102. >     int informat = FORMAT_PEM, outformat = FORMAT_PEM;
103.       int pubin = 0, pubout = 0, pubtext = 0, text = 0, noout = 0, ret = 1;
104.       int private = 0;

apps/pkey.c:103:5: 
101.       OPTION_CHOICE o;
102.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;
103. >     int pubin = 0, pubout = 0, pubtext = 0, text = 0, noout = 0, ret = 1;
104.       int private = 0;
105.   

apps/pkey.c:104:5: 
102.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;
103.       int pubin = 0, pubout = 0, pubtext = 0, text = 0, noout = 0, ret = 1;
104. >     int private = 0;
105.   
106.       prog = opt_init(argc, argv, pkey_options);

apps/pkey.c:106:5: Skipping opt_init(): empty list of specs
104.       int private = 0;
105.   
106.       prog = opt_init(argc, argv, pkey_options);
           ^
107.       while ((o = opt_next()) != OPT_EOF) {
108.           switch (o) {

apps/pkey.c:107:12: Loop condition is false. Leaving loop
105.   
106.       prog = opt_init(argc, argv, pkey_options);
107.       while ((o = opt_next()) != OPT_EOF) {
                  ^
108.           switch (o) {
109.           case OPT_EOF:

apps/pkey.c:161:5: 
159.           }
160.       }
161. >     argc = opt_num_rest();
162.       argv = opt_rest();
163.       private = !noout && !pubout ? 1 : 0;

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/pkey.c:162:5: 
160.       }
161.       argc = opt_num_rest();
162. >     argv = opt_rest();
163.       private = !noout && !pubout ? 1 : 0;
164.       if (text && !pubtext)

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/pkey.c:163:16: Condition is true
161.       argc = opt_num_rest();
162.       argv = opt_rest();
163.       private = !noout && !pubout ? 1 : 0;
                      ^
164.       if (text && !pubtext)
165.           private = 1;

apps/pkey.c:163:26: Condition is true
161.       argc = opt_num_rest();
162.       argv = opt_rest();
163.       private = !noout && !pubout ? 1 : 0;
                                ^
164.       if (text && !pubtext)
165.           private = 1;

apps/pkey.c:163:15: 
161.       argc = opt_num_rest();
162.       argv = opt_rest();
163. >     private = !noout && !pubout ? 1 : 0;
164.       if (text && !pubtext)
165.           private = 1;

apps/pkey.c:163:5: 
161.       argc = opt_num_rest();
162.       argv = opt_rest();
163. >     private = !noout && !pubout ? 1 : 0;
164.       if (text && !pubtext)
165.           private = 1;

apps/pkey.c:164:9: Taking false branch
162.       argv = opt_rest();
163.       private = !noout && !pubout ? 1 : 0;
164.       if (text && !pubtext)
               ^
165.           private = 1;
166.   

apps/pkey.c:167:10: 
165.           private = 1;
166.   
167. >     if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
168.           BIO_printf(bio_err, "Error getting passwords\n");
169.           goto end;

apps/apps.c:397:1: start of procedure app_passwd()
  395.   static char *app_get_pass(char *arg, int keepbio);
  396.   
  397. > int app_passwd(char *arg1, char *arg2, char **pass1, char **pass2)
  398.   {
  399.       int same;

apps/apps.c:400:10: Taking true branch
  398.   {
  399.       int same;
  400.       if (!arg2 || !arg1 || strcmp(arg1, arg2))
                  ^
  401.           same = 0;
  402.       else

apps/apps.c:401:9: 
  399.       int same;
  400.       if (!arg2 || !arg1 || strcmp(arg1, arg2))
  401. >         same = 0;
  402.       else
  403.           same = 1;

apps/apps.c:404:9: Taking false branch
  402.       else
  403.           same = 1;
  404.       if (arg1) {
                 ^
  405.           *pass1 = app_get_pass(arg1, same);
  406.           if (!*pass1)

apps/apps.c:408:16: Taking true branch
  406.           if (!*pass1)
  407.               return 0;
  408.       } else if (pass1)
                        ^
  409.           *pass1 = NULL;
  410.       if (arg2) {

apps/apps.c:409:9: 
  407.               return 0;
  408.       } else if (pass1)
  409. >         *pass1 = NULL;
  410.       if (arg2) {
  411.           *pass2 = app_get_pass(arg2, same ? 2 : 0);

apps/apps.c:410:9: Taking false branch
  408.       } else if (pass1)
  409.           *pass1 = NULL;
  410.       if (arg2) {
                 ^
  411.           *pass2 = app_get_pass(arg2, same ? 2 : 0);
  412.           if (!*pass2)

apps/apps.c:414:16: Taking true branch
  412.           if (!*pass2)
  413.               return 0;
  414.       } else if (pass2)
                        ^
  415.           *pass2 = NULL;
  416.       return 1;

apps/apps.c:415:9: 
  413.               return 0;
  414.       } else if (pass2)
  415. >         *pass2 = NULL;
  416.       return 1;
  417.   }

apps/apps.c:416:5: 
  414.       } else if (pass2)
  415.           *pass2 = NULL;
  416. >     return 1;
  417.   }
  418.   

apps/apps.c:417:1: return from a call to app_passwd
  415.           *pass2 = NULL;
  416.       return 1;
  417. > }
  418.   
  419.   static char *app_get_pass(char *arg, int keepbio)

apps/pkey.c:167:10: Taking false branch
165.           private = 1;
166.   
167.       if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
                ^
168.           BIO_printf(bio_err, "Error getting passwords\n");
169.           goto end;

apps/pkey.c:172:10: 
170.       }
171.   
172. >     if (!app_load_modules(NULL))
173.           goto end;
174.   

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/pkey.c:172:10: Taking false branch
170.       }
171.   
172.       if (!app_load_modules(NULL))
                ^
173.           goto end;
174.   

apps/pkey.c:175:5: 
173.           goto end;
174.   
175. >     out = bio_open_owner(outfile, "wb", private);
176.       if (out == NULL)
177.           goto end;

apps/openssl.c:305:1: start of procedure bio_open_owner()
  303.    * Open a file for writing, owner-read-only.
  304.    */
  305. > BIO *bio_open_owner(const char *filename, const char *modestr, int private)
  306.   {
  307.       FILE *fp = NULL;

apps/openssl.c:307:5: 
  305.   BIO *bio_open_owner(const char *filename, const char *modestr, int private)
  306.   {
  307. >     FILE *fp = NULL;
  308.       BIO *b = NULL;
  309.       int fd = -1, bflags, mode, binmode;

apps/openssl.c:308:5: 
  306.   {
  307.       FILE *fp = NULL;
  308. >     BIO *b = NULL;
  309.       int fd = -1, bflags, mode, binmode;
  310.   

apps/openssl.c:309:5: 
  307.       FILE *fp = NULL;
  308.       BIO *b = NULL;
  309. >     int fd = -1, bflags, mode, binmode;
  310.   
  311.       if (!private || filename == NULL || strcmp(filename, "-") == 0)

apps/openssl.c:311:10: Taking false branch
  309.       int fd = -1, bflags, mode, binmode;
  310.   
  311.       if (!private || filename == NULL || strcmp(filename, "-") == 0)
                  ^
  312.           return bio_open_default(filename, modestr);
  313.   

apps/openssl.c:311:21: Taking false branch
  309.       int fd = -1, bflags, mode, binmode;
  310.   
  311.       if (!private || filename == NULL || strcmp(filename, "-") == 0)
                             ^
  312.           return bio_open_default(filename, modestr);
  313.   

apps/openssl.c:311:41: Taking true branch
  309.       int fd = -1, bflags, mode, binmode;
  310.   
  311.       if (!private || filename == NULL || strcmp(filename, "-") == 0)
                                                 ^
  312.           return bio_open_default(filename, modestr);
  313.   

apps/openssl.c:312:9: 
  310.   
  311.       if (!private || filename == NULL || strcmp(filename, "-") == 0)
  312. >         return bio_open_default(filename, modestr);
  313.   
  314.       mode = O_WRONLY;

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 false
      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:288:1: start of procedure dup_bio_out()
        286.   }
        287.   
        288. > BIO *dup_bio_out(void)
        289.   {
        290.       BIO *b = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);

apps/openssl.c:290:5: Skipping BIO_new_fp(): empty list of specs
        288.   BIO *dup_bio_out(void)
        289.   {
        290.       BIO *b = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);
                   ^
        291.   #ifdef OPENSSL_SYS_VMS
        292.       b = BIO_push(BIO_new(BIO_f_linebuffer()), b);

apps/openssl.c:294:5: 
        292.       b = BIO_push(BIO_new(BIO_f_linebuffer()), b);
        293.   #endif
        294. >     return b;
        295.   }
        296.   

apps/openssl.c:295:1: return from a call to dup_bio_out
        293.   #endif
        294.       return b;
        295. > }
        296.   
        297.   void unbuffer(FILE *fp)

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)

apps/openssl.c:353:1: return from a call to bio_open_owner
  351.           close(fd);
  352.       return NULL;
  353. > }
  354.   
  355.   static BIO *bio_open_default_(const char *filename, const char *mode, int quiet)

int pkey_main(int argc, char **argv)
{
    BIO *in = NULL, *out = NULL;
    ENGINE *e = NULL;
    EVP_PKEY *pkey = NULL;
    const EVP_CIPHER *cipher = NULL;
    char *infile = NULL, *outfile = NULL, *passin = NULL, *passout = NULL;
    char *passinarg = NULL, *passoutarg = NULL, *prog;
    OPTION_CHOICE o;
    int informat = FORMAT_PEM, outformat = FORMAT_PEM;
    int pubin = 0, pubout = 0, pubtext = 0, text = 0, noout = 0, ret = 1;
    int private = 0;
    prog = opt_init(argc, argv, pkey_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(pkey_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_PASSIN:
            passinarg = opt_arg();
            break;
        case OPT_PASSOUT:
            passoutarg = opt_arg();
            break;
        case OPT_ENGINE:
            e = setup_engine(opt_arg(), 0);
            break;
        case OPT_IN:
            infile = opt_arg();
            break;
        case OPT_OUT:
            outfile = opt_arg();
            break;
        case OPT_PUBIN:
            pubin = pubout = pubtext = 1;
            break;
        case OPT_PUBOUT:
            pubout = 1;
            break;
        case OPT_TEXT_PUB:
            pubtext = text = 1;
            break;
        case OPT_TEXT:
            text = 1;
            break;
        case OPT_NOOUT:
            noout = 1;
            break;
        case OPT_MD:
            if (!opt_cipher(opt_unknown(), &cipher))
                goto opthelp;
        }
    }
    argc = opt_num_rest();
    argv = opt_rest();
    private = !noout && !pubout ? 1 : 0;
    if (text && !pubtext)
        private = 1;
    if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {
        BIO_printf(bio_err, "Error getting passwords\n");
        goto end;
    }
    if (!app_load_modules(NULL))
        goto end;
    out = bio_open_owner(outfile, "wb", private);
    if (out == NULL)
        goto end;
    if (pubin)
        pkey = load_pubkey(infile, informat, 1, passin, e, "Public Key");
    else
        pkey = load_key(infile, informat, 1, passin, e, "key");
    if (!pkey)
        goto end;
    if (!noout) {
        if (outformat == FORMAT_PEM) {
            assert(private);
            if (pubout)
                PEM_write_bio_PUBKEY(out, pkey);
            else
                PEM_write_bio_PrivateKey(out, pkey, cipher,
                                         NULL, 0, NULL, passout);
        } else if (outformat == FORMAT_ASN1) {
            assert(private);
            if (pubout)
                i2d_PUBKEY_bio(out, pkey);
            else
                i2d_PrivateKey_bio(out, pkey);
        } else {
            BIO_printf(bio_err, "Bad format specified for key\n");
            goto end;
        }
    }
    if (text) {
        if (pubtext)
            EVP_PKEY_print_public(out, pkey, 0, NULL);
        else {
            assert(private);
            EVP_PKEY_print_private(out, pkey, 0, NULL);
        }
    }
    ret = 0;
 end:
    EVP_PKEY_free(pkey);
    BIO_free_all(out);
    BIO_free(in);
    OPENSSL_free(passin);
    OPENSSL_free(passout);
    return ret;
}
['int pkey_main(int argc, char **argv)\n{\n    BIO *in = NULL, *out = NULL;\n    ENGINE *e = NULL;\n    EVP_PKEY *pkey = NULL;\n    const EVP_CIPHER *cipher = NULL;\n    char *infile = NULL, *outfile = NULL, *passin = NULL, *passout = NULL;\n    char *passinarg = NULL, *passoutarg = NULL, *prog;\n    OPTION_CHOICE o;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM;\n    int pubin = 0, pubout = 0, pubtext = 0, text = 0, noout = 0, ret = 1;\n    int private = 0;\n    prog = opt_init(argc, argv, pkey_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(pkey_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_PASSIN:\n            passinarg = 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_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_PUBIN:\n            pubin = pubout = pubtext = 1;\n            break;\n        case OPT_PUBOUT:\n            pubout = 1;\n            break;\n        case OPT_TEXT_PUB:\n            pubtext = text = 1;\n            break;\n        case OPT_TEXT:\n            text = 1;\n            break;\n        case OPT_NOOUT:\n            noout = 1;\n            break;\n        case OPT_MD:\n            if (!opt_cipher(opt_unknown(), &cipher))\n                goto opthelp;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    private = !noout && !pubout ? 1 : 0;\n    if (text && !pubtext)\n        private = 1;\n    if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {\n        BIO_printf(bio_err, "Error getting passwords\\n");\n        goto end;\n    }\n    if (!app_load_modules(NULL))\n        goto end;\n    out = bio_open_owner(outfile, "wb", private);\n    if (out == NULL)\n        goto end;\n    if (pubin)\n        pkey = load_pubkey(infile, informat, 1, passin, e, "Public Key");\n    else\n        pkey = load_key(infile, informat, 1, passin, e, "key");\n    if (!pkey)\n        goto end;\n    if (!noout) {\n        if (outformat == FORMAT_PEM) {\n            assert(private);\n            if (pubout)\n                PEM_write_bio_PUBKEY(out, pkey);\n            else\n                PEM_write_bio_PrivateKey(out, pkey, cipher,\n                                         NULL, 0, NULL, passout);\n        } else if (outformat == FORMAT_ASN1) {\n            assert(private);\n            if (pubout)\n                i2d_PUBKEY_bio(out, pkey);\n            else\n                i2d_PrivateKey_bio(out, pkey);\n        } else {\n            BIO_printf(bio_err, "Bad format specified for key\\n");\n            goto end;\n        }\n    }\n    if (text) {\n        if (pubtext)\n            EVP_PKEY_print_public(out, pkey, 0, NULL);\n        else {\n            assert(private);\n            EVP_PKEY_print_private(out, pkey, 0, NULL);\n        }\n    }\n    ret = 0;\n end:\n    EVP_PKEY_free(pkey);\n    BIO_free_all(out);\n    BIO_free(in);\n    OPENSSL_free(passin);\n    OPENSSL_free(passout);\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_passwd(char *arg1, char *arg2, char **pass1, char **pass2)\n{\n    int same;\n    if (!arg2 || !arg1 || strcmp(arg1, arg2))\n        same = 0;\n    else\n        same = 1;\n    if (arg1) {\n        *pass1 = app_get_pass(arg1, same);\n        if (!*pass1)\n            return 0;\n    } else if (pass1)\n        *pass1 = NULL;\n    if (arg2) {\n        *pass2 = app_get_pass(arg2, same ? 2 : 0);\n        if (!*pass2)\n            return 0;\n    } else if (pass2)\n        *pass2 = NULL;\n    return 1;\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_owner(const char *filename, const char *modestr, int private)\n{\n    FILE *fp = NULL;\n    BIO *b = NULL;\n    int fd = -1, bflags, mode, binmode;\n    if (!private || filename == NULL || strcmp(filename, "-") == 0)\n        return bio_open_default(filename, modestr);\n    mode = O_WRONLY;\n#ifdef O_CREAT\n    mode |= O_CREAT;\n#endif\n#ifdef O_TRUNC\n    mode |= O_TRUNC;\n#endif\n    binmode = strchr(modestr, \'b\') != NULL;\n    if (binmode) {\n#ifdef O_BINARY\n        mode |= O_BINARY;\n#elif defined(_O_BINARY)\n        mode |= _O_BINARY;\n#endif\n    }\n    fd = open(filename, mode, 0600);\n    if (fd < 0)\n        goto err;\n    fp = fdopen(fd, modestr);\n    if (fp == NULL)\n        goto err;\n    bflags = BIO_CLOSE;\n    if (!binmode)\n        bflags |= BIO_FP_TEXT;\n    b = BIO_new_fp(fp, bflags);\n    if (b)\n        return b;\n err:\n    BIO_printf(bio_err, "%s: Can\'t open \\"%s\\" for writing, %s\\n",\n               opt_getprog(), filename, strerror(errno));\n    ERR_print_errors(bio_err);\n    if (fp)\n        fclose(fp);\n    else if (fd >= 0)\n        close(fd);\n    return NULL;\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_out(void)\n{\n    BIO *b = BIO_new_fp(stdout, BIO_NOCLOSE | BIO_FP_TEXT);\n#ifdef OPENSSL_SYS_VMS\n    b = BIO_push(BIO_new(BIO_f_linebuffer()), b);\n#endif\n    return b;\n}']