From: Richard Levitte Date: Mon, 23 Apr 2018 08:26:05 +0000 (+0200) Subject: Fix late opening of output file X-Git-Tag: OpenSSL_1_1_0i~167 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7afe18bd003ff7477168626d99efb5a297f2df39;p=openssl 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: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/6051) (cherry picked from commit 10b37541dc7f27b0ca74102970691ce4636cc0bd) --- diff --git a/apps/dhparam.c b/apps/dhparam.c index 94322e37de..ae2279e243 100644 --- a/apps/dhparam.c +++ b/apps/dhparam.c @@ -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); }