All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Daniel P . Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PULL v1 1/7] cipher: fix leak on initialization error
Date: Wed, 21 Dec 2016 14:35:35 +0000	[thread overview]
Message-ID: <20161221143541.9260-2-berrange@redhat.com> (raw)
In-Reply-To: <20161221143541.9260-1-berrange@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

On error path, ctx may be leaked. Assign ctx earlier, and call
qcrypto_cipher_free() on error.

Spotted thanks to ASAN.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 crypto/cipher-nettle.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c
index cd094cd..5798910 100644
--- a/crypto/cipher-nettle.c
+++ b/crypto/cipher-nettle.c
@@ -254,6 +254,7 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
     cipher->mode = mode;
 
     ctx = g_new0(QCryptoCipherNettle, 1);
+    cipher->opaque = ctx;
 
     switch (alg) {
     case QCRYPTO_CIPHER_ALG_DES_RFB:
@@ -384,13 +385,11 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
     }
 
     ctx->iv = g_new0(uint8_t, ctx->blocksize);
-    cipher->opaque = ctx;
 
     return cipher;
 
  error:
-    g_free(cipher);
-    g_free(ctx);
+    qcrypto_cipher_free(cipher);
     return NULL;
 }
 
-- 
2.9.3

  reply	other threads:[~2016-12-21 14:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-21 14:35 [Qemu-devel] [PULL v1 0/7] Merge qcrypto 2016/12/21 Daniel P. Berrange
2016-12-21 14:35 ` Daniel P. Berrange [this message]
2016-12-21 14:35 ` [Qemu-devel] [PULL v1 2/7] crypto: add 3des-ede support when using libgcrypt/nettle Daniel P. Berrange
2016-12-21 14:35 ` [Qemu-devel] [PULL v1 3/7] crypto: add HMAC algorithms framework Daniel P. Berrange
2016-12-22  1:07   ` Longpeng (Mike)
2016-12-22  9:26     ` Daniel P. Berrange
2016-12-21 14:35 ` [Qemu-devel] [PULL v1 4/7] crypto: support HMAC algorithms based on libgcrypt Daniel P. Berrange
2016-12-21 14:35 ` [Qemu-devel] [PULL v1 5/7] crypto: support HMAC algorithms based on glib Daniel P. Berrange
2016-12-21 14:35 ` [Qemu-devel] [PULL v1 6/7] crypto: support HMAC algorithms based on nettle Daniel P. Berrange
2016-12-21 14:35 ` [Qemu-devel] [PULL v1 7/7] crypto: add HMAC algorithms testcases Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161221143541.9260-2-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.