Skip to contentSkip to conversation

Add Null Pointer Checks

PATCH In review Roushan Kumar Singh 3 participants 3 messages Feb 1 – Feb 3 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add Null Pointer Checks

---
 src/device.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
src/device.c +12 -5
index af8df5f29..c0b95d09c 100644
@@ -380,6 +380,9 @@ static GSList *find_service_with_uuid(GSList *list, char *uuid)
 		struct btd_service *service = l->data;
 		struct btd_profile *profile = btd_service_get_profile(service);
 
+		if (!profile || !profile->remote_uuid)
+			continue;
+
 		if (bt_uuid_strcmp(profile->remote_uuid, uuid) == 0)
 			return l;
 	}
@@ -2540,7 +2543,7 @@ static struct btd_service *find_connectable_service(struct btd_device *dev,
 		struct btd_service *service = l->data;
 		struct btd_profile *p = btd_service_get_profile(service);
 
-		if (!p->connect || !p->remote_uuid)
+		if (!p || !p->connect || !p->remote_uuid)
 			continue;
 
 		if (strcasecmp(uuid, p->remote_uuid) == 0)
@@ -2594,6 +2597,9 @@ void btd_device_update_allowed_services(struct btd_device *dev)
 		service = l->data;
 		profile = btd_service_get_profile(service);
 
+		if (!profile || !profile->remote_uuid)
+			continue;
+
 		is_allowed = btd_adapter_is_uuid_allowed(adapter,
 							profile->remote_uuid);
 		btd_service_set_allowed(service, is_allowed);
@@ -2629,11 +2635,12 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
 		service = l->data;
 		p = btd_service_get_profile(service);
 
-		if (!p->auto_connect)
+		if (!p || !p->auto_connect)
 			continue;
 
 		if (!btd_service_is_allowed(service)) {
-			info("service %s is blocked", p->remote_uuid);
+			if (p->remote_uuid)
+				info("service %s is blocked", p->remote_uuid);
 			continue;
 		}
 
@@ -6173,8 +6180,8 @@ static void disconnect_gatt_service(gpointer data, gpointer user_data)
 	struct btd_service *service = data;
 	struct btd_profile *profile = btd_service_get_profile(service);
 
-	/* Ignore if profile cannot accept connections */
-	if (!profile->accept)
+	/* Ignore if profile is NULL or cannot accept connections */
+	if (!profile || !profile->accept)
 		return;
 
 	btd_service_disconnect(service);
Signature · 1 line
2.51.0
#1 lore raw

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=1049427

---Test result---

Test Summary:

CheckPatch                    PENDING   0.40 seconds
GitLint                       PENDING   0.42 seconds
BuildEll                      PASS      19.88 seconds
BluezMake                     PASS      650.91 seconds
MakeCheck                     PASS      18.51 seconds
MakeDistcheck                 PASS      242.66 seconds
CheckValgrind                 PASS      293.92 seconds
CheckSmatch                   PASS      348.58 seconds
bluezmakeextell               PASS      182.42 seconds
IncrementalBuild              PENDING   0.38 seconds
ScanBuild                     PASS      1000.60 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Roushan Kumar Singh

Hi Roushan,

Could please add the backtrace so we can check this actually reproducible, afaik the likes of service_create are only called with non-NULL profile, but maybe this is the result of the service being removed or something that resets service->profile to NULL but in that case the service should be invalidate as well and removed from the list of services.

Quoted 68 lines · Roushan Kumar Singh
---
 src/device.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
src/device.c +12 -6
index af8df5f29..c0b95d09c 100644
@@ -380,6 +380,9 @@ static GSList *find_service_with_uuid(GSList *list, char *uuid)
                struct btd_service *service = l->data;
                struct btd_profile *profile = btd_service_get_profile(service);
 
+               if (!profile || !profile->remote_uuid)
+                       continue;
+
                if (bt_uuid_strcmp(profile->remote_uuid, uuid) == 0)
                        return l;
        }
@@ -2540,7 +2543,7 @@ static struct btd_service *find_connectable_service(struct btd_device *dev,
                struct btd_service *service = l->data;
                struct btd_profile *p = btd_service_get_profile(service);
 
-               if (!p->connect || !p->remote_uuid)
+               if (!p || !p->connect || !p->remote_uuid)
                        continue;
 
                if (strcasecmp(uuid, p->remote_uuid) == 0)
@@ -2594,6 +2597,9 @@ void btd_device_update_allowed_services(struct btd_device *dev)
                service = l->data;
                profile = btd_service_get_profile(service);
 
+               if (!profile || !profile->remote_uuid)
+                       continue;
+
                is_allowed = btd_adapter_is_uuid_allowed(adapter,
                                                        profile->remote_uuid);
                btd_service_set_allowed(service, is_allowed);
@@ -2629,11 +2635,12 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
                service = l->data;
                p = btd_service_get_profile(service);
 
-               if (!p->auto_connect)
+               if (!p || !p->auto_connect)
                        continue;
 
                if (!btd_service_is_allowed(service)) {
-                       info("service %s is blocked", p->remote_uuid);
+                       if (p->remote_uuid)
+                               info("service %s is blocked", p->remote_uuid);
                        continue;
                }
 
@@ -6173,8 +6180,8 @@ static void disconnect_gatt_service(gpointer data, gpointer user_data)
        struct btd_service *service = data;
        struct btd_profile *profile = btd_service_get_profile(service);
 
-       /* Ignore if profile cannot accept connections */
-       if (!profile->accept)
+       /* Ignore if profile is NULL or cannot accept connections */
+       if (!profile || !profile->accept)
                return;
 
        btd_service_disconnect(service);
--

2.51.0

Signature · 1 line
Luiz Augusto von Dentz