[PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux