Add error handling in dsa_main and ASN1_i2d_bio.
authorPavel Kopyl <p.kopyl@samsung.com>
Fri, 27 Oct 2017 13:13:11 +0000 (16:13 +0300)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 3 Nov 2017 15:19:00 +0000 (16:19 +0100)
CLA: trivial

Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from https://github.com/openssl/openssl/pull/4600)

(cherry picked from commit a6f622bc99ffdc7b34199babb9d200b24a7a6431)

apps/dsa.c
crypto/asn1/a_i2d_fp.c

index 4ed21d891e8698f5c852bb10a02098e6ae24173e..82a870eb291004f8992e52a79d3b0ff19f7e05e0 100644 (file)
@@ -327,6 +327,9 @@ int MAIN(int argc, char **argv)
     } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
         EVP_PKEY *pk;
         pk = EVP_PKEY_new();
+        if (pk == NULL)
+           goto end;
+
         EVP_PKEY_set1_DSA(pk, dsa);
         if (outformat == FORMAT_PVK)
             i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
index 0f56cd4e07451bdb596a8ebe6bef0bbac2dfa958..2e85e041e4cf40e9ca59349feaeecff8588cec19 100644 (file)
@@ -87,6 +87,9 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
     int i, j = 0, n, ret = 1;
 
     n = i2d(x, NULL);
+    if (n <= 0)
+        return 0;
+
     b = (char *)OPENSSL_malloc(n);
     if (b == NULL) {
         ASN1err(ASN1_F_ASN1_I2D_BIO, ERR_R_MALLOC_FAILURE);