Linux bluetooth development
 help / color / mirror / Atom feed
From: Andrejs Hanins <andrejs.hanins@ubnt.com>
To: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: [PATCH] core/gatt-database: Fix memory corruption
Date: Wed, 11 Mar 2015 15:31:57 +0200	[thread overview]
Message-ID: <550043CD.7080202@ubnt.com> (raw)

Pointer to on-stack variable was returned from pending_write_new
---
 src/gatt-database.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 35f8471..c0135b6 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -1461,6 +1461,7 @@ static void pending_op_free(void *data)
 	if (op->owner_queue)
 		queue_remove(op->owner_queue, op);
 
+	free(op->setup_data);
 	free(op);
 }
 
@@ -1561,19 +1562,24 @@ static struct pending_op *pending_write_new(struct queue *owner_queue,
 					size_t len)
 {
 	struct pending_op *op;
-	struct iovec iov;
+	struct iovec* iov;
 
 	op = new0(struct pending_op, 1);
 	if (!op)
 		return NULL;
+	iov = new0(struct iovec, 1);
+	if (!iov) {
+		free(op);
+		return NULL;
+	}
 
-	iov.iov_base = (uint8_t *) value;
-	iov.iov_len = len;
+	iov->iov_base = (uint8_t *) value;
+	iov->iov_len = len;
 
 	op->owner_queue = owner_queue;
 	op->attrib = attrib;
 	op->id = id;
-	op->setup_data = &iov;
+	op->setup_data = iov;
 	queue_push_tail(owner_queue, op);
 
 	return op;
-- 
1.9.1


             reply	other threads:[~2015-03-11 13:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-11 13:31 Andrejs Hanins [this message]
2015-03-11 14:06 ` [PATCH] core/gatt-database: Fix memory corruption Luiz Augusto von Dentz
2015-03-11 14:35   ` Andrejs Hanins
2015-03-11 21:19     ` Stefan Seyfried
2015-03-12  8:24       ` Andrejs Hanins
2015-03-12  8:39         ` Luiz Augusto von Dentz
2015-03-12  8:54           ` Andrejs Hanins
2015-03-12  9:14             ` Luiz Augusto von Dentz
2015-03-12  9:32               ` Andrejs Hanins
2015-03-12 10:16                 ` Johan Hedberg

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=550043CD.7080202@ubnt.com \
    --to=andrejs.hanins@ubnt.com \
    --cc=linux-bluetooth@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox