All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix duplicate free for GATT service includes
@ 2020-11-20  0:22 Pavel Maltsev
  2020-11-20  1:00 ` bluez.test.bot
  0 siblings, 1 reply; 5+ messages in thread
From: Pavel Maltsev @ 2020-11-20  0:22 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pavel Maltsev

Objects in the service->includes queue are obtained via
dbus_message_iter_get_basic call and according to the
contract for the value is that it is returned by the reference
and should not be freed thus we should make a copy.

This will fix the issue when the GATT service app is disconnected
(reproduced with gatt-service included in bluez), bluetoothd is crashing:

src/gatt-database.c:gatt_db_service_removed() Local GATT service removed
src/adapter.c:adapter_service_remove() /org/bluez/hci0
src/adapter.c:remove_uuid() sending remove uuid command for index 0
src/gatt-database.c:proxy_removed_cb() Proxy removed - removing service: /serv1
munmap_chunk(): invalid pointer
---
 src/gatt-database.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 6694a0174..90cc4bade 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -1999,6 +1999,7 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
 	DBusMessageIter iter;
 	DBusMessageIter array;
 	char *obj;
+	char *includes;
 	int type;
 
 	/* Includes property is optional */
@@ -2017,7 +2018,11 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
 
 		dbus_message_iter_get_basic(&array, &obj);
 
-		if (!queue_push_tail(service->includes, obj)) {
+		includes = g_strdup(obj);
+		if (!includes)
+			return false;
+
+		if (!queue_push_tail(service->includes, includes)) {
 			error("Failed to add Includes path in queue\n");
 			return false;
 		}
-- 
2.29.2.454.gaff20da3a2-goog


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

* RE: Fix duplicate free for GATT service includes
  2020-11-20  0:22 [PATCH] Fix duplicate free for GATT service includes Pavel Maltsev
@ 2020-11-20  1:00 ` bluez.test.bot
  2020-11-20 17:48   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 5+ messages in thread
From: bluez.test.bot @ 2020-11-20  1:00 UTC (permalink / raw)
  To: linux-bluetooth, pavelm

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=388009

---Test result---

##############################
Test: CheckPatch - PASS

##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS



---
Regards,
Linux Bluetooth


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

* Re: Fix duplicate free for GATT service includes
  2020-11-20  1:00 ` bluez.test.bot
@ 2020-11-20 17:48   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2020-11-20 17:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: pavelm

Hi Pavel,

On Thu, Nov 19, 2020 at 5:06 PM <bluez.test.bot@gmail.com> wrote:
>
> This is automated email and please do not reply to this email!
>
> Dear submitter,
>
> Thank you for submitting the patches to the linux bluetooth mailing list.
> This is a CI test results with your patch series:
> PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=388009
>
> ---Test result---
>
> ##############################
> Test: CheckPatch - PASS
>
> ##############################
> Test: CheckGitLint - PASS
>
> ##############################
> Test: CheckBuild - PASS
>
> ##############################
> Test: MakeCheck - PASS
>
>
>
> ---
> Regards,
> Linux Bluetooth
>

Applied, thanks.

-- 
Luiz Augusto von Dentz

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

* [PATCH] Fix duplicate free for GATT service includes
@ 2020-11-19 21:43 Pavel Maltsev
  0 siblings, 0 replies; 5+ messages in thread
From: Pavel Maltsev @ 2020-11-19 21:43 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pavel Maltsev

Objects in the service->includes queue are obtained via
dbus_message_iter_get_basic call and according to the
contract for the value is that it is returned by the reference
and should not be freed thus we should make a copy.

This will fix the issue when the GATT service app is disconnected
(reproduced with gatt-service included in bluez), bluetoothd is crashing:

bluetoothd: src/gatt-database.c:gatt_db_service_removed() Local GATT service removed
bluetoothd: src/adapter.c:adapter_service_remove() /org/bluez/hci0
bluetoothd: src/adapter.c:remove_uuid() sending remove uuid command for index 0
bluetoothd: src/sdpd-service.c:remove_record_from_server() Removing record with handle 0x10006
bluetoothd: src/gatt-database.c:proxy_removed_cb() Proxy removed - removing service: /service1
munmap_chunk(): invalid pointer
---
 src/gatt-database.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 6694a0174..90cc4bade 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -1999,6 +1999,7 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
 	DBusMessageIter iter;
 	DBusMessageIter array;
 	char *obj;
+	char *includes;
 	int type;
 
 	/* Includes property is optional */
@@ -2017,7 +2018,11 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
 
 		dbus_message_iter_get_basic(&array, &obj);
 
-		if (!queue_push_tail(service->includes, obj)) {
+		includes = g_strdup(obj);
+		if (!includes)
+			return false;
+
+		if (!queue_push_tail(service->includes, includes)) {
 			error("Failed to add Includes path in queue\n");
 			return false;
 		}
-- 
2.29.2.299.gdc1121823c-goog


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

* [PATCH] Fix duplicate free for GATT service includes
@ 2020-11-19 20:02 Pavel Maltsev
  0 siblings, 0 replies; 5+ messages in thread
From: Pavel Maltsev @ 2020-11-19 20:02 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pavel Maltsev

Service includes object is obtained via dbus_message_iter_get_basic call
and according to the contract for the value is that it is returned by
the references and should not be freed so we should make a copy.

The issue I'm running is when the GATT service app is disconnected
(reproduced with gatt-service included in bluez), bluetoothd is crashing:

bluetoothd[9771]: src/gatt-database.c:gatt_db_service_removed() Local GATT service removed
bluetoothd[9771]: src/adapter.c:adapter_service_remove() /org/bluez/hci0
bluetoothd[9771]: src/adapter.c:remove_uuid() sending remove uuid command for index 0
bluetoothd[9771]: src/sdpd-service.c:remove_record_from_server() Removing record with handle 0x10006
bluetoothd[9771]: src/gatt-database.c:proxy_removed_cb() Proxy removed - removing service: /service1
munmap_chunk(): invalid pointer

Signed-off-by: Pavel Maltsev <pavelm@google.com>
---
 src/gatt-database.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 6694a0174..04b49e2c1 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -2017,7 +2017,11 @@ static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
 
 		dbus_message_iter_get_basic(&array, &obj);
 
-		if (!queue_push_tail(service->includes, obj)) {
+		const char* includes = g_strdup(obj);
+		if (!includes)
+			return false;
+
+		if (!queue_push_tail(service->includes, includes)) {
 			error("Failed to add Includes path in queue\n");
 			return false;
 		}
-- 
2.29.2.299.gdc1121823c-goog


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

end of thread, other threads:[~2020-11-20 17:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20  0:22 [PATCH] Fix duplicate free for GATT service includes Pavel Maltsev
2020-11-20  1:00 ` bluez.test.bot
2020-11-20 17:48   ` Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2020-11-19 21:43 [PATCH] " Pavel Maltsev
2020-11-19 20:02 Pavel Maltsev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.