Skip to contentSkip to conversation

Bluetooth: Fix bug with filter in service discovery optimization

PATCH Applied Marcel Holtmann 2 participants 2 messages Dec 17, 2014

Subsystems (2)
lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: Fix bug with filter in service discovery optimization

The optimization for filtering out extended inquiry results, advertising reports or scan response data based on provided UUID list has a logic bug. In case no match is found in the advertising data, the scan response is ignored and not checked against the filter. This will lead to events being filtered wrongly.

Change the code to actually only drop the events when the scan response data is not present. If it is present, it needs to be checked against the provided filter.

The patch is a bit more complex than it needs to be. That is because it also fixes this compiler warning that some gcc versions produce.

CC net/bluetooth/mgmt.o
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:
net/bluetooth/mgmt.c:7028:7: warning: ‘match’ may be used uninitialized in this function [-Wmaybe-uninitialized]

  bool match;
       ^

It seems that gcc can not clearly figure out the context of the match variable. So just change the branches for the extended inquiry response and advertising data around so that it is clear.

---
 net/bluetooth/mgmt.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
net/bluetooth/mgmt.c +9 -5
index 23a0ca5a4737..6c5a8cc06b43 100644
@@ -7081,13 +7081,15 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 		 * kept and checking possible scan response data
 		 * will be skipped.
 		 */
-		if (hdev->discovery.uuid_count > 0) {
+		if (hdev->discovery.uuid_count > 0)
 			match = eir_has_uuids(eir, eir_len,
 					      hdev->discovery.uuid_count,
 					      hdev->discovery.uuids);
-			if (!match)
-				return;
-		}
+		else
+			match = true;
+
+		if (!match && !scan_rsp_len)
+			return;
 
 		/* Copy EIR or advertising data into event */
 		memcpy(ev->eir, eir, eir_len);
@@ -7096,8 +7098,10 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 		 * provided, results with empty EIR or advertising data
 		 * should be dropped since they do not match any UUID.
 		 */
-		if (hdev->discovery.uuid_count > 0)
+		if (hdev->discovery.uuid_count > 0 && !scan_rsp_len)
 			return;
+
+		match = false;
 	}
 
 	if (dev_class && !eir_has_data_type(ev->eir, eir_len, EIR_CLASS_OF_DEV))
Signature · 1 line
2.1.0
#1 lore raw

Hi Marcel,

Quoted 23 lines · Marcel Holtmann

The optimization for filtering out extended inquiry results, advertising reports or scan response data based on provided UUID list has a logic bug. In case no match is found in the advertising data, the scan response is ignored and not checked against the filter. This will lead to events being filtered wrongly.

Change the code to actually only drop the events when the scan response data is not present. If it is present, it needs to be checked against the provided filter.

The patch is a bit more complex than it needs to be. That is because it also fixes this compiler warning that some gcc versions produce.

CC net/bluetooth/mgmt.o
net/bluetooth/mgmt.c: In function ‘mgmt_device_found’:
net/bluetooth/mgmt.c:7028:7: warning: ‘match’ may be used uninitialized in this function [-Wmaybe-uninitialized]

  bool match;
       ^

It seems that gcc can not clearly figure out the context of the match variable. So just change the branches for the extended inquiry response and advertising data around so that it is clear.

Quoted 5 lines
---
 net/bluetooth/mgmt.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Applied to the bluetooth.git tree. Thanks.

Johan