Do not ignore EVP_PKEY_print_public/EVP_PKEY_print_private return values
authorDmitry Belyavskiy <beldmit@gmail.com>
Sat, 18 Aug 2018 16:43:23 +0000 (19:43 +0300)
committerNicola Tuveri <nic.tuv@gmail.com>
Fri, 24 Aug 2018 12:33:26 +0000 (15:33 +0300)
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/7007)

apps/pkey.c

index 760fc1bbc058203243f634bc78c57489df5cf9de..0dd5590bdc0bc7cc63a3500a2c7c879146048ff1 100644 (file)
@@ -186,23 +186,29 @@ int pkey_main(int argc, char **argv)
     if (!noout) {
         if (outformat == FORMAT_PEM) {
             if (pubout) {
-                PEM_write_bio_PUBKEY(out, pkey);
+                if (!PEM_write_bio_PUBKEY(out, pkey))
+                    goto end;
             } else {
                 assert(private);
-                if (traditional)
-                    PEM_write_bio_PrivateKey_traditional(out, pkey, cipher,
-                                                         NULL, 0, NULL,
-                                                         passout);
-                else
-                    PEM_write_bio_PrivateKey(out, pkey, cipher,
-                                             NULL, 0, NULL, passout);
+                if (traditional) {
+                    if (!PEM_write_bio_PrivateKey_traditional(out, pkey, cipher,
+                                                              NULL, 0, NULL,
+                                                              passout))
+                        goto end;
+                } else {
+                    if (!PEM_write_bio_PrivateKey(out, pkey, cipher,
+                                                  NULL, 0, NULL, passout))
+                        goto end;
+                }
             }
         } else if (outformat == FORMAT_ASN1) {
             if (pubout) {
-                i2d_PUBKEY_bio(out, pkey);
+                if (!i2d_PUBKEY_bio(out, pkey))
+                    goto end;
             } else {
                 assert(private);
-                i2d_PrivateKey_bio(out, pkey);
+                if (!i2d_PrivateKey_bio(out, pkey))
+                    goto end;
             }
         } else {
             BIO_printf(bio_err, "Bad format specified for key\n");
@@ -212,10 +218,12 @@ int pkey_main(int argc, char **argv)
 
     if (text) {
         if (pubtext) {
-            EVP_PKEY_print_public(out, pkey, 0, NULL);
+            if (EVP_PKEY_print_public(out, pkey, 0, NULL) <= 0)
+                goto end;
         } else {
             assert(private);
-            EVP_PKEY_print_private(out, pkey, 0, NULL);
+            if (EVP_PKEY_print_private(out, pkey, 0, NULL) <= 0)
+                goto end;
         }
     }