apps/pkeyparam.c:82: error: NULL_DEREFERENCE
  pointer `infile` last assigned on line 44 could be null and is dereferenced by call to `bio_open_default()` at line 82, column 10.
Showing all 77 steps of the trace


apps/pkeyparam.c:37:1: start of procedure pkeyparam_main()
35.   };
36.   
37. > int pkeyparam_main(int argc, char **argv)
38.   {
39.       ENGINE *e = NULL;

apps/pkeyparam.c:39:5: 
37.   int pkeyparam_main(int argc, char **argv)
38.   {
39. >     ENGINE *e = NULL;
40.       BIO *in = NULL, *out = NULL;
41.       EVP_PKEY *pkey = NULL;

apps/pkeyparam.c:40:5: 
38.   {
39.       ENGINE *e = NULL;
40. >     BIO *in = NULL, *out = NULL;
41.       EVP_PKEY *pkey = NULL;
42.       int text = 0, noout = 0, ret = 1, check = 0;

apps/pkeyparam.c:41:5: 
39.       ENGINE *e = NULL;
40.       BIO *in = NULL, *out = NULL;
41. >     EVP_PKEY *pkey = NULL;
42.       int text = 0, noout = 0, ret = 1, check = 0;
43.       OPTION_CHOICE o;

apps/pkeyparam.c:42:5: 
40.       BIO *in = NULL, *out = NULL;
41.       EVP_PKEY *pkey = NULL;
42. >     int text = 0, noout = 0, ret = 1, check = 0;
43.       OPTION_CHOICE o;
44.       char *infile = NULL, *outfile = NULL, *prog;

apps/pkeyparam.c:44:5: 
42.       int text = 0, noout = 0, ret = 1, check = 0;
43.       OPTION_CHOICE o;
44. >     char *infile = NULL, *outfile = NULL, *prog;
45.   
46.       prog = opt_init(argc, argv, pkeyparam_options);

apps/pkeyparam.c:46:5: Skipping opt_init(): empty list of specs
44.       char *infile = NULL, *outfile = NULL, *prog;
45.   
46.       prog = opt_init(argc, argv, pkeyparam_options);
          ^
47.       while ((o = opt_next()) != OPT_EOF) {
48.           switch (o) {

apps/pkeyparam.c:47:12: Loop condition is false. Leaving loop
45.   
46.       prog = opt_init(argc, argv, pkeyparam_options);
47.       while ((o = opt_next()) != OPT_EOF) {
                 ^
48.           switch (o) {
49.           case OPT_EOF:

apps/pkeyparam.c:78:5: 
76.           }
77.       }
78. >     argc = opt_num_rest();
79.       if (argc != 0)
80.           goto opthelp;

apps/opt.c:788:1: start of procedure opt_num_rest()
  786.   
  787.   /* How many items in remaining args? */
  788. > int opt_num_rest(void)
  789.   {
  790.       int i = 0;

apps/opt.c:790:5: 
  788.   int opt_num_rest(void)
  789.   {
  790. >     int i = 0;
  791.       char **pp;
  792.   

apps/opt.c:793:10: 
  791.       char **pp;
  792.   
  793. >     for (pp = opt_rest(); *pp; pp++, i++)
  794.           continue;
  795.       return i;

apps/opt.c:782:1: start of procedure opt_rest()
    780.   
    781.   /* Return the rest of the arguments after parsing flags. */
    782. > char **opt_rest(void)
    783.   {
    784.       return &argv[opt_index];

apps/opt.c:784:5: 
    782.   char **opt_rest(void)
    783.   {
    784. >     return &argv[opt_index];
    785.   }
    786.   

apps/opt.c:785:1: return from a call to opt_rest
    783.   {
    784.       return &argv[opt_index];
    785. > }
    786.   
    787.   /* How many items in remaining args? */

apps/opt.c:793:27: Loop condition is false. Leaving loop
  791.       char **pp;
  792.   
  793.       for (pp = opt_rest(); *pp; pp++, i++)
                                   ^
  794.           continue;
  795.       return i;

apps/opt.c:795:5: 
  793.       for (pp = opt_rest(); *pp; pp++, i++)
  794.           continue;
  795. >     return i;
  796.   }
  797.   

apps/opt.c:796:1: return from a call to opt_num_rest
  794.           continue;
  795.       return i;
  796. > }
  797.   
  798.   /* Return a string describing the parameter type. */

apps/pkeyparam.c:79:9: Taking false branch
77.       }
78.       argc = opt_num_rest();
79.       if (argc != 0)
              ^
80.           goto opthelp;
81.   

apps/pkeyparam.c:82:5: 
80.           goto opthelp;
81.   
82. >     in = bio_open_default(infile, 'r', FORMAT_PEM);
83.       if (in == NULL)
84.           goto end;

apps/apps.c:2455:1: start of procedure bio_open_default()
  2453.   }
  2454.   
  2455. > BIO *bio_open_default(const char *filename, char mode, int format)
  2456.   {
  2457.       return bio_open_default_(filename, mode, format, 0);

apps/apps.c:2457:5: 
  2455.   BIO *bio_open_default(const char *filename, char mode, int format)
  2456.   {
  2457. >     return bio_open_default_(filename, mode, format, 0);
  2458.   }
  2459.   

apps/apps.c:2423:1: start of procedure bio_open_default_()
    2421.   }
    2422.   
    2423. > static BIO *bio_open_default_(const char *filename, char mode, int format,
    2424.                                 int quiet)
    2425.   {

apps/apps.c:2428:9: Taking false branch
    2426.       BIO *ret;
    2427.   
    2428.       if (filename == NULL || strcmp(filename, "-") == 0) {
                    ^
    2429.           ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
    2430.           if (quiet) {

apps/apps.c:2428:29: Taking true branch
    2426.       BIO *ret;
    2427.   
    2428.       if (filename == NULL || strcmp(filename, "-") == 0) {
                                        ^
    2429.           ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
    2430.           if (quiet) {

apps/apps.c:2429:15: Condition is true
    2427.   
    2428.       if (filename == NULL || strcmp(filename, "-") == 0) {
    2429.           ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
                          ^
    2430.           if (quiet) {
    2431.               ERR_clear_error();

apps/apps.c:2264:1: start of procedure dup_bio_in()
      2262.    * text and binary input/output on non-Unix platforms
      2263.    */
      2264. > BIO *dup_bio_in(int format)
      2265.   {
      2266.       return BIO_new_fp(stdin,

apps/apps.c:2267:38: 
      2265.   {
      2266.       return BIO_new_fp(stdin,
      2267. >                       BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
      2268.   }
      2269.   

apps/fmt.c:12:1: start of procedure FMT_istext()
        10.   #include "fmt.h"
        11.   
        12. > int FMT_istext(int format)
        13.   {
        14.       return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;

apps/fmt.c:14:12: Condition is true
        12.   int FMT_istext(int format)
        13.   {
        14.       return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;
                         ^
        15.   }

apps/fmt.c:14:5: 
        12.   int FMT_istext(int format)
        13.   {
        14. >     return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;
        15.   }

apps/fmt.c:15:1: return from a call to FMT_istext
        13.   {
        14.       return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;
        15. > }

apps/apps.c:2267:38: Condition is true
      2265.   {
      2266.       return BIO_new_fp(stdin,
      2267.                         BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
                                                   ^
      2268.   }
      2269.   

apps/apps.c:2266:5: 
      2264.   BIO *dup_bio_in(int format)
      2265.   {
      2266. >     return BIO_new_fp(stdin,
      2267.                         BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
      2268.   }

crypto/bio/bss_file.c:92:1: start of procedure BIO_new_fp()
        90.   }
        91.   
        92. > BIO *BIO_new_fp(FILE *stream, int close_flag)
        93.   {
        94.       BIO *ret;

crypto/bio/bss_file.c:96:9: 
        94.       BIO *ret;
        95.   
        96. >     if ((ret = BIO_new(BIO_s_file())) == NULL)
        97.           return NULL;
        98.   

crypto/bio/bss_file.c:105:1: start of procedure BIO_s_file()
          103.   }
          104.   
          105. > const BIO_METHOD *BIO_s_file(void)
          106.   {
          107.       return &methods_filep;

crypto/bio/bss_file.c:107:5: 
          105.   const BIO_METHOD *BIO_s_file(void)
          106.   {
          107. >     return &methods_filep;
          108.   }
          109.   

crypto/bio/bss_file.c:108:1: return from a call to BIO_s_file
          106.   {
          107.       return &methods_filep;
          108. > }
          109.   
          110.   static int file_new(BIO *bi)

crypto/bio/bss_file.c:96:9: Taking true branch
        94.       BIO *ret;
        95.   
        96.       if ((ret = BIO_new(BIO_s_file())) == NULL)
                      ^
        97.           return NULL;
        98.   

crypto/bio/bss_file.c:97:9: 
        95.   
        96.       if ((ret = BIO_new(BIO_s_file())) == NULL)
        97. >         return NULL;
        98.   
        99.       /* redundant flag, left for documentation purposes */

crypto/bio/bss_file.c:103:1: return from a call to BIO_new_fp
        101.       BIO_set_fp(ret, stream, close_flag);
        102.       return ret;
        103. > }
        104.   
        105.   const BIO_METHOD *BIO_s_file(void)

apps/apps.c:2268:1: return from a call to dup_bio_in
      2266.       return BIO_new_fp(stdin,
      2267.                         BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));
      2268. > }
      2269.   
      2270.   BIO *dup_bio_out(int format)

apps/apps.c:2429:9: 
    2427.   
    2428.       if (filename == NULL || strcmp(filename, "-") == 0) {
    2429. >         ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
    2430.           if (quiet) {
    2431.               ERR_clear_error();

apps/apps.c:2430:13: Taking false branch
    2428.       if (filename == NULL || strcmp(filename, "-") == 0) {
    2429.           ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
    2430.           if (quiet) {
                        ^
    2431.               ERR_clear_error();
    2432.               return ret;

apps/apps.c:2434:13: Taking false branch
    2432.               return ret;
    2433.           }
    2434.           if (ret != NULL)
                        ^
    2435.               return ret;
    2436.           BIO_printf(bio_err,

apps/apps.c:2438:20: Condition is true
    2436.           BIO_printf(bio_err,
    2437.                      "Can't open %s, %s\n",
    2438.                      mode == 'r' ? "stdin" : "stdout", strerror(errno));
                               ^
    2439.       } else {
    2440.           ret = BIO_new_file(filename, modestr(mode, format));

apps/apps.c:2436:9: Skipping BIO_printf(): empty list of specs
    2434.           if (ret != NULL)
    2435.               return ret;
    2436.           BIO_printf(bio_err,
                    ^
    2437.                      "Can't open %s, %s\n",
    2438.                      mode == 'r' ? "stdin" : "stdout", strerror(errno));

apps/apps.c:2451:5: 
    2449.                      filename, modeverb(mode), strerror(errno));
    2450.       }
    2451. >     ERR_print_errors(bio_err);
    2452.       return NULL;
    2453.   }

crypto/err/err_prn.c:42:1: start of procedure ERR_print_errors()
      40.   }
      41.   
      42. > void ERR_print_errors(BIO *bp)
      43.   {
      44.       ERR_print_errors_cb(print_bio, bp);

crypto/err/err_prn.c:44:5: 
      42.   void ERR_print_errors(BIO *bp)
      43.   {
      44. >     ERR_print_errors_cb(print_bio, bp);
      45.   }
      46.   

crypto/err/err_prn.c:16:1: start of procedure ERR_print_errors_cb()
        14.   #include <openssl/err.h>
        15.   
        16. > void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
        17.                            void *u)
        18.   {

crypto/err/err_prn.c:19:5: 
        17.                            void *u)
        18.   {
        19. >     CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();
        20.       unsigned long l;
        21.       char buf[256];

crypto/threads_pthread.c:148:1: start of procedure CRYPTO_THREAD_get_current_id()
          146.   }
          147.   
          148. > CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
          149.   {
          150.       return pthread_self();

crypto/threads_pthread.c:150:5: Skipping pthread_self(): method has no implementation
          148.   CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
          149.   {
          150.       return pthread_self();
                     ^
          151.   }
          152.   

crypto/threads_pthread.c:151:1: return from a call to CRYPTO_THREAD_get_current_id
          149.   {
          150.       return pthread_self();
          151. > }
          152.   
          153.   int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)

crypto/err/err_prn.c:26:12: 
        24.       int line, flags;
        25.   
        26. >     while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
        27.           ERR_error_string_n(l, buf, sizeof(buf));
        28.           hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));

crypto/err/err.c:444:1: start of procedure ERR_get_error_line_data()
          442.   }
          443.   
          444. > unsigned long ERR_get_error_line_data(const char **file, int *line,
          445.                                         const char **data, int *flags)
          446.   {

crypto/err/err.c:447:5: 
          445.                                         const char **data, int *flags)
          446.   {
          447. >     return get_error_values(1, 0, file, line, data, flags);
          448.   }
          449.   

crypto/err/err.c:482:1: start of procedure get_error_values()
            480.   }
            481.   
            482. > static unsigned long get_error_values(int inc, int top, const char **file,
            483.                                         int *line, const char **data,
            484.                                         int *flags)

crypto/err/err.c:486:5: 
            484.                                         int *flags)
            485.   {
            486. >     int i = 0;
            487.       ERR_STATE *es;
            488.       unsigned long ret;

crypto/err/err.c:490:5: 
            488.       unsigned long ret;
            489.   
            490. >     es = ERR_get_state();
            491.       if (es == NULL)
            492.           return 0;

crypto/err/err.c:679:1: start of procedure ERR_get_state()
              677.   }
              678.   
              679. > ERR_STATE *ERR_get_state(void)
              680.   {
              681.       ERR_STATE *state;

crypto/err/err.c:682:5: 
              680.   {
              681.       ERR_STATE *state;
              682. >     int saveerrno = get_last_sys_error();
              683.   
              684.       if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))

crypto/err/err.c:684:10: Taking true branch
              682.       int saveerrno = get_last_sys_error();
              683.   
              684.       if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
                              ^
              685.           return NULL;
              686.   

crypto/err/err.c:685:9: 
              683.   
              684.       if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
              685. >         return NULL;
              686.   
              687.       if (!RUN_ONCE(&err_init, err_do_init))

crypto/err/err.c:716:1: return from a call to ERR_get_state
              714.       set_sys_error(saveerrno);
              715.       return state;
              716. > }
              717.   
              718.   /*

crypto/err/err.c:491:9: Taking true branch
            489.   
            490.       es = ERR_get_state();
            491.       if (es == NULL)
                           ^
            492.           return 0;
            493.   

crypto/err/err.c:492:9: 
            490.       es = ERR_get_state();
            491.       if (es == NULL)
            492. >         return 0;
            493.   
            494.       if (inc && top) {

crypto/err/err.c:562:1: return from a call to get_error_values
            560.       }
            561.       return ret;
            562. > }
            563.   
            564.   void ERR_error_string_n(unsigned long e, char *buf, size_t len)

crypto/err/err.c:448:1: return from a call to ERR_get_error_line_data
          446.   {
          447.       return get_error_values(1, 0, file, line, data, flags);
          448. > }
          449.   
          450.   unsigned long ERR_peek_error(void)

crypto/err/err_prn.c:26:12: Loop condition is false. Leaving loop
        24.       int line, flags;
        25.   
        26.       while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
                         ^
        27.           ERR_error_string_n(l, buf, sizeof(buf));
        28.           hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));

crypto/err/err_prn.c:35:1: return from a call to ERR_print_errors_cb
        33.               break;              /* abort outputting the error report */
        34.       }
        35. > }
        36.   
        37.   static int print_bio(const char *str, size_t len, void *bp)

crypto/err/err_prn.c:45:1: return from a call to ERR_print_errors
      43.   {
      44.       ERR_print_errors_cb(print_bio, bp);
      45. > }
      46.   
      47.   #ifndef OPENSSL_NO_STDIO

apps/apps.c:2452:5: 
    2450.       }
    2451.       ERR_print_errors(bio_err);
    2452. >     return NULL;
    2453.   }
    2454.   

apps/apps.c:2453:1: return from a call to bio_open_default_
    2451.       ERR_print_errors(bio_err);
    2452.       return NULL;
    2453. > }
    2454.   
    2455.   BIO *bio_open_default(const char *filename, char mode, int format)

apps/apps.c:2458:1: return from a call to bio_open_default
  2456.   {
  2457.       return bio_open_default_(filename, mode, format, 0);
  2458. > }
  2459.   
  2460.   BIO *bio_open_default_quiet(const char *filename, char mode, int format)

int pkeyparam_main(int argc, char **argv)
{
    ENGINE *e = NULL;
    BIO *in = NULL, *out = NULL;
    EVP_PKEY *pkey = NULL;
    int text = 0, noout = 0, ret = 1, check = 0;
    OPTION_CHOICE o;
    char *infile = NULL, *outfile = NULL, *prog;
    prog = opt_init(argc, argv, pkeyparam_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(pkeyparam_options);
            ret = 0;
            goto end;
        case OPT_IN:
            infile = opt_arg();
            break;
        case OPT_OUT:
            outfile = opt_arg();
            break;
        case OPT_ENGINE:
            e = setup_engine(opt_arg(), 0);
            break;
        case OPT_TEXT:
            text = 1;
            break;
        case OPT_NOOUT:
            noout = 1;
            break;
        case OPT_CHECK:
            check = 1;
            break;
        }
    }
    argc = opt_num_rest();
    if (argc != 0)
        goto opthelp;
    in = bio_open_default(infile, 'r', FORMAT_PEM);
    if (in == NULL)
        goto end;
    out = bio_open_default(outfile, 'w', FORMAT_PEM);
    if (out == NULL)
        goto end;
    pkey = PEM_read_bio_Parameters(in, NULL);
    if (pkey == NULL) {
        BIO_printf(bio_err, "Error reading parameters\n");
        ERR_print_errors(bio_err);
        goto end;
    }
    if (check) {
        int r;
        EVP_PKEY_CTX *ctx;
        ctx = EVP_PKEY_CTX_new(pkey, e);
        if (ctx == NULL) {
            ERR_print_errors(bio_err);
            goto end;
        }
        r = EVP_PKEY_param_check(ctx);
        if (r == 1) {
            BIO_printf(out, "Parameters are valid\n");
        } else {
            unsigned long err;
            BIO_printf(out, "Parameters are invalid\n");
            while ((err = ERR_peek_error()) != 0) {
                BIO_printf(out, "Detailed error: %s\n",
                           ERR_reason_error_string(err));
                ERR_get_error();
            }
        }
        EVP_PKEY_CTX_free(ctx);
    }
    if (!noout)
        PEM_write_bio_Parameters(out, pkey);
    if (text)
        EVP_PKEY_print_params(out, pkey, 0, NULL);
    ret = 0;
 end:
    EVP_PKEY_free(pkey);
    release_engine(e);
    BIO_free_all(out);
    BIO_free(in);
    return ret;
}
['int pkeyparam_main(int argc, char **argv)\n{\n    ENGINE *e = NULL;\n    BIO *in = NULL, *out = NULL;\n    EVP_PKEY *pkey = NULL;\n    int text = 0, noout = 0, ret = 1, check = 0;\n    OPTION_CHOICE o;\n    char *infile = NULL, *outfile = NULL, *prog;\n    prog = opt_init(argc, argv, pkeyparam_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(pkeyparam_options);\n            ret = 0;\n            goto end;\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            e = setup_engine(opt_arg(), 0);\n            break;\n        case OPT_TEXT:\n            text = 1;\n            break;\n        case OPT_NOOUT:\n            noout = 1;\n            break;\n        case OPT_CHECK:\n            check = 1;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    if (argc != 0)\n        goto opthelp;\n    in = bio_open_default(infile, \'r\', FORMAT_PEM);\n    if (in == NULL)\n        goto end;\n    out = bio_open_default(outfile, \'w\', FORMAT_PEM);\n    if (out == NULL)\n        goto end;\n    pkey = PEM_read_bio_Parameters(in, NULL);\n    if (pkey == NULL) {\n        BIO_printf(bio_err, "Error reading parameters\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (check) {\n        int r;\n        EVP_PKEY_CTX *ctx;\n        ctx = EVP_PKEY_CTX_new(pkey, e);\n        if (ctx == NULL) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        r = EVP_PKEY_param_check(ctx);\n        if (r == 1) {\n            BIO_printf(out, "Parameters are valid\\n");\n        } else {\n            unsigned long err;\n            BIO_printf(out, "Parameters are invalid\\n");\n            while ((err = ERR_peek_error()) != 0) {\n                BIO_printf(out, "Detailed error: %s\\n",\n                           ERR_reason_error_string(err));\n                ERR_get_error();\n            }\n        }\n        EVP_PKEY_CTX_free(ctx);\n    }\n    if (!noout)\n        PEM_write_bio_Parameters(out, pkey);\n    if (text)\n        EVP_PKEY_print_params(out, pkey, 0, NULL);\n    ret = 0;\n end:\n    EVP_PKEY_free(pkey);\n    release_engine(e);\n    BIO_free_all(out);\n    BIO_free(in);\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}', 'BIO *bio_open_default(const char *filename, char mode, int format)\n{\n    return bio_open_default_(filename, mode, format, 0);\n}', 'static BIO *bio_open_default_(const char *filename, char mode, int format,\n                              int quiet)\n{\n    BIO *ret;\n    if (filename == NULL || strcmp(filename, "-") == 0) {\n        ret = mode == \'r\' ? dup_bio_in(format) : dup_bio_out(format);\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, modestr(mode, format));\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, modeverb(mode), strerror(errno));\n    }\n    ERR_print_errors(bio_err);\n    return NULL;\n}', 'BIO *dup_bio_in(int format)\n{\n    return BIO_new_fp(stdin,\n                      BIO_NOCLOSE | (FMT_istext(format) ? BIO_FP_TEXT : 0));\n}', 'int FMT_istext(int format)\n{\n    return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;\n}', 'BIO *BIO_new_fp(FILE *stream, int close_flag)\n{\n    BIO *ret;\n    if ((ret = BIO_new(BIO_s_file())) == NULL)\n        return NULL;\n    BIO_set_flags(ret, BIO_FLAGS_UPLINK_INTERNAL);\n    BIO_set_fp(ret, stream, close_flag);\n    return ret;\n}', 'const BIO_METHOD *BIO_s_file(void)\n{\n    return &methods_filep;\n}', 'void ERR_print_errors(BIO *bp)\n{\n    ERR_print_errors_cb(print_bio, bp);\n}', 'void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),\n                         void *u)\n{\n    CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id();\n    unsigned long l;\n    char buf[256];\n    char buf2[4096], *hex;\n    const char *file, *data;\n    int line, flags;\n    while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {\n        ERR_error_string_n(l, buf, sizeof(buf));\n        hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid));\n        BIO_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%d:%s\\n", hex, buf, file,\n                     line, (flags & ERR_TXT_STRING) ? data : "");\n        OPENSSL_free(hex);\n        if (cb(buf2, strlen(buf2), u) <= 0)\n            break;\n    }\n}', 'CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)\n{\n    return pthread_self();\n}', 'unsigned long ERR_get_error_line_data(const char **file, int *line,\n                                      const char **data, int *flags)\n{\n    return get_error_values(1, 0, file, line, data, flags);\n}', 'static unsigned long get_error_values(int inc, int top, const char **file,\n                                      int *line, const char **data,\n                                      int *flags)\n{\n    int i = 0;\n    ERR_STATE *es;\n    unsigned long ret;\n    es = ERR_get_state();\n    if (es == NULL)\n        return 0;\n    if (inc && top) {\n        if (file)\n            *file = "";\n        if (line)\n            *line = 0;\n        if (data)\n            *data = "";\n        if (flags)\n            *flags = 0;\n        return ERR_R_INTERNAL_ERROR;\n    }\n    while (es->bottom != es->top) {\n        if (es->err_flags[es->top] & ERR_FLAG_CLEAR) {\n            err_clear(es, es->top);\n            es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;\n            continue;\n        }\n        i = (es->bottom + 1) % ERR_NUM_ERRORS;\n        if (es->err_flags[i] & ERR_FLAG_CLEAR) {\n            es->bottom = i;\n            err_clear(es, es->bottom);\n            continue;\n        }\n        break;\n    }\n    if (es->bottom == es->top)\n        return 0;\n    if (top)\n        i = es->top;\n    else\n        i = (es->bottom + 1) % ERR_NUM_ERRORS;\n    ret = es->err_buffer[i];\n    if (inc) {\n        es->bottom = i;\n        es->err_buffer[i] = 0;\n    }\n    if (file != NULL && line != NULL) {\n        if (es->err_file[i] == NULL) {\n            *file = "NA";\n            *line = 0;\n        } else {\n            *file = es->err_file[i];\n            *line = es->err_line[i];\n        }\n    }\n    if (data == NULL) {\n        if (inc) {\n            err_clear_data(es, i);\n        }\n    } else {\n        if (es->err_data[i] == NULL) {\n            *data = "";\n            if (flags != NULL)\n                *flags = 0;\n        } else {\n            *data = es->err_data[i];\n            if (flags != NULL)\n                *flags = es->err_data_flags[i];\n        }\n    }\n    return ret;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n    ERR_STATE *state;\n    int saveerrno = get_last_sys_error();\n    if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))\n        return NULL;\n    if (!RUN_ONCE(&err_init, err_do_init))\n        return NULL;\n    state = CRYPTO_THREAD_get_local(&err_thread_local);\n    if (state == (ERR_STATE*)-1)\n        return NULL;\n    if (state == NULL) {\n        if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))\n            return NULL;\n        if ((state = OPENSSL_zalloc(sizeof(*state))) == NULL) {\n            CRYPTO_THREAD_set_local(&err_thread_local, NULL);\n            return NULL;\n        }\n        if (!ossl_init_thread_start(NULL, NULL, err_delete_thread_state)\n                || !CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n            ERR_STATE_free(state);\n            CRYPTO_THREAD_set_local(&err_thread_local, NULL);\n            return NULL;\n        }\n        OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n    }\n    set_sys_error(saveerrno);\n    return state;\n}']