bluez/0002-Use-g_memdup2-everywhere.patch

998 lines
35 KiB
Diff
Raw Normal View History

2021-05-18 09:40:00 +00:00
From 393a58bbe5174123ee9d52c03a75b08219642024 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Mon, 3 May 2021 15:06:36 +0200
Subject: [PATCH] Use g_memdup2 everywhere
---
android/a2dp.c | 8 ++---
android/avctp.c | 4 +--
android/avrcp-lib.c | 2 +-
android/gatt.c | 4 +--
android/hidhost.c | 2 +-
android/tester-main.c | 70 +++++++++++++++++++-------------------
attrib/gatt.c | 6 ++--
client/gatt.c | 2 +-
gobex/gobex-header.c | 4 +--
gobex/gobex-packet.c | 2 +-
obexd/src/obex.c | 2 +-
plugins/neard.c | 6 ++--
plugins/policy.c | 4 +--
profiles/audio/avctp.c | 4 +--
profiles/audio/avrcp.c | 6 ++--
profiles/battery/bas.c | 2 +-
profiles/battery/battery.c | 2 +-
profiles/deviceinfo/dis.c | 2 +-
profiles/input/hog-lib.c | 6 ++--
profiles/scanparam/scpp.c | 2 +-
src/attrib-server.c | 2 +-
src/eir.c | 4 +--
tools/gatt-service.c | 6 ++--
tools/mesh-gatt/gatt.c | 2 +-
unit/test-avctp.c | 4 +--
unit/test-avdtp.c | 6 ++--
unit/test-avrcp.c | 10 +++---
unit/test-gatt.c | 4 +--
unit/test-hfp.c | 10 +++---
unit/test-hog.c | 4 +--
unit/test-sdp.c | 8 ++---
unit/test-uhid.c | 2 +-
32 files changed, 101 insertions(+), 101 deletions(-)
diff --git a/android/a2dp.c b/android/a2dp.c
index e24f793..1d9538a 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -428,7 +428,7 @@ static struct a2dp_preset *sbc_select_range(void *caps, uint8_t caps_len,
p = g_new0(struct a2dp_preset, 1);
p->len = conf_len;
- p->data = g_memdup(conf, p->len);
+ p->data = g_memdup2(conf, p->len);
return p;
}
@@ -448,7 +448,7 @@ static struct a2dp_preset *aac_select_range(void *caps, uint8_t caps_len,
p = g_new0(struct a2dp_preset, 1);
p->len = conf_len;
- p->data = g_memdup(conf, p->len);
+ p->data = g_memdup2(conf, p->len);
return p;
}
@@ -1036,7 +1036,7 @@ static gboolean sep_setconf_ind(struct avdtp *session,
preset = g_new0(struct a2dp_preset, 1);
preset->len = cap->length - sizeof(*codec);
- preset->data = g_memdup(codec->data, preset->len);
+ preset->data = g_memdup2(codec->data, preset->len);
if (check_config(endpoint, preset) < 0) {
preset_free(preset);
@@ -1365,7 +1365,7 @@ static GSList *parse_presets(const struct audio_preset *p, uint8_t count,
preset = g_new0(struct a2dp_preset, 1);
preset->len = p->len;
- preset->data = g_memdup(p->data, preset->len);
+ preset->data = g_memdup2(p->data, preset->len);
l = g_slist_append(l, preset);
len -= preset->len;
diff --git a/android/avctp.c b/android/avctp.c
index c2ea5f4..d1b8fe3 100644
--- a/android/avctp.c
+++ b/android/avctp.c
@@ -1179,7 +1179,7 @@ static int avctp_send_req(struct avctp *session, uint8_t code, uint8_t subunit,
for (i = 0; i < iov_cnt; i++) {
pdu[i].iov_len = iov[i].iov_len;
- pdu[i].iov_base = g_memdup(iov[i].iov_base, iov[i].iov_len);
+ pdu[i].iov_base = g_memdup2(iov[i].iov_base, iov[i].iov_len);
}
req = g_new0(struct avctp_control_req, 1);
@@ -1220,7 +1220,7 @@ int avctp_send_browsing_req(struct avctp *session,
for (i = 0; i < iov_cnt; i++) {
pdu[i].iov_len = iov[i].iov_len;
- pdu[i].iov_base = g_memdup(iov[i].iov_base, iov[i].iov_len);
+ pdu[i].iov_base = g_memdup2(iov[i].iov_base, iov[i].iov_len);
}
req = g_new0(struct avctp_browsing_req, 1);
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 2007d09..ededdcf 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -2620,7 +2620,7 @@ static char *parse_folder_list(uint8_t *params, uint16_t params_len,
return NULL;
}
- folders[count] = g_memdup(&params[i], len);
+ folders[count] = g_memdup2(&params[i], len);
i += len;
}
diff --git a/android/gatt.c b/android/gatt.c
index a8a0c48..6e8c431 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1338,7 +1338,7 @@ static void discover_primary_cb(uint8_t status, GSList *services,
}
bt_uuid_to_uuid128(&uuid, &u128);
- new_uuid = g_memdup(&u128.value.u128, sizeof(u128.value.u128));
+ new_uuid = g_memdup2(&u128.value.u128, sizeof(u128.value.u128));
uuids = g_slist_prepend(uuids, new_uuid);
}
@@ -6633,7 +6633,7 @@ static uint8_t write_prep_request(const uint8_t *cmd, uint16_t cmd_len,
queue_push_tail(dev->pending_requests, data);
- data->value = g_memdup(value, vlen);
+ data->value = g_memdup2(value, vlen);
data->length = vlen;
if (!gatt_db_attribute_write(attrib, offset, value, vlen, cmd[0],
diff --git a/android/hidhost.c b/android/hidhost.c
index 016382e..6f0ec85 100644
--- a/android/hidhost.c
+++ b/android/hidhost.c
@@ -689,7 +689,7 @@ static void hid_sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
goto fail;
dev->rd_size = data->unitSize;
- dev->rd_data = g_memdup(data->val.str, data->unitSize);
+ dev->rd_data = g_memdup2(data->val.str, data->unitSize);
}
}
diff --git a/android/tester-main.c b/android/tester-main.c
index 2bfa770..c09bc0a 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -1253,7 +1253,7 @@ static bt_property_t *copy_properties(int num_properties,
for (i = 0; i < num_properties; i++) {
props[i].type = properties[i].type;
props[i].len = properties[i].len;
- props[i].val = g_memdup(properties[i].val, properties[i].len);
+ props[i].val = g_memdup2(properties[i].val, properties[i].len);
}
return props;
@@ -1268,7 +1268,7 @@ static bt_property_t *repack_properties(int num_properties,
for (i = 0; i < num_properties; i++) {
props[i].type = properties[i]->type;
props[i].len = properties[i]->len;
- props[i].val = g_memdup(properties[i]->val, properties[i]->len);
+ props[i].val = g_memdup2(properties[i]->val, properties[i]->len);
}
return props;
@@ -1281,7 +1281,7 @@ static bt_property_t *create_property(bt_property_type_t type, void *val,
prop->type = type;
prop->len = len;
- prop->val = g_memdup(val, len);
+ prop->val = g_memdup2(val, len);
return prop;
}
@@ -1615,7 +1615,7 @@ static void gattc_search_result_cb(int conn_id, btgatt_srvc_id_t *srvc_id)
step->callback = CB_GATTC_SEARCH_RESULT;
step->callback_result.conn_id = conn_id;
- step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
+ step->callback_result.service = g_memdup2(srvc_id, sizeof(*srvc_id));
schedule_callback_verification(step);
}
@@ -1639,8 +1639,8 @@ static void gattc_get_characteristic_cb(int conn_id, int status,
step->callback = CB_GATTC_GET_CHARACTERISTIC;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
- step->callback_result.characteristic = g_memdup(char_id,
+ step->callback_result.service = g_memdup2(srvc_id, sizeof(*srvc_id));
+ step->callback_result.characteristic = g_memdup2(char_id,
sizeof(*char_id));
step->callback_result.char_prop = char_prop;
@@ -1656,10 +1656,10 @@ static void gattc_get_descriptor_cb(int conn_id, int status,
step->callback = CB_GATTC_GET_DESCRIPTOR;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
- step->callback_result.characteristic = g_memdup(char_id,
+ step->callback_result.service = g_memdup2(srvc_id, sizeof(*srvc_id));
+ step->callback_result.characteristic = g_memdup2(char_id,
sizeof(*char_id));
- step->callback_result.descriptor = g_memdup(descr_id,
+ step->callback_result.descriptor = g_memdup2(descr_id,
sizeof(*descr_id));
schedule_callback_verification(step);
@@ -1673,8 +1673,8 @@ static void gattc_get_included_service_cb(int conn_id, int status,
step->callback = CB_GATTC_GET_INCLUDED_SERVICE;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
- step->callback_result.included = g_memdup(incl_srvc_id,
+ step->callback_result.service = g_memdup2(srvc_id, sizeof(*srvc_id));
+ step->callback_result.included = g_memdup2(incl_srvc_id,
sizeof(*srvc_id));
schedule_callback_verification(step);
@@ -1688,7 +1688,7 @@ static void gattc_read_characteristic_cb(int conn_id, int status,
step->callback = CB_GATTC_READ_CHARACTERISTIC;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.read_params = g_memdup(p_data, sizeof(*p_data));
+ step->callback_result.read_params = g_memdup2(p_data, sizeof(*p_data));
schedule_callback_verification(step);
}
@@ -1701,7 +1701,7 @@ static void gattc_read_descriptor_cb(int conn_id, int status,
step->callback = CB_GATTC_READ_DESCRIPTOR;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.read_params = g_memdup(p_data, sizeof(*p_data));
+ step->callback_result.read_params = g_memdup2(p_data, sizeof(*p_data));
schedule_callback_verification(step);
}
@@ -1714,7 +1714,7 @@ static void gattc_write_characteristic_cb(int conn_id, int status,
step->callback = CB_GATTC_WRITE_CHARACTERISTIC;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.write_params = g_memdup(p_data, sizeof(*p_data));
+ step->callback_result.write_params = g_memdup2(p_data, sizeof(*p_data));
schedule_callback_verification(step);
}
@@ -1727,7 +1727,7 @@ static void gattc_write_descriptor_cb(int conn_id, int status,
step->callback = CB_GATTC_WRITE_DESCRIPTOR;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.write_params = g_memdup(p_data, sizeof(*p_data));
+ step->callback_result.write_params = g_memdup2(p_data, sizeof(*p_data));
schedule_callback_verification(step);
}
@@ -1742,8 +1742,8 @@ static void gattc_register_for_notification_cb(int conn_id, int registered,
step->callback = CB_GATTC_REGISTER_FOR_NOTIFICATION;
step->callback_result.status = status;
step->callback_result.conn_id = conn_id;
- step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
- step->callback_result.characteristic = g_memdup(char_id,
+ step->callback_result.service = g_memdup2(srvc_id, sizeof(*srvc_id));
+ step->callback_result.characteristic = g_memdup2(char_id,
sizeof(*char_id));
step->callback_result.notification_registered = registered;
@@ -1756,7 +1756,7 @@ static void gattc_notif_cb(int conn_id, btgatt_notify_params_t *p_data)
step->callback = CB_GATTC_NOTIFY;
step->callback_result.conn_id = conn_id;
- step->callback_result.notify_params = g_memdup(p_data, sizeof(*p_data));
+ step->callback_result.notify_params = g_memdup2(p_data, sizeof(*p_data));
schedule_callback_verification(step);
}
@@ -1827,8 +1827,8 @@ static void gatts_service_added_cb(int status, int server_if,
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.service = g_memdup(srvc_id, sizeof(*srvc_id));
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.service = g_memdup2(srvc_id, sizeof(*srvc_id));
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
schedule_callback_verification(step);
@@ -1844,9 +1844,9 @@ static void gatts_included_service_added_cb(int status, int server_if,
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
- step->callback_result.inc_srvc_handle = g_memdup(&inc_srvc_handle,
+ step->callback_result.inc_srvc_handle = g_memdup2(&inc_srvc_handle,
sizeof(inc_srvc_handle));
schedule_callback_verification(step);
@@ -1863,10 +1863,10 @@ static void gatts_characteristic_added_cb(int status, int server_if,
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
- step->callback_result.uuid = g_memdup(uuid, sizeof(*uuid));
- step->callback_result.char_handle = g_memdup(&char_handle,
+ step->callback_result.uuid = g_memdup2(uuid, sizeof(*uuid));
+ step->callback_result.char_handle = g_memdup2(&char_handle,
sizeof(char_handle));
schedule_callback_verification(step);
@@ -1883,10 +1883,10 @@ static void gatts_descriptor_added_cb(int status, int server_if,
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
- step->callback_result.uuid = g_memdup(uuid, sizeof(*uuid));
- step->callback_result.desc_handle = g_memdup(&desc_handle,
+ step->callback_result.uuid = g_memdup2(uuid, sizeof(*uuid));
+ step->callback_result.desc_handle = g_memdup2(&desc_handle,
sizeof(desc_handle));
schedule_callback_verification(step);
@@ -1900,7 +1900,7 @@ static void gatts_service_started_cb(int status, int server_if, int srvc_handle)
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
schedule_callback_verification(step);
@@ -1914,7 +1914,7 @@ static void gatts_service_stopped_cb(int status, int server_if, int srvc_handle)
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
schedule_callback_verification(step);
@@ -1928,7 +1928,7 @@ static void gatts_service_deleted_cb(int status, int server_if, int srvc_handle)
step->callback_result.status = status;
step->callback_result.gatt_app_id = server_if;
- step->callback_result.srvc_handle = g_memdup(&srvc_handle,
+ step->callback_result.srvc_handle = g_memdup2(&srvc_handle,
sizeof(srvc_handle));
schedule_callback_verification(step);
@@ -1945,7 +1945,7 @@ static void gatts_request_read_cb(int conn_id, int trans_id, bt_bdaddr_t *bda,
step->callback_result.conn_id = conn_id;
step->callback_result.trans_id = trans_id;
- step->callback_result.attr_handle = g_memdup(&attr_handle,
+ step->callback_result.attr_handle = g_memdup2(&attr_handle,
sizeof(attr_handle));
step->callback_result.offset = offset;
step->callback_result.is_long = is_long;
@@ -1974,13 +1974,13 @@ static void gatts_request_write_cb(int conn_id, int trans_id, bt_bdaddr_t *bda,
step->callback_result.conn_id = conn_id;
step->callback_result.trans_id = trans_id;
- step->callback_result.attr_handle = g_memdup(&attr_handle,
+ step->callback_result.attr_handle = g_memdup2(&attr_handle,
sizeof(attr_handle));
step->callback_result.offset = offset;
step->callback_result.length = length;
step->callback_result.need_rsp = need_rsp;
step->callback_result.is_prep = is_prep;
- step->callback_result.value = g_memdup(&value, length);
+ step->callback_result.value = g_memdup2(&value, length);
/* Utilize property verification mechanism for bdaddr */
props[0] = create_property(BT_PROPERTY_BDADDR, bda, sizeof(*bda));
@@ -2169,7 +2169,7 @@ static btmce_mas_instance_t *copy_mas_instances(int num_instances,
inst[i].id = instances[i].id;
inst[i].scn = instances[i].scn;
inst[i].msg_types = instances[i].msg_types;
- inst[i].p_name = g_memdup(instances[i].p_name,
+ inst[i].p_name = g_memdup2(instances[i].p_name,
strlen(instances[i].p_name));
}
diff --git a/attrib/gatt.c b/attrib/gatt.c
index 46b2ca3..1f30764 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -696,7 +696,7 @@ guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
dc->user_data = user_data;
dc->end = end;
dc->start = start;
- dc->uuid = g_memdup(uuid, sizeof(bt_uuid_t));
+ dc->uuid = g_memdup2(uuid, sizeof(bt_uuid_t));
dc->id = g_attrib_send(attrib, 0, buf, plen, char_discovered_cb,
discover_char_ref(dc), discover_char_unref);
@@ -964,7 +964,7 @@ guint gatt_write_char(GAttrib *attrib, uint16_t handle, const uint8_t *value,
long_write->func = func;
long_write->user_data = user_data;
long_write->handle = handle;
- long_write->value = g_memdup(value, vlen);
+ long_write->value = g_memdup2(value, vlen);
long_write->vlen = vlen;
return prepare_write(long_write);
@@ -1130,7 +1130,7 @@ guint gatt_discover_desc(GAttrib *attrib, uint16_t start, uint16_t end,
dd->user_data = user_data;
dd->start = start;
dd->end = end;
- dd->uuid = g_memdup(uuid, sizeof(bt_uuid_t));
+ dd->uuid = g_memdup2(uuid, sizeof(bt_uuid_t));
dd->id = g_attrib_send(attrib, 0, buf, plen, desc_discovered_cb,
discover_desc_ref(dd), discover_desc_unref);
diff --git a/client/gatt.c b/client/gatt.c
index 21fd38e..d302183 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -790,7 +790,7 @@ static uint8_t *str2bytearray(char *arg, size_t *val_len)
*val_len = i;
- return g_memdup(value, i);
+ return g_memdup2(value, i);
}
void gatt_write_attribute(GDBusProxy *proxy, int argc, char *argv[])
diff --git a/gobex/gobex-header.c b/gobex/gobex-header.c
index 011d33d..c56be2f 100644
--- a/gobex/gobex-header.c
+++ b/gobex/gobex-header.c
@@ -222,7 +222,7 @@ GObexHeader *g_obex_header_decode(const void *data, gsize len,
switch (data_policy) {
case G_OBEX_DATA_COPY:
- header->v.data = g_memdup(ptr, header->vlen);
+ header->v.data = g_memdup2(ptr, header->vlen);
break;
case G_OBEX_DATA_REF:
header->extdata = TRUE;
@@ -410,7 +410,7 @@ GObexHeader *g_obex_header_new_bytes(guint8 id, const void *data, gsize len)
header->id = id;
header->vlen = len;
header->hlen = len + 3;
- header->v.data = g_memdup(data, len);
+ header->v.data = g_memdup2(data, len);
return header;
}
diff --git a/gobex/gobex-packet.c b/gobex/gobex-packet.c
index 11937a5..18da6ea 100644
--- a/gobex/gobex-packet.c
+++ b/gobex/gobex-packet.c
@@ -201,7 +201,7 @@ gboolean g_obex_packet_set_data(GObexPacket *pkt, const void *data, gsize len,
switch (data_policy) {
case G_OBEX_DATA_COPY:
- pkt->data.buf = g_memdup(data, len);
+ pkt->data.buf = g_memdup2(data, len);
break;
case G_OBEX_DATA_REF:
pkt->data.buf_ref = data;
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 9f992ec..151d956 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -594,7 +594,7 @@ static void parse_apparam(struct obex_session *os, GObexPacket *req)
if (!g_obex_header_get_bytes(hdr, &apparam, &len))
return;
- os->apparam = g_memdup(apparam, len);
+ os->apparam = g_memdup2(apparam, len);
os->apparam_len = len;
DBG("APPARAM");
}
diff --git a/plugins/neard.c b/plugins/neard.c
index e07b511..a806bb7 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -407,10 +407,10 @@ static int process_nokia_long (void *data, size_t size, uint8_t marker,
remote->name = g_strndup((char *)n->name, n->name_len);
if (marker == 0x01) {
- remote->pin = g_memdup(n->authentication, 4);
+ remote->pin = g_memdup2(n->authentication, 4);
remote->pin_len = 4;
} else if (marker == 0x02) {
- remote->pin = g_memdup(n->authentication, 16);
+ remote->pin = g_memdup2(n->authentication, 16);
remote->pin_len = 16;
}
@@ -439,7 +439,7 @@ static int process_nokia_short (void *data, size_t size,
if (n->name_len > 0)
remote->name = g_strndup((char *)n->name, n->name_len);
- remote->pin = g_memdup(n->authentication, 4);
+ remote->pin = g_memdup2(n->authentication, 4);
remote->pin_len = 4;
return 0;
diff --git a/plugins/policy.c b/plugins/policy.c
index bf93df0..79943fc 100644
--- a/plugins/policy.c
+++ b/plugins/policy.c
@@ -855,7 +855,7 @@ static int policy_init(void)
reconnect_attempts = default_attempts;
reconnect_intervals_len = sizeof(default_intervals) /
sizeof(*reconnect_intervals);
- reconnect_intervals = g_memdup(default_intervals,
+ reconnect_intervals = g_memdup2(default_intervals,
sizeof(default_intervals));
goto done;
}
@@ -886,7 +886,7 @@ static int policy_init(void)
g_clear_error(&gerr);
reconnect_intervals_len = sizeof(default_intervals) /
sizeof(*reconnect_intervals);
- reconnect_intervals = g_memdup(default_intervals,
+ reconnect_intervals = g_memdup2(default_intervals,
sizeof(default_intervals));
}
diff --git a/profiles/audio/avctp.c b/profiles/audio/avctp.c
index 50de336..2733a76 100644
--- a/profiles/audio/avctp.c
+++ b/profiles/audio/avctp.c
@@ -1731,7 +1731,7 @@ static int avctp_send_req(struct avctp *session, uint8_t code,
req->subunit = subunit;
req->op = opcode;
req->func = func;
- req->operands = g_memdup(operands, operand_count);
+ req->operands = g_memdup2(operands, operand_count);
req->operand_count = operand_count;
req->user_data = user_data;
@@ -1769,7 +1769,7 @@ int avctp_send_browsing_req(struct avctp *session,
req = g_new0(struct avctp_browsing_req, 1);
req->func = func;
- req->operands = g_memdup(operands, operand_count);
+ req->operands = g_memdup2(operands, operand_count);
req->operand_count = operand_count;
req->user_data = user_data;
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 05dd791..e23228d 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1297,7 +1297,7 @@ static uint8_t avrcp_handle_get_current_player_value(struct avrcp *session,
* Save a copy of requested settings because we can override them
* while responding
*/
- settings = g_memdup(&pdu->params[1], pdu->params[0]);
+ settings = g_memdup2(&pdu->params[1], pdu->params[0]);
len = 0;
/*
@@ -2786,7 +2786,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
break;
}
- folders[count] = g_memdup(&pdu->params[i], len);
+ folders[count] = g_memdup2(&pdu->params[i], len);
i += len;
}
@@ -2873,7 +2873,7 @@ static void avrcp_player_parse_features(struct avrcp_player *player,
{
struct media_player *mp = player->user_data;
- player->features = g_memdup(features, 16);
+ player->features = g_memdup2(features, 16);
if (features[7] & 0x08) {
media_player_set_browsable(mp, true);
diff --git a/profiles/battery/bas.c b/profiles/battery/bas.c
index 3c6173b..b223fbe 100644
--- a/profiles/battery/bas.c
+++ b/profiles/battery/bas.c
@@ -75,7 +75,7 @@ struct bt_bas *bt_bas_new(void *primary)
bas->gatt_op = queue_new();
if (primary)
- bas->primary = g_memdup(primary, sizeof(*bas->primary));
+ bas->primary = g_memdup2(primary, sizeof(*bas->primary));
return bt_bas_ref(bas);
}
diff --git a/profiles/battery/battery.c b/profiles/battery/battery.c
index 176d127..3b5aa5c 100644
--- a/profiles/battery/battery.c
+++ b/profiles/battery/battery.c
@@ -159,7 +159,7 @@ static void read_initial_battery_level_cb(bool success,
if (!length)
return;
- batt->initial_value = g_memdup(value, length);
+ batt->initial_value = g_memdup2(value, length);
/* request notify */
batt->batt_level_cb_id =
diff --git a/profiles/deviceinfo/dis.c b/profiles/deviceinfo/dis.c
index 87fa633..79d98c3 100644
--- a/profiles/deviceinfo/dis.c
+++ b/profiles/deviceinfo/dis.c
@@ -143,7 +143,7 @@ struct bt_dis *bt_dis_new_primary(void *primary)
dis->gatt_op = queue_new();
if (primary)
- dis->primary = g_memdup(primary, sizeof(*dis->primary));
+ dis->primary = g_memdup2(primary, sizeof(*dis->primary));
return bt_dis_ref(dis);
}
diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c
index e5e3d3e..3652bdf 100644
--- a/profiles/input/hog-lib.c
+++ b/profiles/input/hog-lib.c
@@ -514,7 +514,7 @@ static void report_read_cb(guint8 status, const guint8 *pdu, guint16 len,
if (report->value)
g_free(report->value);
- report->value = g_memdup(pdu, len);
+ report->value = g_memdup2(pdu, len);
report->len = len;
}
@@ -1595,7 +1595,7 @@ static void hog_attach_hog(struct bt_hog *hog, struct gatt_primary *primary)
struct bt_hog *instance;
if (!hog->primary) {
- hog->primary = g_memdup(primary, sizeof(*primary));
+ hog->primary = g_memdup2(primary, sizeof(*primary));
discover_char(hog, hog->attrib, primary->range.start,
primary->range.end, NULL,
char_discovered_cb, hog);
@@ -1609,7 +1609,7 @@ static void hog_attach_hog(struct bt_hog *hog, struct gatt_primary *primary)
if (!instance)
return;
- instance->primary = g_memdup(primary, sizeof(*primary));
+ instance->primary = g_memdup2(primary, sizeof(*primary));
find_included(instance, hog->attrib, primary->range.start,
primary->range.end, find_included_cb, instance);
diff --git a/profiles/scanparam/scpp.c b/profiles/scanparam/scpp.c
index da38a6a..1134360 100644
--- a/profiles/scanparam/scpp.c
+++ b/profiles/scanparam/scpp.c
@@ -110,7 +110,7 @@ struct bt_scpp *bt_scpp_new(void *primary)
scan->gatt_op = queue_new();
if (primary)
- scan->primary = g_memdup(primary, sizeof(*scan->primary));
+ scan->primary = g_memdup2(primary, sizeof(*scan->primary));
return bt_scpp_ref(scan);
}
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 5a178f9..ce412c3 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -339,7 +339,7 @@ static struct attribute *attrib_db_add_new(struct gatt_server *server,
a = g_new0(struct attribute, 1);
a->len = len;
- a->data = g_memdup(value, len);
+ a->data = g_memdup2(value, len);
a->handle = handle;
a->uuid = *uuid;
a->read_req = read_req;
diff --git a/src/eir.c b/src/eir.c
index 0f5d14f..ceeb5f7 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -323,13 +323,13 @@ void eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
case EIR_SSP_HASH:
if (data_len < 16)
break;
- eir->hash = g_memdup(data, 16);
+ eir->hash = g_memdup2(data, 16);
break;
case EIR_SSP_RANDOMIZER:
if (data_len < 16)
break;
- eir->randomizer = g_memdup(data, 16);
+ eir->randomizer = g_memdup2(data, 16);
break;
case EIR_DEVICE_ID:
diff --git a/tools/gatt-service.c b/tools/gatt-service.c
index 631c4f2..1e272a5 100644
--- a/tools/gatt-service.c
+++ b/tools/gatt-service.c
@@ -127,7 +127,7 @@ static gboolean desc_get_value(const GDBusPropertyTable *property,
static void desc_write(struct descriptor *desc, const uint8_t *value, int len)
{
g_free(desc->value);
- desc->value = g_memdup(value, len);
+ desc->value = g_memdup2(value, len);
desc->vlen = len;
g_dbus_emit_property_changed(connection, desc->path,
@@ -265,7 +265,7 @@ static gboolean chr_get_props(const GDBusPropertyTable *property,
static void chr_write(struct characteristic *chr, const uint8_t *value, int len)
{
g_free(chr->value);
- chr->value = g_memdup(value, len);
+ chr->value = g_memdup2(value, len);
chr->vlen = len;
g_dbus_emit_property_changed(connection, chr->path, GATT_CHR_IFACE,
@@ -592,7 +592,7 @@ static gboolean register_characteristic(const char *chr_uuid,
chr = g_new0(struct characteristic, 1);
chr->uuid = g_strdup(chr_uuid);
- chr->value = g_memdup(value, vlen);
+ chr->value = g_memdup2(value, vlen);
chr->vlen = vlen;
chr->props = props;
chr->service = g_strdup(service_path);
diff --git a/tools/mesh-gatt/gatt.c b/tools/mesh-gatt/gatt.c
index b99234f..d7685f0 100644
--- a/tools/mesh-gatt/gatt.c
+++ b/tools/mesh-gatt/gatt.c
@@ -338,7 +338,7 @@ bool mesh_gatt_write(GDBusProxy *proxy, uint8_t *buf, uint16_t len,
/* TODO: should keep in queue in case we need to cancel write? */
data->gatt_len = len;
- data->gatt_data = g_memdup(buf, len);
+ data->gatt_data = g_memdup2(buf, len);
data->gatt_data[0] &= GATT_TYPE_MASK;
data->iov.iov_base = data->gatt_data;
data->iov.iov_len = len;
diff --git a/unit/test-avctp.c b/unit/test-avctp.c
index fa7db59..0bd138e 100644
--- a/unit/test-avctp.c
+++ b/unit/test-avctp.c
@@ -53,7 +53,7 @@ struct context {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -64,7 +64,7 @@ struct context {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, function, NULL); \
} while (0)
diff --git a/unit/test-avdtp.c b/unit/test-avdtp.c
index f5340d6..d6fdd3d 100644
--- a/unit/test-avdtp.c
+++ b/unit/test-avdtp.c
@@ -48,7 +48,7 @@ struct test_data {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -56,7 +56,7 @@ struct test_data {
{ \
.valid = true, \
.fragmented = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -67,7 +67,7 @@ struct test_data {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, function, NULL); \
} while (0)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 34a7037..0c860e3 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -61,7 +61,7 @@ struct context {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -69,7 +69,7 @@ struct context {
{ \
.valid = true, \
.browse = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -77,7 +77,7 @@ struct context {
{ \
.valid = true, \
.fragmented = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -85,7 +85,7 @@ struct context {
{ \
.valid = true, \
.continuing = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -96,7 +96,7 @@ struct context {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, function, NULL); \
} while (0)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 4aa87d0..ab16818 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -73,7 +73,7 @@ struct context {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -94,7 +94,7 @@ struct context {
data.uuid = bt_uuid; \
data.step = test_step; \
data.source_db = db; \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, function, NULL); \
} while (0)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index f504724..6afc145 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -50,7 +50,7 @@ struct test_data {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -62,7 +62,7 @@ struct test_data {
#define type_pdu(cmd_type, args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
.type = cmd_type, \
}
@@ -70,7 +70,7 @@ struct test_data {
#define frg_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
.fragmented = true, \
}
@@ -82,7 +82,7 @@ struct test_data {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
data.result_func = result_function; \
tester_add(name, &data, NULL, function, NULL); \
data.test_handler = test_handler; \
@@ -96,7 +96,7 @@ struct test_data {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
data.hf_result_func = result_func; \
data.response_func = response_function; \
tester_add(name, &data, NULL, function, NULL); \
diff --git a/unit/test-hog.c b/unit/test-hog.c
index e6d4aff..edf0633 100644
--- a/unit/test-hog.c
+++ b/unit/test-hog.c
@@ -59,7 +59,7 @@ struct context {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .data = g_memdup(data(args), sizeof(data(args))), \
+ .data = g_memdup2(data(args), sizeof(data(args))), \
.size = sizeof(data(args)), \
}
@@ -75,7 +75,7 @@ struct context {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, function, NULL); \
} while (0)
diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index d3a885f..3a003ff 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -47,14 +47,14 @@ struct test_data {
#define raw_pdu(args...) \
{ \
.valid = true, \
- .raw_data = g_memdup(raw_data(args), sizeof(raw_data(args))), \
+ .raw_data = g_memdup2(raw_data(args), sizeof(raw_data(args))), \
.raw_size = sizeof(raw_data(args)), \
}
#define raw_pdu_cont(cont, args...) \
{ \
.valid = true, \
- .raw_data = g_memdup(raw_data(args), sizeof(raw_data(args))), \
+ .raw_data = g_memdup2(raw_data(args), sizeof(raw_data(args))), \
.raw_size = sizeof(raw_data(args)), \
.cont_len = cont, \
}
@@ -66,7 +66,7 @@ struct test_data {
}; \
static struct test_data data; \
data.mtu = _mtu; \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, test_sdp, NULL); \
} while (0)
@@ -92,7 +92,7 @@ struct test_data_de {
#define define_test_de_attr(name, input, exp) \
do { \
static struct test_data_de data; \
- data.input_data = g_memdup(input, sizeof(input)); \
+ data.input_data = g_memdup2(input, sizeof(input)); \
data.input_size = sizeof(input); \
data.expected = exp; \
tester_add("/sdp/DE/ATTR/" name, &data, NULL, \
diff --git a/unit/test-uhid.c b/unit/test-uhid.c
index 001d39a..bfe8369 100644
--- a/unit/test-uhid.c
+++ b/unit/test-uhid.c
@@ -61,7 +61,7 @@ struct context {
}; \
static struct test_data data; \
data.test_name = g_strdup(name); \
- data.pdu_list = g_memdup(pdus, sizeof(pdus)); \
+ data.pdu_list = g_memdup2(pdus, sizeof(pdus)); \
tester_add(name, &data, NULL, function, NULL); \
} while (0)
--
2.31.1