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


apps/nseq.c:30:1: start of procedure nseq_main()
28.   };
29.   
30. > int nseq_main(int argc, char **argv)
31.   {
32.       BIO *in = NULL, *out = NULL;

apps/nseq.c:32:5: 
30.   int nseq_main(int argc, char **argv)
31.   {
32. >     BIO *in = NULL, *out = NULL;
33.       X509 *x509 = NULL;
34.       NETSCAPE_CERT_SEQUENCE *seq = NULL;

apps/nseq.c:33:5: 
31.   {
32.       BIO *in = NULL, *out = NULL;
33. >     X509 *x509 = NULL;
34.       NETSCAPE_CERT_SEQUENCE *seq = NULL;
35.       OPTION_CHOICE o;

apps/nseq.c:34:5: 
32.       BIO *in = NULL, *out = NULL;
33.       X509 *x509 = NULL;
34. >     NETSCAPE_CERT_SEQUENCE *seq = NULL;
35.       OPTION_CHOICE o;
36.       int toseq = 0, ret = 1, i;

apps/nseq.c:36:5: 
34.       NETSCAPE_CERT_SEQUENCE *seq = NULL;
35.       OPTION_CHOICE o;
36. >     int toseq = 0, ret = 1, i;
37.       char *infile = NULL, *outfile = NULL, *prog;
38.   

apps/nseq.c:37:5: 
35.       OPTION_CHOICE o;
36.       int toseq = 0, ret = 1, i;
37. >     char *infile = NULL, *outfile = NULL, *prog;
38.   
39.       prog = opt_init(argc, argv, nseq_options);

apps/nseq.c:39:5: Skipping opt_init(): empty list of specs
37.       char *infile = NULL, *outfile = NULL, *prog;
38.   
39.       prog = opt_init(argc, argv, nseq_options);
          ^
40.       while ((o = opt_next()) != OPT_EOF) {
41.           switch (o) {

apps/nseq.c:40:12: Loop condition is false. Leaving loop
38.   
39.       prog = opt_init(argc, argv, nseq_options);
40.       while ((o = opt_next()) != OPT_EOF) {
                 ^
41.           switch (o) {
42.           case OPT_EOF:

apps/nseq.c:62:5: 
60.           }
61.       }
62. >     argc = opt_num_rest();
63.       if (argc != 0)
64.           goto opthelp;

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

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

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

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

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

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

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

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

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

apps/nseq.c:63:9: Taking false branch
61.       }
62.       argc = opt_num_rest();
63.       if (argc != 0)
              ^
64.           goto opthelp;
65.   

apps/nseq.c:66:5: 
64.           goto opthelp;
65.   
66. >     in = bio_open_default(infile, 'r', FORMAT_PEM);
67.       if (in == NULL)
68.           goto end;

apps/apps.c:2448:1: start of procedure bio_open_default()
  2446.   }
  2447.   
  2448. > BIO *bio_open_default(const char *filename, char mode, int format)
  2449.   {
  2450.       return bio_open_default_(filename, mode, format, 0);

apps/apps.c:2450:5: 
  2448.   BIO *bio_open_default(const char *filename, char mode, int format)
  2449.   {
  2450. >     return bio_open_default_(filename, mode, format, 0);
  2451.   }
  2452.   

apps/apps.c:2416:1: start of procedure bio_open_default_()
    2414.   }
    2415.   
    2416. > static BIO *bio_open_default_(const char *filename, char mode, int format,
    2417.                                 int quiet)
    2418.   {

apps/apps.c:2421:9: Taking false branch
    2419.       BIO *ret;
    2420.   
    2421.       if (filename == NULL || strcmp(filename, "-") == 0) {
                    ^
    2422.           ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
    2423.           if (quiet) {

apps/apps.c:2421:29: Taking false branch
    2419.       BIO *ret;
    2420.   
    2421.       if (filename == NULL || strcmp(filename, "-") == 0) {
                                        ^
    2422.           ret = mode == 'r' ? dup_bio_in(format) : dup_bio_out(format);
    2423.           if (quiet) {

apps/apps.c:2433:9: 
    2431.                      mode == 'r' ? "stdin" : "stdout", strerror(errno));
    2432.       } else {
    2433. >         ret = BIO_new_file(filename, modestr(mode, format));
    2434.           if (quiet) {
    2435.               ERR_clear_error();

apps/apps.c:2324:1: start of procedure modestr()
      2322.   }
      2323.   
      2324. > static const char *modestr(char mode, int format)
      2325.   {
      2326.       OPENSSL_assert(mode == 'a' || mode == 'r' || mode == 'w');

apps/apps.c:2326:5: Condition is false
      2324.   static const char *modestr(char mode, int format)
      2325.   {
      2326.       OPENSSL_assert(mode == 'a' || mode == 'r' || mode == 'w');
                  ^
      2327.   
      2328.       switch (mode) {

apps/apps.c:2326:5: Condition is true
      2324.   static const char *modestr(char mode, int format)
      2325.   {
      2326.       OPENSSL_assert(mode == 'a' || mode == 'r' || mode == 'w');
                  ^
      2327.   
      2328.       switch (mode) {

apps/apps.c:2328:5: 
      2326.       OPENSSL_assert(mode == 'a' || mode == 'r' || mode == 'w');
      2327.   
      2328. >     switch (mode) {
      2329.       case 'a':
      2330.           return FMT_istext(format) ? "a" : "ab";

apps/apps.c:2329:5: Switch condition is false. Skipping switch case
      2327.   
      2328.       switch (mode) {
      2329.       case 'a':
                  ^
      2330.           return FMT_istext(format) ? "a" : "ab";
      2331.       case 'r':

apps/apps.c:2331:5: Switch condition is true. Entering switch case
      2329.       case 'a':
      2330.           return FMT_istext(format) ? "a" : "ab";
      2331.       case 'r':
                  ^
      2332.           return FMT_istext(format) ? "r" : "rb";
      2333.       case 'w':

apps/apps.c:2332:16: 
      2330.           return FMT_istext(format) ? "a" : "ab";
      2331.       case 'r':
      2332. >         return FMT_istext(format) ? "r" : "rb";
      2333.       case 'w':
      2334.           return FMT_istext(format) ? "w" : "wb";

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:2332:16: Condition is true
      2330.           return FMT_istext(format) ? "a" : "ab";
      2331.       case 'r':
      2332.           return FMT_istext(format) ? "r" : "rb";
                             ^
      2333.       case 'w':
      2334.           return FMT_istext(format) ? "w" : "wb";

apps/apps.c:2332:9: 
      2330.           return FMT_istext(format) ? "a" : "ab";
      2331.       case 'r':
      2332. >         return FMT_istext(format) ? "r" : "rb";
      2333.       case 'w':
      2334.           return FMT_istext(format) ? "w" : "wb";

apps/apps.c:2338:1: return from a call to modestr
      2336.       /* The assert above should make sure we never reach this point */
      2337.       return NULL;
      2338. > }
      2339.   
      2340.   static const char *modeverb(char mode)

apps/apps.c:2433:9: Skipping BIO_new_file(): empty list of specs
    2431.                      mode == 'r' ? "stdin" : "stdout", strerror(errno));
    2432.       } else {
    2433.           ret = BIO_new_file(filename, modestr(mode, format));
                    ^
    2434.           if (quiet) {
    2435.               ERR_clear_error();

apps/apps.c:2434:13: Taking false branch
    2432.       } else {
    2433.           ret = BIO_new_file(filename, modestr(mode, format));
    2434.           if (quiet) {
                        ^
    2435.               ERR_clear_error();
    2436.               return ret;

apps/apps.c:2438:13: Taking true branch
    2436.               return ret;
    2437.           }
    2438.           if (ret != NULL)
                        ^
    2439.               return ret;
    2440.           BIO_printf(bio_err,

apps/apps.c:2439:13: 
    2437.           }
    2438.           if (ret != NULL)
    2439. >             return ret;
    2440.           BIO_printf(bio_err,
    2441.                      "Can't open %s for %s, %s\n",

apps/apps.c:2446:1: return from a call to bio_open_default_
    2444.       ERR_print_errors(bio_err);
    2445.       return NULL;
    2446. > }
    2447.   
    2448.   BIO *bio_open_default(const char *filename, char mode, int format)

apps/apps.c:2451:1: return from a call to bio_open_default
  2449.   {
  2450.       return bio_open_default_(filename, mode, format, 0);
  2451. > }
  2452.   
  2453.   BIO *bio_open_default_quiet(const char *filename, char mode, int format)

int nseq_main(int argc, char **argv)
{
    BIO *in = NULL, *out = NULL;
    X509 *x509 = NULL;
    NETSCAPE_CERT_SEQUENCE *seq = NULL;
    OPTION_CHOICE o;
    int toseq = 0, ret = 1, i;
    char *infile = NULL, *outfile = NULL, *prog;
    prog = opt_init(argc, argv, nseq_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:
            ret = 0;
            opt_help(nseq_options);
            goto end;
        case OPT_TOSEQ:
            toseq = 1;
            break;
        case OPT_IN:
            infile = opt_arg();
            break;
        case OPT_OUT:
            outfile = opt_arg();
            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;
    if (toseq) {
        seq = NETSCAPE_CERT_SEQUENCE_new();
        if (seq == NULL)
            goto end;
        seq->certs = sk_X509_new_null();
        if (seq->certs == NULL)
            goto end;
        while ((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL)))
            sk_X509_push(seq->certs, x509);
        if (!sk_X509_num(seq->certs)) {
            BIO_printf(bio_err, "%s: Error reading certs file %s\n",
                       prog, infile);
            ERR_print_errors(bio_err);
            goto end;
        }
        PEM_write_bio_NETSCAPE_CERT_SEQUENCE(out, seq);
        ret = 0;
        goto end;
    }
    seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL);
    if (seq == NULL) {
        BIO_printf(bio_err, "%s: Error reading sequence file %s\n",
                   prog, infile);
        ERR_print_errors(bio_err);
        goto end;
    }
    for (i = 0; i < sk_X509_num(seq->certs); i++) {
        x509 = sk_X509_value(seq->certs, i);
        dump_cert_text(out, x509);
        PEM_write_bio_X509(out, x509);
    }
    ret = 0;
 end:
    BIO_free(in);
    BIO_free_all(out);
    NETSCAPE_CERT_SEQUENCE_free(seq);
    return ret;
}
['int nseq_main(int argc, char **argv)\n{\n    BIO *in = NULL, *out = NULL;\n    X509 *x509 = NULL;\n    NETSCAPE_CERT_SEQUENCE *seq = NULL;\n    OPTION_CHOICE o;\n    int toseq = 0, ret = 1, i;\n    char *infile = NULL, *outfile = NULL, *prog;\n    prog = opt_init(argc, argv, nseq_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(nseq_options);\n            goto end;\n        case OPT_TOSEQ:\n            toseq = 1;\n            break;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\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    if (toseq) {\n        seq = NETSCAPE_CERT_SEQUENCE_new();\n        if (seq == NULL)\n            goto end;\n        seq->certs = sk_X509_new_null();\n        if (seq->certs == NULL)\n            goto end;\n        while ((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL)))\n            sk_X509_push(seq->certs, x509);\n        if (!sk_X509_num(seq->certs)) {\n            BIO_printf(bio_err, "%s: Error reading certs file %s\\n",\n                       prog, infile);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        PEM_write_bio_NETSCAPE_CERT_SEQUENCE(out, seq);\n        ret = 0;\n        goto end;\n    }\n    seq = PEM_read_bio_NETSCAPE_CERT_SEQUENCE(in, NULL, NULL, NULL);\n    if (seq == NULL) {\n        BIO_printf(bio_err, "%s: Error reading sequence file %s\\n",\n                   prog, infile);\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    for (i = 0; i < sk_X509_num(seq->certs); i++) {\n        x509 = sk_X509_value(seq->certs, i);\n        dump_cert_text(out, x509);\n        PEM_write_bio_X509(out, x509);\n    }\n    ret = 0;\n end:\n    BIO_free(in);\n    BIO_free_all(out);\n    NETSCAPE_CERT_SEQUENCE_free(seq);\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}', 'static const char *modestr(char mode, int format)\n{\n    OPENSSL_assert(mode == \'a\' || mode == \'r\' || mode == \'w\');\n    switch (mode) {\n    case \'a\':\n        return FMT_istext(format) ? "a" : "ab";\n    case \'r\':\n        return FMT_istext(format) ? "r" : "rb";\n    case \'w\':\n        return FMT_istext(format) ? "w" : "wb";\n    }\n    return NULL;\n}', 'int FMT_istext(int format)\n{\n    return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;\n}']