Fix printing of DH Parameters
authorMatt Caswell <matt@openssl.org>
Fri, 27 May 2016 12:55:47 +0000 (13:55 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 1 Jun 2016 12:19:02 +0000 (13:19 +0100)
The -text argument to dhparam is broken, because the DHparams_print()
function always returns an error. The problem is that always expects a
public or private key to be present, even though that is never the case
with parameters.

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/dh/dh_ameth.c

index b7b37177c160174b06a390330e215ec4bc4383d0..78aea36093263ee2d58d18393f4d402d5cb737df 100644 (file)
@@ -280,7 +280,8 @@ static int do_dh_print(BIO *bp, const DH *x, int indent, int ptype)
     else
         pub_key = NULL;
 
     else
         pub_key = NULL;
 
-    if (priv_key == NULL && pub_key == NULL) {
+    if (x->p == NULL || (ptype == 2 && priv_key == NULL)
+            || (ptype > 0 && pub_key == NULL)) {
         reason = ERR_R_PASSED_NULL_PARAMETER;
         goto err;
     }
         reason = ERR_R_PASSED_NULL_PARAMETER;
         goto err;
     }