public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] plugins/sixaxis: add NULL check in setup_device()
@ 2024-06-27 10:30 Roman Smirnov
  2024-06-27 12:07 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Roman Smirnov @ 2024-06-27 10:30 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Roman Smirnov

btd_adapter_get_device() may return NULL on the next call stack:

btd_adapter_get_device()
    adapter_create_device()
        device_create()
	    device_new()
                g_try_malloc0()

It is necessary to prevent this to avoid dereferencing a null
pointer further.
---
 plugins/sixaxis.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
index 544ab399a..3e69f1dd2 100644
--- a/plugins/sixaxis.c
+++ b/plugins/sixaxis.c
@@ -346,6 +346,11 @@ static bool setup_device(int fd, const char *sysfs_path,
 
 	device = btd_adapter_get_device(adapter, &device_bdaddr, BDADDR_BREDR);
 
+	if (!device) {
+		error("sixaxis: unable to set up a new device");
+		return false;
+	}
+
 	info("sixaxis: setting up new device");
 
 	btd_device_device_set_name(device, cp->name);
-- 
2.43.0


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

end of thread, other threads:[~2024-06-27 12:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-27 10:30 [PATCH BlueZ] plugins/sixaxis: add NULL check in setup_device() Roman Smirnov
2024-06-27 12:07 ` [BlueZ] " bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox