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


apps/pkcs7.c:141:1: start of procedure pkcs7_main()
139.   };
140.   
141. > int pkcs7_main(int argc, char **argv)
142.   {
143.       PKCS7 *p7 = NULL;

apps/pkcs7.c:143:5: 
141.   int pkcs7_main(int argc, char **argv)
142.   {
143. >     PKCS7 *p7 = NULL;
144.       BIO *in = NULL, *out = NULL;
145.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;

apps/pkcs7.c:144:5: 
142.   {
143.       PKCS7 *p7 = NULL;
144. >     BIO *in = NULL, *out = NULL;
145.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;
146.       char *infile = NULL, *outfile = NULL, *prog;

apps/pkcs7.c:145:5: 
143.       PKCS7 *p7 = NULL;
144.       BIO *in = NULL, *out = NULL;
145. >     int informat = FORMAT_PEM, outformat = FORMAT_PEM;
146.       char *infile = NULL, *outfile = NULL, *prog;
147.       int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, ret = 1;

apps/pkcs7.c:146:5: 
144.       BIO *in = NULL, *out = NULL;
145.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;
146. >     char *infile = NULL, *outfile = NULL, *prog;
147.       int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, ret = 1;
148.       OPTION_CHOICE o;

apps/pkcs7.c:147:5: 
145.       int informat = FORMAT_PEM, outformat = FORMAT_PEM;
146.       char *infile = NULL, *outfile = NULL, *prog;
147. >     int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, ret = 1;
148.       OPTION_CHOICE o;
149.   

apps/pkcs7.c:150:5: Skipping opt_init(): empty list of specs
148.       OPTION_CHOICE o;
149.   
150.       prog = opt_init(argc, argv, pkcs7_options);
           ^
151.       while ((o = opt_next()) != OPT_EOF) {
152.           switch (o) {

apps/pkcs7.c:151:12: Loop condition is false. Leaving loop
149.   
150.       prog = opt_init(argc, argv, pkcs7_options);
151.       while ((o = opt_next()) != OPT_EOF) {
                  ^
152.           switch (o) {
153.           case OPT_EOF:

apps/pkcs7.c:193:5: 
191.           }
192.       }
193. >     argc = opt_num_rest();
194.       argv = opt_rest();
195.   

apps/opt.c:721:1: start of procedure opt_num_rest()
  719.   
  720.   /* How many items in remaining args? */
  721. > int opt_num_rest(void)
  722.   {
  723.       int i = 0;

apps/opt.c:723:5: 
  721.   int opt_num_rest(void)
  722.   {
  723. >     int i = 0;
  724.       char **pp;
  725.   

apps/opt.c:726:10: 
  724.       char **pp;
  725.   
  726. >     for (pp = opt_rest(); *pp; pp++, i++)
  727.           continue;
  728.       return i;

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

apps/opt.c:717:5: 
    715.   char **opt_rest(void)
    716.   {
    717. >     return &argv[opt_index];
    718.   }
    719.   

apps/opt.c:718:1: return from a call to opt_rest
    716.   {
    717.       return &argv[opt_index];
    718. > }
    719.   
    720.   /* How many items in remaining args? */

apps/opt.c:726:27: Loop condition is false. Leaving loop
  724.       char **pp;
  725.   
  726.       for (pp = opt_rest(); *pp; pp++, i++)
                                   ^
  727.           continue;
  728.       return i;

apps/opt.c:728:5: 
  726.       for (pp = opt_rest(); *pp; pp++, i++)
  727.           continue;
  728. >     return i;
  729.   }
  730.   

apps/opt.c:729:1: return from a call to opt_num_rest
  727.           continue;
  728.       return i;
  729. > }
  730.   
  731.   /* Return a string describing the parameter type. */

apps/pkcs7.c:194:5: 
192.       }
193.       argc = opt_num_rest();
194. >     argv = opt_rest();
195.   
196.       if (!app_load_modules(NULL))

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

apps/opt.c:717:5: 
  715.   char **opt_rest(void)
  716.   {
  717. >     return &argv[opt_index];
  718.   }
  719.   

apps/opt.c:718:1: return from a call to opt_rest
  716.   {
  717.       return &argv[opt_index];
  718. > }
  719.   
  720.   /* How many items in remaining args? */

apps/pkcs7.c:196:10: 
194.       argv = opt_rest();
195.   
196. >     if (!app_load_modules(NULL))
197.           goto end;
198.   

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/pkcs7.c:196:10: Taking false branch
194.       argv = opt_rest();
195.   
196.       if (!app_load_modules(NULL))
                ^
197.           goto end;
198.   

apps/pkcs7.c:199:35: Condition is true
197.           goto end;
198.   
199.       in = bio_open_default(infile, RB(informat));
                                         ^
200.       if (in == NULL)
201.           goto end;

apps/pkcs7.c:199:5: 
197.           goto end;
198.   
199. >     in = bio_open_default(infile, RB(informat));
200.       if (in == NULL)
201.           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 pkcs7_main(int argc, char **argv)
{
    PKCS7 *p7 = NULL;
    BIO *in = NULL, *out = NULL;
    int informat = FORMAT_PEM, outformat = FORMAT_PEM;
    char *infile = NULL, *outfile = NULL, *prog;
    int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, ret = 1;
    OPTION_CHOICE o;
    prog = opt_init(argc, argv, pkcs7_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(pkcs7_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_NOOUT:
            noout = 1;
            break;
        case OPT_TEXT:
            text = 1;
            break;
        case OPT_PRINT:
            p7_print = 1;
            break;
        case OPT_PRINT_CERTS:
            print_certs = 1;
            break;
        case OPT_ENGINE:
            (void)setup_engine(opt_arg(), 0);
            break;
        }
    }
    argc = opt_num_rest();
    argv = opt_rest();
    if (!app_load_modules(NULL))
        goto end;
    in = bio_open_default(infile, RB(informat));
    if (in == NULL)
        goto end;
    if (informat == FORMAT_ASN1)
        p7 = d2i_PKCS7_bio(in, NULL);
    else
        p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
    if (p7 == NULL) {
        BIO_printf(bio_err, "unable to load PKCS7 object\n");
        ERR_print_errors(bio_err);
        goto end;
    }
    out = bio_open_default(outfile, WB(outformat));
    if (out == NULL)
        goto end;
    if (p7_print)
        PKCS7_print_ctx(out, p7, 0, NULL);
    if (print_certs) {
        STACK_OF(X509) *certs = NULL;
        STACK_OF(X509_CRL) *crls = NULL;
        i = OBJ_obj2nid(p7->type);
        switch (i) {
        case NID_pkcs7_signed:
            certs = p7->d.sign->cert;
            crls = p7->d.sign->crl;
            break;
        case NID_pkcs7_signedAndEnveloped:
            certs = p7->d.signed_and_enveloped->cert;
            crls = p7->d.signed_and_enveloped->crl;
            break;
        default:
            break;
        }
        if (certs != NULL) {
            X509 *x;
            for (i = 0; i < sk_X509_num(certs); i++) {
                x = sk_X509_value(certs, i);
                if (text)
                    X509_print(out, x);
                else
                    dump_cert_text(out, x);
                if (!noout)
                    PEM_write_bio_X509(out, x);
                BIO_puts(out, "\n");
            }
        }
        if (crls != NULL) {
            X509_CRL *crl;
            for (i = 0; i < sk_X509_CRL_num(crls); i++) {
                crl = sk_X509_CRL_value(crls, i);
                X509_CRL_print(out, crl);
                if (!noout)
                    PEM_write_bio_X509_CRL(out, crl);
                BIO_puts(out, "\n");
            }
        }
        ret = 0;
        goto end;
    }
    if (!noout) {
        if (outformat == FORMAT_ASN1)
            i = i2d_PKCS7_bio(out, p7);
        else
            i = PEM_write_bio_PKCS7(out, p7);
        if (!i) {
            BIO_printf(bio_err, "unable to write pkcs7 object\n");
            ERR_print_errors(bio_err);
            goto end;
        }
    }
    ret = 0;
 end:
    PKCS7_free(p7);
    BIO_free(in);
    BIO_free_all(out);
    return (ret);
}
['int pkcs7_main(int argc, char **argv)\n{\n    PKCS7 *p7 = NULL;\n    BIO *in = NULL, *out = NULL;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM;\n    char *infile = NULL, *outfile = NULL, *prog;\n    int i, print_certs = 0, text = 0, noout = 0, p7_print = 0, ret = 1;\n    OPTION_CHOICE o;\n    prog = opt_init(argc, argv, pkcs7_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(pkcs7_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_NOOUT:\n            noout = 1;\n            break;\n        case OPT_TEXT:\n            text = 1;\n            break;\n        case OPT_PRINT:\n            p7_print = 1;\n            break;\n        case OPT_PRINT_CERTS:\n            print_certs = 1;\n            break;\n        case OPT_ENGINE:\n            (void)setup_engine(opt_arg(), 0);\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (!app_load_modules(NULL))\n        goto end;\n    in = bio_open_default(infile, RB(informat));\n    if (in == NULL)\n        goto end;\n    if (informat == FORMAT_ASN1)\n        p7 = d2i_PKCS7_bio(in, NULL);\n    else\n        p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);\n    if (p7 == NULL) {\n        BIO_printf(bio_err, "unable to load PKCS7 object\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    out = bio_open_default(outfile, WB(outformat));\n    if (out == NULL)\n        goto end;\n    if (p7_print)\n        PKCS7_print_ctx(out, p7, 0, NULL);\n    if (print_certs) {\n        STACK_OF(X509) *certs = NULL;\n        STACK_OF(X509_CRL) *crls = NULL;\n        i = OBJ_obj2nid(p7->type);\n        switch (i) {\n        case NID_pkcs7_signed:\n            certs = p7->d.sign->cert;\n            crls = p7->d.sign->crl;\n            break;\n        case NID_pkcs7_signedAndEnveloped:\n            certs = p7->d.signed_and_enveloped->cert;\n            crls = p7->d.signed_and_enveloped->crl;\n            break;\n        default:\n            break;\n        }\n        if (certs != NULL) {\n            X509 *x;\n            for (i = 0; i < sk_X509_num(certs); i++) {\n                x = sk_X509_value(certs, i);\n                if (text)\n                    X509_print(out, x);\n                else\n                    dump_cert_text(out, x);\n                if (!noout)\n                    PEM_write_bio_X509(out, x);\n                BIO_puts(out, "\\n");\n            }\n        }\n        if (crls != NULL) {\n            X509_CRL *crl;\n            for (i = 0; i < sk_X509_CRL_num(crls); i++) {\n                crl = sk_X509_CRL_value(crls, i);\n                X509_CRL_print(out, crl);\n                if (!noout)\n                    PEM_write_bio_X509_CRL(out, crl);\n                BIO_puts(out, "\\n");\n            }\n        }\n        ret = 0;\n        goto end;\n    }\n    if (!noout) {\n        if (outformat == FORMAT_ASN1)\n            i = i2d_PKCS7_bio(out, p7);\n        else\n            i = PEM_write_bio_PKCS7(out, p7);\n        if (!i) {\n            BIO_printf(bio_err, "unable to write pkcs7 object\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    ret = 0;\n end:\n    PKCS7_free(p7);\n    BIO_free(in);\n    BIO_free_all(out);\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}']