Diff between b81d63d581a4fc2a5f76ed5fe03be2d3a32ef51b and 0b4da9426f177bf46aa77b12e05da147a8b6f108

Changed Files

File Additions Deletions Status
plugins/wiimote.c +0 -1 modified
profiles/input/device.c +1 -1 modified
src/device.c +4 -1 modified

Full Patch

diff --git a/plugins/wiimote.c b/plugins/wiimote.c
index c23607f..bd8820e 100644
--- a/plugins/wiimote.c
+++ b/plugins/wiimote.c
@@ -90,7 +90,6 @@ static ssize_t wii_pincb(struct btd_adapter *adapter, struct btd_device *device,
 	product = btd_device_get_product(device);
 
 	device_get_name(device, name, sizeof(name));
-	name[sizeof(name) - 1] = 0;
 
 	for (i = 0; i < G_N_ELEMENTS(wii_ids); ++i) {
 		if (vendor == wii_ids[i][0] && product == wii_ids[i][1])
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 10c3d5c..d6e97c7 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -822,7 +822,7 @@ static struct input_device *input_device_new(struct btd_service *service)
 	idev->handle = rec->handle;
 	idev->disable_sdp = is_device_sdp_disable(rec);
 
-	device_get_name(device, name, HCI_MAX_NAME_LENGTH);
+	device_get_name(device, name, sizeof(name));
 	if (strlen(name) > 0)
 		idev->name = g_strdup(name);
 
diff --git a/src/device.c b/src/device.c
index 41a6fc8..eabbe0a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2272,7 +2272,10 @@ void btd_device_device_set_name(struct btd_device *device, const char *name)
 
 void device_get_name(struct btd_device *device, char *name, size_t len)
 {
-	strncpy(name, device->name, len);
+	if (name != NULL && len > 0) {
+		strncpy(name, device->name, len - 1);
+		name[len - 1] = '\0';
+	}
 }
 
 bool device_name_known(struct btd_device *device)