Skip to contentSkip to conversation

Fix invalid write to memory issue in a2dp module

PATCH Superseded Rafal Michalski 1 participant 2 messages Jun 10, 2011 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Fix invalid write to memory issue in a2dp module

Under some circumstances (such as terminating bluetoothd during music is streamed) sep object may be destroyed (memory for sep object is internally freed, directly by "a2dp_unregister_sep") after invoking "media_endpoint_clear_configuration" (in "stream_state_changed") It leads to invalid write issue (reported by valgrind) after assigning "sep->stream = NULL", since "sep" is "alias" pointer to sep object which is already out of date (memory for sep object has been already freed).

This patch prevents from this issue by ensuring that assignment "sep->stream = NULL" would be executed when sep object certainly exists.

---
 audio/a2dp.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
audio/a2dp.c +2 -3
index b4ec274..f3e7af3 100644
@@ -371,11 +371,10 @@ static void stream_state_changed(struct avdtp_stream *stream,
 		sep->session = NULL;
 	}
 
-	if (sep->endpoint)
-		media_endpoint_clear_configuration(sep->endpoint);
-
 	sep->stream = NULL;
 
+	if (sep->endpoint)
+		media_endpoint_clear_configuration(sep->endpoint);
 }
 
 static gboolean auto_config(gpointer data)
Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 2/3 Fix invalid write to memory issue in media module

Under some circumstances (such as terminating bluetoothd during music is streamed) endpoint object may be destroyed (memory for endpoint object is internally freed, directly by "media_endpoint_remove") after invoking "media_transport_destroy" (in "media_endpoint_clear_configuration") to destroy transport object (memory for transport object is directly freed by "media_transport_free"). It leads to invalid write issue (reported by valgrind) after assigning "endpoint->transport = NULL", since "endpoint" is "alias" pointer to endpoint object which is already out of date (memory for endpoint object has been already freed).

This patch prevents from this issue by ensuring that assignment "endpoint->transport = NULL" would be executed when enpoint object certainly exists.

---
 audio/media.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
audio/media.c +2 -1
index 0eb712a..bbb77cf 100644
@@ -643,6 +643,7 @@ void media_endpoint_clear_configuration(struct media_endpoint *endpoint)
 	DBusConnection *conn;
 	DBusMessage *msg;
 	const char *path;
+	struct media_transport *transport = endpoint->transport;
 
 	if (endpoint->transport == NULL)
 		return;
@@ -665,8 +666,8 @@ void media_endpoint_clear_configuration(struct media_endpoint *endpoint)
 							DBUS_TYPE_INVALID);
 	g_dbus_send_message(conn, msg);
 done:
-	media_transport_destroy(endpoint->transport);
 	endpoint->transport = NULL;
+	media_transport_destroy(transport);
 }
 
 void media_endpoint_release(struct media_endpoint *endpoint)
Signature · 1 line
1.6.3.3