From f595cb837c158c8d4e40c087ad1dfa9b3659e900 Mon Sep 17 00:00:00 2001 From: bcook Date: Sun, 5 Aug 2018 13:35:45 +0000 Subject: [PATCH] Fix a memory leak in i2d_RSA_NET on failure of ASN1_STRING_set. Found by Coverity. Feedback and ok tb@ --- lib/libcrypto/asn1/n_pkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libcrypto/asn1/n_pkey.c b/lib/libcrypto/asn1/n_pkey.c index d2fabf6e879..6c7031677df 100644 --- a/lib/libcrypto/asn1/n_pkey.c +++ b/lib/libcrypto/asn1/n_pkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: n_pkey.c,v 1.31 2017/01/29 17:49:22 beck Exp $ */ +/* $OpenBSD: n_pkey.c,v 1.32 2018/08/05 13:35:45 bcook Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -273,11 +273,11 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp, goto err; } + enckey->enckey->digest->data = zz; if (!ASN1_STRING_set(enckey->os, "private-key", -1)) { ASN1error(ERR_R_MALLOC_FAILURE); goto err; } - enckey->enckey->digest->data = zz; i2d_NETSCAPE_PKEY(pkey, &zz); /* Wipe the private key encoding */ -- 2.20.1