apps/gendsa.c:186: error: NULL_DEREFERENCE
  pointer `dsa` last assigned on line 97 could be null and is dereferenced by call to `DSA_free()` at line 186, column 5.
Showing all 41 steps of the trace


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

apps/gendsa.c:96:5: 
94.   int gendsa_main(int argc, char **argv)
95.   {
96. >     BIO *out = NULL, *in = NULL;
97.       DSA *dsa = NULL;
98.       const EVP_CIPHER *enc = NULL;

apps/gendsa.c:97:5: 
95.   {
96.       BIO *out = NULL, *in = NULL;
97. >     DSA *dsa = NULL;
98.       const EVP_CIPHER *enc = NULL;
99.       char *inrand = NULL, *dsaparams = NULL;

apps/gendsa.c:98:5: 
96.       BIO *out = NULL, *in = NULL;
97.       DSA *dsa = NULL;
98. >     const EVP_CIPHER *enc = NULL;
99.       char *inrand = NULL, *dsaparams = NULL;
100.       char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;

apps/gendsa.c:99:5: 
97.       DSA *dsa = NULL;
98.       const EVP_CIPHER *enc = NULL;
99. >     char *inrand = NULL, *dsaparams = NULL;
100.       char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;
101.       OPTION_CHOICE o;

apps/gendsa.c:100:5: 
98.       const EVP_CIPHER *enc = NULL;
99.       char *inrand = NULL, *dsaparams = NULL;
100. >     char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;
101.       OPTION_CHOICE o;
102.       int ret = 1, private = 0;

apps/gendsa.c:102:5: 
100.       char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;
101.       OPTION_CHOICE o;
102. >     int ret = 1, private = 0;
103.   
104.       prog = opt_init(argc, argv, gendsa_options);

apps/gendsa.c:104:5: Skipping opt_init(): empty list of specs
102.       int ret = 1, private = 0;
103.   
104.       prog = opt_init(argc, argv, gendsa_options);
           ^
105.       while ((o = opt_next()) != OPT_EOF) {
106.           switch (o) {

apps/gendsa.c:105:12: Loop condition is true. Entering loop body
103.   
104.       prog = opt_init(argc, argv, gendsa_options);
105.       while ((o = opt_next()) != OPT_EOF) {
                  ^
106.           switch (o) {
107.           case OPT_EOF:

apps/gendsa.c:106:9: 
104.       prog = opt_init(argc, argv, gendsa_options);
105.       while ((o = opt_next()) != OPT_EOF) {
106. >         switch (o) {
107.           case OPT_EOF:
108.           case OPT_ERR:

apps/gendsa.c:107:9: Switch condition is false. Skipping switch case
105.       while ((o = opt_next()) != OPT_EOF) {
106.           switch (o) {
107.           case OPT_EOF:
               ^
108.           case OPT_ERR:
109.    opthelp:

apps/gendsa.c:108:9: Switch condition is false. Skipping switch case
106.           switch (o) {
107.           case OPT_EOF:
108.           case OPT_ERR:
               ^
109.    opthelp:
110.               BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);

apps/gendsa.c:112:9: Switch condition is true. Entering switch case
110.               BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
111.               goto end;
112.           case OPT_HELP:
               ^
113.               ret = 0;
114.               opt_help(gendsa_options);

apps/gendsa.c:113:13: 
111.               goto end;
112.           case OPT_HELP:
113. >             ret = 0;
114.               opt_help(gendsa_options);
115.               goto end;

apps/gendsa.c:114:13: Skipping opt_help(): empty list of specs
112.           case OPT_HELP:
113.               ret = 0;
114.               opt_help(gendsa_options);
                   ^
115.               goto end;
116.           case OPT_OUT:

apps/gendsa.c:180:2: 
178.           goto end;
179.       ret = 0;
180. >  end:
181.       if (ret != 0)
182.           ERR_print_errors(bio_err);

apps/gendsa.c:181:9: Taking false branch
179.       ret = 0;
180.    end:
181.       if (ret != 0)
               ^
182.           ERR_print_errors(bio_err);
183.    end2:

apps/gendsa.c:183:2: 
181.       if (ret != 0)
182.           ERR_print_errors(bio_err);
183. >  end2:
184.       BIO_free(in);
185.       BIO_free_all(out);

apps/gendsa.c:184:5: 
182.           ERR_print_errors(bio_err);
183.    end2:
184. >     BIO_free(in);
185.       BIO_free_all(out);
186.       DSA_free(dsa);

crypto/bio/bio_lib.c:106:1: start of procedure BIO_free()
  104.   }
  105.   
  106. > int BIO_free(BIO *a)
  107.   {
  108.       int i;

crypto/bio/bio_lib.c:110:9: Taking true branch
  108.       int i;
  109.   
  110.       if (a == NULL)
                 ^
  111.           return (0);
  112.   

crypto/bio/bio_lib.c:111:9: 
  109.   
  110.       if (a == NULL)
  111. >         return (0);
  112.   
  113.       i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);

crypto/bio/bio_lib.c:135:1: return from a call to BIO_free
  133.       OPENSSL_free(a);
  134.       return (1);
  135. > }
  136.   
  137.   void BIO_vfree(BIO *a)

apps/gendsa.c:185:5: 
183.    end2:
184.       BIO_free(in);
185. >     BIO_free_all(out);
186.       DSA_free(dsa);
187.       OPENSSL_free(passout);

crypto/bio/bio_lib.c:499:1: start of procedure BIO_free_all()
  497.   }
  498.   
  499. > void BIO_free_all(BIO *bio)
  500.   {
  501.       BIO *b;

crypto/bio/bio_lib.c:504:12: Loop condition is false. Leaving loop
  502.       int ref;
  503.   
  504.       while (bio != NULL) {
                    ^
  505.           b = bio;
  506.           ref = b->references;

crypto/bio/bio_lib.c:513:1: return from a call to BIO_free_all
  511.               break;
  512.       }
  513. > }
  514.   
  515.   BIO *BIO_dup_chain(BIO *in)

apps/gendsa.c:186:5: 
184.       BIO_free(in);
185.       BIO_free_all(out);
186. >     DSA_free(dsa);
187.       OPENSSL_free(passout);
188.       return (ret);

crypto/dsa/dsa_lib.c:161:1: start of procedure DSA_free()
  159.   }
  160.   
  161. > void DSA_free(DSA *r)
  162.   {
  163.       int i;

crypto/dsa/dsa_lib.c:165:9: Taking false branch
  163.       int i;
  164.   
  165.       if (r == NULL)
                 ^
  166.           return;
  167.   

crypto/dsa/dsa_lib.c:168:5: 
  166.           return;
  167.   
  168. >     i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA);
  169.   #ifdef REF_PRINT
  170.       REF_PRINT("DSA", r);

crypto/lock.c:458:1: start of procedure CRYPTO_add_lock()
    456.   }
    457.   
    458. > int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
    459.                       int line)
    460.   {

crypto/lock.c:461:5: 
    459.                       int line)
    460.   {
    461. >     int ret = 0;
    462.   
    463.       if (add_lock_callback != NULL) {

crypto/lock.c:463:9: Taking false branch
    461.       int ret = 0;
    462.   
    463.       if (add_lock_callback != NULL) {
                   ^
    464.   #ifdef LOCK_DEBUG
    465.           int before = *pointer;

crypto/lock.c:479:9: 
    477.   #endif
    478.       } else {
    479. >         CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);
    480.   
    481.           ret = *pointer + amount;

crypto/lock.c:416:1: start of procedure CRYPTO_lock()
      414.   }
      415.   
      416. > void CRYPTO_lock(int mode, int type, const char *file, int line)
      417.   {
      418.   #ifdef LOCK_DEBUG

crypto/lock.c:443:9: Taking false branch
      441.       }
      442.   #endif
      443.       if (type < 0) {
                     ^
      444.           if (dynlock_lock_callback != NULL) {
      445.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:454:16: Taking false branch
      452.               CRYPTO_destroy_dynlockid(type);
      453.           }
      454.       } else if (locking_callback != NULL)
                            ^
      455.           locking_callback(mode, type, file, line);
      456.   }

crypto/lock.c:443:5: 
      441.       }
      442.   #endif
      443. >     if (type < 0) {
      444.           if (dynlock_lock_callback != NULL) {
      445.               struct CRYPTO_dynlock_value *pointer

crypto/lock.c:456:1: return from a call to CRYPTO_lock
      454.       } else if (locking_callback != NULL)
      455.           locking_callback(mode, type, file, line);
      456. > }
      457.   
      458.   int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,

crypto/lock.c:481:9: 
    479.           CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);
    480.   
    481. >         ret = *pointer + amount;
    482.   #ifdef LOCK_DEBUG
    483.           {

int gendsa_main(int argc, char **argv)
{
    BIO *out = NULL, *in = NULL;
    DSA *dsa = NULL;
    const EVP_CIPHER *enc = NULL;
    char *inrand = NULL, *dsaparams = NULL;
    char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;
    OPTION_CHOICE o;
    int ret = 1, private = 0;
    prog = opt_init(argc, argv, gendsa_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(gendsa_options);
            goto end;
        case OPT_OUT:
            outfile = opt_arg();
            break;
        case OPT_PASSOUT:
            passoutarg = opt_arg();
            break;
        case OPT_ENGINE:
            (void)setup_engine(opt_arg(), 0);
            break;
        case OPT_RAND:
            inrand = opt_arg();
            break;
        case OPT_CIPHER:
            if (!opt_cipher(opt_unknown(), &enc))
                goto end;
            break;
        }
    }
    argc = opt_num_rest();
    argv = opt_rest();
    private = 1;
    if (argc != 1)
        goto opthelp;
    dsaparams = *argv;
    if (!app_passwd(NULL, passoutarg, NULL, &passout)) {
        BIO_printf(bio_err, "Error getting password\n");
        goto end;
    }
    in = bio_open_default(dsaparams, 'r', FORMAT_PEM);
    if (in == NULL)
        goto end2;
    if ((dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL)) == NULL) {
        BIO_printf(bio_err, "unable to load DSA parameter file\n");
        goto end;
    }
    BIO_free(in);
    in = NULL;
    out = bio_open_owner(outfile, FORMAT_PEM, private);
    if (out == NULL)
        goto end2;
    if (!app_RAND_load_file(NULL, 1) && inrand == NULL) {
        BIO_printf(bio_err,
                   "warning, not much extra random data, consider using the -rand option\n");
    }
    if (inrand != NULL)
        BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
                   app_RAND_load_files(inrand));
    BIO_printf(bio_err, "Generating DSA key, %d bits\n", BN_num_bits(dsa->p));
    if (!DSA_generate_key(dsa))
        goto end;
    app_RAND_write_file(NULL);
    assert(private);
    if (!PEM_write_bio_DSAPrivateKey(out, dsa, enc, NULL, 0, NULL, passout))
        goto end;
    ret = 0;
 end:
    if (ret != 0)
        ERR_print_errors(bio_err);
 end2:
    BIO_free(in);
    BIO_free_all(out);
    DSA_free(dsa);
    OPENSSL_free(passout);
    return (ret);
}
['int gendsa_main(int argc, char **argv)\n{\n    BIO *out = NULL, *in = NULL;\n    DSA *dsa = NULL;\n    const EVP_CIPHER *enc = NULL;\n    char *inrand = NULL, *dsaparams = NULL;\n    char *outfile = NULL, *passoutarg = NULL, *passout = NULL, *prog;\n    OPTION_CHOICE o;\n    int ret = 1, private = 0;\n    prog = opt_init(argc, argv, gendsa_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(gendsa_options);\n            goto end;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_PASSOUT:\n            passoutarg = opt_arg();\n            break;\n        case OPT_ENGINE:\n            (void)setup_engine(opt_arg(), 0);\n            break;\n        case OPT_RAND:\n            inrand = opt_arg();\n            break;\n        case OPT_CIPHER:\n            if (!opt_cipher(opt_unknown(), &enc))\n                goto end;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    private = 1;\n    if (argc != 1)\n        goto opthelp;\n    dsaparams = *argv;\n    if (!app_passwd(NULL, passoutarg, NULL, &passout)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    in = bio_open_default(dsaparams, \'r\', FORMAT_PEM);\n    if (in == NULL)\n        goto end2;\n    if ((dsa = PEM_read_bio_DSAparams(in, NULL, NULL, NULL)) == NULL) {\n        BIO_printf(bio_err, "unable to load DSA parameter file\\n");\n        goto end;\n    }\n    BIO_free(in);\n    in = NULL;\n    out = bio_open_owner(outfile, FORMAT_PEM, private);\n    if (out == NULL)\n        goto end2;\n    if (!app_RAND_load_file(NULL, 1) && inrand == NULL) {\n        BIO_printf(bio_err,\n                   "warning, not much extra random data, consider using the -rand option\\n");\n    }\n    if (inrand != NULL)\n        BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n                   app_RAND_load_files(inrand));\n    BIO_printf(bio_err, "Generating DSA key, %d bits\\n", BN_num_bits(dsa->p));\n    if (!DSA_generate_key(dsa))\n        goto end;\n    app_RAND_write_file(NULL);\n    assert(private);\n    if (!PEM_write_bio_DSAPrivateKey(out, dsa, enc, NULL, 0, NULL, passout))\n        goto end;\n    ret = 0;\n end:\n    if (ret != 0)\n        ERR_print_errors(bio_err);\n end2:\n    BIO_free(in);\n    BIO_free_all(out);\n    DSA_free(dsa);\n    OPENSSL_free(passout);\n    return (ret);\n}', 'int BIO_free(BIO *a)\n{\n    int i;\n    if (a == NULL)\n        return (0);\n    i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);\n#ifdef REF_PRINT\n    REF_PRINT("BIO", a);\n#endif\n    if (i > 0)\n        return (1);\n#ifdef REF_CHECK\n    if (i < 0) {\n        fprintf(stderr, "BIO_free, bad reference count\\n");\n        abort();\n    }\n#endif\n    if ((a->callback != NULL) &&\n        ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))\n        return (i);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);\n    if ((a->method != NULL) && (a->method->destroy != NULL))\n        a->method->destroy(a);\n    OPENSSL_free(a);\n    return (1);\n}', 'void BIO_free_all(BIO *bio)\n{\n    BIO *b;\n    int ref;\n    while (bio != NULL) {\n        b = bio;\n        ref = b->references;\n        bio = bio->next_bio;\n        BIO_free(b);\n        if (ref > 1)\n            break;\n    }\n}', 'void DSA_free(DSA *r)\n{\n    int i;\n    if (r == NULL)\n        return;\n    i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA);\n#ifdef REF_PRINT\n    REF_PRINT("DSA", r);\n#endif\n    if (i > 0)\n        return;\n#ifdef REF_CHECK\n    if (i < 0) {\n        fprintf(stderr, "DSA_free, bad reference count\\n");\n        abort();\n    }\n#endif\n    if (r->meth->finish)\n        r->meth->finish(r);\n#ifndef OPENSSL_NO_ENGINE\n    if (r->engine)\n        ENGINE_finish(r->engine);\n#endif\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);\n    BN_clear_free(r->p);\n    BN_clear_free(r->q);\n    BN_clear_free(r->g);\n    BN_clear_free(r->pub_key);\n    BN_clear_free(r->priv_key);\n    BN_clear_free(r->kinv);\n    BN_clear_free(r->r);\n    OPENSSL_free(r);\n}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n                    int line)\n{\n    int ret = 0;\n    if (add_lock_callback != NULL) {\n#ifdef LOCK_DEBUG\n        int before = *pointer;\n#endif\n        ret = add_lock_callback(pointer, amount, type, file, line);\n#ifdef LOCK_DEBUG\n        {\n            CRYPTO_THREADID id;\n            CRYPTO_THREADID_current(&id);\n            fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n                    CRYPTO_THREADID_hash(&id), before, amount, ret,\n                    CRYPTO_get_lock_name(type), file, line);\n        }\n#endif\n    } else {\n        CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, type, file, line);\n        ret = *pointer + amount;\n#ifdef LOCK_DEBUG\n        {\n            CRYPTO_THREADID id;\n            CRYPTO_THREADID_current(&id);\n            fprintf(stderr, "ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n                    CRYPTO_THREADID_hash(&id),\n                    *pointer, amount, ret,\n                    CRYPTO_get_lock_name(type), file, line);\n        }\n#endif\n        *pointer = ret;\n        CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, type, file, line);\n    }\n    return (ret);\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n{\n#ifdef LOCK_DEBUG\n    {\n        CRYPTO_THREADID id;\n        char *rw_text, *operation_text;\n        if (mode & CRYPTO_LOCK)\n            operation_text = "lock  ";\n        else if (mode & CRYPTO_UNLOCK)\n            operation_text = "unlock";\n        else\n            operation_text = "ERROR ";\n        if (mode & CRYPTO_READ)\n            rw_text = "r";\n        else if (mode & CRYPTO_WRITE)\n            rw_text = "w";\n        else\n            rw_text = "ERROR";\n        CRYPTO_THREADID_current(&id);\n        fprintf(stderr, "lock:%08lx:(%s)%s %-18s %s:%d\\n",\n                CRYPTO_THREADID_hash(&id), rw_text, operation_text,\n                CRYPTO_get_lock_name(type), file, line);\n    }\n#endif\n    if (type < 0) {\n        if (dynlock_lock_callback != NULL) {\n            struct CRYPTO_dynlock_value *pointer\n                = CRYPTO_get_dynlock_value(type);\n            OPENSSL_assert(pointer != NULL);\n            dynlock_lock_callback(mode, pointer, file, line);\n            CRYPTO_destroy_dynlockid(type);\n        }\n    } else if (locking_callback != NULL)\n        locking_callback(mode, type, file, line);\n}']