linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9
Date: Fri, 11 Jan 2019 11:18:17 -0300	[thread overview]
Message-ID: <20190111141817.25077-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20190111141817.25077-1-luiz.dentz@gmail.com>

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


      reply	other threads:[~2019-01-11 14:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=20190111141817.25077-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.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;
as well as URLs for NNTP newsgroup(s).