mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-16 00:34:39 +08:00
unit: Fix fsanitize-address-use-after-scope with GCC 9
Raw data payload must be copied since the declaration goes out of scope: Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=202213
This commit is contained in:
parent
fa69d51084
commit
0be5246170
@ -43,7 +43,7 @@
|
||||
|
||||
struct test_pdu {
|
||||
bool valid;
|
||||
const uint8_t *data;
|
||||
uint8_t *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
@ -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)), \
|
||||
}
|
||||
|
||||
@ -84,6 +84,11 @@ struct context {
|
||||
static void test_free(gconstpointer user_data)
|
||||
{
|
||||
const struct test_data *data = user_data;
|
||||
struct test_pdu *pdu;
|
||||
int i;
|
||||
|
||||
for (i = 0; (pdu = &data->pdu_list[i]) && pdu->valid; i++)
|
||||
g_free(pdu->data);
|
||||
|
||||
g_free(data->test_name);
|
||||
g_free(data->pdu_list);
|
||||
|
@ -47,7 +47,7 @@
|
||||
struct test_pdu {
|
||||
bool valid;
|
||||
bool fragmented;
|
||||
const uint8_t *data;
|
||||
uint8_t *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
@ -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)), \
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ struct test_data {
|
||||
{ \
|
||||
.valid = true, \
|
||||
.fragmented = true, \
|
||||
.data = data(args), \
|
||||
.data = g_memdup(data(args), sizeof(data(args))), \
|
||||
.size = sizeof(data(args)), \
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ struct test_data {
|
||||
static struct test_data data; \
|
||||
data.test_name = g_strdup(name); \
|
||||
data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
|
||||
tester_add(name, &data, NULL, function, NULL); \
|
||||
tester_add(name, &data, NULL, function, NULL); \
|
||||
} while (0)
|
||||
|
||||
struct context {
|
||||
@ -102,6 +102,11 @@ struct context {
|
||||
static void test_free(gconstpointer user_data)
|
||||
{
|
||||
const struct test_data *data = user_data;
|
||||
struct test_pdu *pdu;
|
||||
int i;
|
||||
|
||||
for (i = 0; (pdu = &data->pdu_list[i]) && pdu->valid; i++)
|
||||
g_free(pdu->data);
|
||||
|
||||
g_free(data->test_name);
|
||||
g_free(data->pdu_list);
|
||||
|
@ -49,7 +49,7 @@ struct test_pdu {
|
||||
bool fragmented;
|
||||
bool continuing;
|
||||
bool browse;
|
||||
const uint8_t *data;
|
||||
uint8_t *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
@ -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)), \
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ struct context {
|
||||
{ \
|
||||
.valid = true, \
|
||||
.browse = true, \
|
||||
.data = data(args), \
|
||||
.data = g_memdup(data(args), sizeof(data(args))), \
|
||||
.size = sizeof(data(args)), \
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ struct context {
|
||||
{ \
|
||||
.valid = true, \
|
||||
.fragmented = true, \
|
||||
.data = data(args), \
|
||||
.data = g_memdup(data(args), sizeof(data(args))), \
|
||||
.size = sizeof(data(args)), \
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ struct context {
|
||||
{ \
|
||||
.valid = true, \
|
||||
.continuing = true, \
|
||||
.data = data(args), \
|
||||
.data = g_memdup(data(args), sizeof(data(args))), \
|
||||
.size = sizeof(data(args)), \
|
||||
}
|
||||
|
||||
@ -116,6 +116,11 @@ struct context {
|
||||
static void test_free(gconstpointer user_data)
|
||||
{
|
||||
const struct test_data *data = user_data;
|
||||
struct test_pdu *pdu;
|
||||
int i;
|
||||
|
||||
for (i = 0; (pdu = &data->pdu_list[i]) && pdu->valid; i++)
|
||||
g_free(pdu->data);
|
||||
|
||||
g_free(data->test_name);
|
||||
g_free(data->pdu_list);
|
||||
|
@ -48,7 +48,7 @@
|
||||
|
||||
struct test_pdu {
|
||||
bool valid;
|
||||
const uint8_t *data;
|
||||
uint8_t *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
@ -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)), \
|
||||
}
|
||||
|
||||
@ -306,6 +306,11 @@ static bt_uuid_t uuid_char_128 = {
|
||||
static void test_free(gconstpointer user_data)
|
||||
{
|
||||
const struct test_data *data = user_data;
|
||||
struct test_pdu *pdu;
|
||||
int i;
|
||||
|
||||
for (i = 0; (pdu = &data->pdu_list[i]) && pdu->valid; i++)
|
||||
g_free(pdu->data);
|
||||
|
||||
g_free(data->test_name);
|
||||
g_free(data->pdu_list);
|
||||
@ -1911,6 +1916,8 @@ static void test_server(gconstpointer data)
|
||||
g_assert_cmpint(len, ==, pdu.size);
|
||||
|
||||
tester_monitor('<', 0x0004, 0x0000, pdu.data, len);
|
||||
|
||||
g_free(pdu.data);
|
||||
}
|
||||
|
||||
static void test_search_primary(gconstpointer data)
|
||||
|
@ -43,7 +43,7 @@ struct context {
|
||||
|
||||
struct test_pdu {
|
||||
bool valid;
|
||||
const uint8_t *data;
|
||||
uint8_t *data;
|
||||
size_t size;
|
||||
enum hfp_gw_cmd_type type;
|
||||
bool fragmented;
|
||||
@ -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)), \
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ struct test_data {
|
||||
#define type_pdu(cmd_type, args...) \
|
||||
{ \
|
||||
.valid = true, \
|
||||
.data = data(args), \
|
||||
.data = g_memdup(data(args), sizeof(data(args))), \
|
||||
.size = sizeof(data(args)), \
|
||||
.type = cmd_type, \
|
||||
}
|
||||
@ -83,7 +83,7 @@ struct test_data {
|
||||
#define frg_pdu(args...) \
|
||||
{ \
|
||||
.valid = true, \
|
||||
.data = data(args), \
|
||||
.data = g_memdup(data(args), sizeof(data(args))), \
|
||||
.size = sizeof(data(args)), \
|
||||
.fragmented = true, \
|
||||
}
|
||||
@ -119,6 +119,11 @@ struct test_data {
|
||||
static void test_free(gconstpointer user_data)
|
||||
{
|
||||
const struct test_data *data = user_data;
|
||||
struct test_pdu *pdu;
|
||||
int i;
|
||||
|
||||
for (i = 0; (pdu = &data->pdu_list[i]) && pdu->valid; i++)
|
||||
g_free(pdu->data);
|
||||
|
||||
g_free(data->test_name);
|
||||
g_free(data->pdu_list);
|
||||
|
@ -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() \
|
||||
|
@ -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, \
|
||||
|
Loading…
Reference in New Issue
Block a user