Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] core/gatt-database: Fix memory corruption
@ 2015-03-11 13:31 Andrejs Hanins
  2015-03-11 14:06 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 10+ messages in thread
From: Andrejs Hanins @ 2015-03-11 13:31 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-03-12 10:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-11 13:31 [PATCH] core/gatt-database: Fix memory corruption Andrejs Hanins
2015-03-11 14:06 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox