Check more return values in the SRP code
[openssl.git] / apps / pkey.c
index 6160e5a381d0bca0b23d8c9542646550a5d57dbb..0dd5590bdc0bc7cc63a3500a2c7c879146048ff1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -10,6 +10,7 @@
 #include <stdio.h>
 #include <string.h>
 #include "apps.h"
+#include "progs.h"
 #include <openssl/pem.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
@@ -185,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");
@@ -211,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;
         }
     }