Fix late opening of output file
authorRichard Levitte <levitte@openssl.org>
Mon, 23 Apr 2018 08:26:05 +0000 (10:26 +0200)
committerRichard Levitte <levitte@openssl.org>
Mon, 23 Apr 2018 08:51:36 +0000 (10:51 +0200)
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 <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6051)

apps/dhparam.c

index 8a3a389155ea3cda455e88ead235e8b17171302f..44160fde2b549ef69865be8fdedcc516b9eb221f 100644 (file)
@@ -153,6 +153,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;
@@ -260,10 +265,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);
     }