summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/pem/pvkfmt.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/lib/libcrypto/pem/pvkfmt.c b/src/lib/libcrypto/pem/pvkfmt.c
index 18de5d52a4..76cc6fefe3 100644
--- a/src/lib/libcrypto/pem/pvkfmt.c
+++ b/src/lib/libcrypto/pem/pvkfmt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pvkfmt.c,v 1.19 2017/05/02 03:59:44 deraadt Exp $ */ 1/* $OpenBSD: pvkfmt.c,v 1.20 2018/08/05 11:19:25 bcook Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -847,17 +847,10 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
847 if (pklen < 0) 847 if (pklen < 0)
848 return -1; 848 return -1;
849 outlen += pklen; 849 outlen += pklen;
850 if (!out) 850 p = malloc(outlen);
851 return outlen; 851 if (!p) {
852 if (*out) 852 PEMerror(ERR_R_MALLOC_FAILURE);
853 p = *out; 853 return -1;
854 else {
855 p = malloc(outlen);
856 if (!p) {
857 PEMerror(ERR_R_MALLOC_FAILURE);
858 return -1;
859 }
860 *out = p;
861 } 854 }
862 855
863 write_ledword(&p, MS_PVKMAGIC); 856 write_ledword(&p, MS_PVKMAGIC);
@@ -875,9 +868,10 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
875 p += PVK_SALTLEN; 868 p += PVK_SALTLEN;
876 } 869 }
877 do_i2b(&p, pk, 0); 870 do_i2b(&p, pk, 0);
878 if (enclevel == 0) 871 if (enclevel == 0) {
872 *out = p;
879 return outlen; 873 return outlen;
880 else { 874 } else {
881 char psbuf[PEM_BUFSIZE]; 875 char psbuf[PEM_BUFSIZE];
882 unsigned char keybuf[20]; 876 unsigned char keybuf[20];
883 int enctmplen, inlen; 877 int enctmplen, inlen;
@@ -904,10 +898,12 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
904 goto error; 898 goto error;
905 } 899 }
906 EVP_CIPHER_CTX_cleanup(&cctx); 900 EVP_CIPHER_CTX_cleanup(&cctx);
901 *out = p;
907 return outlen; 902 return outlen;
908 903
909error: 904error:
910 EVP_CIPHER_CTX_cleanup(&cctx); 905 EVP_CIPHER_CTX_cleanup(&cctx);
906 free(p);
911 return -1; 907 return -1;
912} 908}
913 909