Fix a memory leak in i2d_RSA_NET on failure of ASN1_STRING_set.
authorbcook <bcook@openbsd.org>
Sun, 5 Aug 2018 13:35:45 +0000 (13:35 +0000)
committerbcook <bcook@openbsd.org>
Sun, 5 Aug 2018 13:35:45 +0000 (13:35 +0000)
Found by Coverity.
Feedback and ok tb@

lib/libcrypto/asn1/n_pkey.c

index d2fabf6..6c70316 100644 (file)
@@ -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 */