Linux-Bluetooth Archive on lore.kernel.org
 help / Atom feed
* [PATCH BlueZ 1/2] unit/test-sdp: Avoid extra copies when sending a PDU
@ 2019-01-11 14:18 Luiz Augusto von Dentz
  2019-01-11 14:18 ` [PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9 Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2019-01-11 14:18 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Make use of writev instead of creating a separate buffer to transmit
the data.
---
 unit/test-sdp.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 5a50cbbf1..66da038cd 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <sys/socket.h>
+#include <sys/uio.h>
 
 #include <glib.h>
 
@@ -191,31 +192,23 @@ static gboolean send_pdu(gpointer user_data)
 {
 	struct context *context = user_data;
 	const struct sdp_pdu *req_pdu;
-	uint16_t pdu_len;
-	unsigned char *buf;
+	struct iovec iov[2];
 	ssize_t len;
 
 	req_pdu = &context->data->pdu_list[context->pdu_offset];
 
-	pdu_len = req_pdu->raw_size + context->cont_size;
+	iov[0].iov_base = (void *) req_pdu->raw_data;
+	iov[0].iov_len = req_pdu->raw_size;
 
-	buf = g_malloc0(pdu_len);
+	iov[1].iov_base = context->cont_data;
+	iov[1].iov_len = context->cont_size;
 
-	memcpy(buf, req_pdu->raw_data, req_pdu->raw_size);
+	if (context->cont_size && context->cont_size != req_pdu->cont_len)
+		put_be16(req_pdu->cont_len, iov[1].iov_base + 4);
 
-	if (context->cont_size > 0) {
-		memcpy(buf + req_pdu->raw_size, context->cont_data,
-						context->cont_size);
-		if (context->cont_size != req_pdu->cont_len)
-			put_be16(req_pdu->cont_len,
-					buf + req_pdu->raw_size + 4);
-	}
-
-	len = write(context->fd, buf, pdu_len);
-
-	g_free(buf);
+	len = writev(context->fd, iov, 2);
 
-	g_assert(len == pdu_len);
+	g_assert(len == (ssize_t) (iov[0].iov_len + iov[1].iov_len));
 
 	return FALSE;
 }
-- 
2.17.2


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

* [PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9
  2019-01-11 14:18 [PATCH BlueZ 1/2] unit/test-sdp: Avoid extra copies when sending a PDU Luiz Augusto von Dentz
@ 2019-01-11 14:18 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2019-01-11 14:18 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Raw data payload must be copied since the declaration goes out of
scope:

Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=202213
---
 unit/test-avctp.c |  2 +-
 unit/test-avdtp.c |  2 +-
 unit/test-avrcp.c |  2 +-
 unit/test-gatt.c  |  2 +-
 unit/test-hfp.c   |  2 +-
 unit/test-hog.c   | 10 +++++-----
 unit/test-sdp.c   |  6 +++---
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/unit/test-avctp.c b/unit/test-avctp.c
index 60fd6ad71..e338acb07 100644
--- a/unit/test-avctp.c
+++ b/unit/test-avctp.c
@@ -66,7 +66,7 @@ struct context {
 #define raw_pdu(args...)					\
 	{							\
 		.valid = true,					\
-		.data = data(args),				\
+		.data = g_memdup(data(args), sizeof(data(args))), \
 		.size = sizeof(data(args)),			\
 	}
 
diff --git a/unit/test-avdtp.c b/unit/test-avdtp.c
index 176852ae7..2fb6877f9 100644
--- a/unit/test-avdtp.c
+++ b/unit/test-avdtp.c
@@ -61,7 +61,7 @@ struct test_data {
 #define raw_pdu(args...) \
 	{							\
 		.valid = true,					\
-		.data = data(args),				\
+		.data = g_memdup(data(args), sizeof(data(args))), \
 		.size = sizeof(data(args)),			\
 	}
 
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 9ffd44cfd..ddde68d71 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -74,7 +74,7 @@ struct context {
 #define raw_pdu(args...)					\
 	{							\
 		.valid = true,					\
-		.data = data(args),				\
+		.data = g_memdup(data(args), sizeof(data(args))), \
 		.size = sizeof(data(args)),			\
 	}
 
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index d8d007386..4a655b28f 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -86,7 +86,7 @@ struct context {
 #define raw_pdu(args...)					\
 	{							\
 		.valid = true,					\
-		.data = data(args),				\
+		.data = g_memdup(data(args), sizeof(data(args))), \
 		.size = sizeof(data(args)),			\
 	}
 
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index f2b9622c2..baf9e93c6 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -63,7 +63,7 @@ struct test_data {
 #define raw_pdu(args...)					\
 	{							\
 		.valid = true,					\
-		.data = data(args),				\
+		.data = g_memdup(data(args), sizeof(data(args))), \
 		.size = sizeof(data(args)),			\
 	}
 
diff --git a/unit/test-hog.c b/unit/test-hog.c
index 37d3abe3f..e257fbd88 100644
--- a/unit/test-hog.c
+++ b/unit/test-hog.c
@@ -69,11 +69,11 @@ struct context {
 
 #define data(args...) ((const unsigned char[]) { args })
 
-#define raw_pdu(args...)    \
-{      \
-	.valid = true,		\
-	.data = data(args), \
-	.size = sizeof(data(args)),\
+#define raw_pdu(args...)					\
+{								\
+	.valid = true,						\
+	.data = g_memdup(data(args), sizeof(data(args))),	\
+	.size = sizeof(data(args)),				\
 }
 
 #define false_pdu()	\
diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 66da038cd..03501d021 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -60,14 +60,14 @@ struct test_data {
 #define raw_pdu(args...) \
 	{							\
 		.valid = true,					\
-		.raw_data = raw_data(args),			\
+		.raw_data = g_memdup(raw_data(args), sizeof(raw_data(args))), \
 		.raw_size = sizeof(raw_data(args)),		\
 	}
 
 #define raw_pdu_cont(cont, args...) \
 	{							\
 		.valid = true,					\
-		.raw_data = raw_data(args),			\
+		.raw_data = g_memdup(raw_data(args), sizeof(raw_data(args))), \
 		.raw_size = sizeof(raw_data(args)),		\
 		.cont_len = cont,				\
 	}
@@ -105,7 +105,7 @@ struct test_data_de {
 #define define_test_de_attr(name, input, exp) \
 	do {								\
 		static struct test_data_de data;			\
-		data.input_data = input;				\
+		data.input_data = g_memdup(input, sizeof(input));	\
 		data.input_size = sizeof(input);			\
 		data.expected = exp;					\
 		tester_add("/sdp/DE/ATTR/" name, &data,	NULL,		\
-- 
2.17.2


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 14:18 [PATCH BlueZ 1/2] unit/test-sdp: Avoid extra copies when sending a PDU Luiz Augusto von Dentz
2019-01-11 14:18 ` [PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9 Luiz Augusto von Dentz

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox