Commit 7afe18bd authored by Richard Levitte's avatar Richard Levitte
Browse files

Fix late opening of output file



For 'openssl dhparams', the output file was opened after calculations
were made, which is a waste of cycles and time if the output file
turns out not to be writable.

Fixes #3404

Reviewed-by: default avatarMatt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6051)

(cherry picked from commit 10b37541)
parent bf21fe93
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -151,6 +151,11 @@ int dhparam_main(int argc, char **argv)
        goto end;
    }
# endif

    out = bio_open_default(outfile, 'w', outformat);
    if (out == NULL)
        goto end;

    /* DH parameters */
    if (num && !g)
        g = 2;
@@ -266,10 +271,6 @@ int dhparam_main(int argc, char **argv)
        /* dh != NULL */
    }

    out = bio_open_default(outfile, 'w', outformat);
    if (out == NULL)
        goto end;

    if (text) {
        DHparams_print(out, dh);
    }